Skip to content

Commit

Permalink
Do less panicking in general
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Feb 19, 2016
1 parent 3a87278 commit 11e0ba4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ pub fn compile_input(sess: &Session,
// possible to keep the peak memory usage low
let (outputs, trans) = {
let (outputs, expanded_crate, id) = {
let krate = panictry!(phase_1_parse_input(sess, cfg, input));
let krate = match phase_1_parse_input(sess, cfg, input) {
Ok(krate) => krate,
Err(mut parse_error) => {
parse_error.emit();
return Err(1);
}
};

controller_entry_point!(after_parse,
sess,
Expand Down
14 changes: 13 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,19 @@ impl RustcDefaultCalls {
return Compilation::Continue;
}

let attrs = input.map(|input| panictry!(parse_crate_attrs(sess, input)));
let attrs = match input {
None => None,
Some(input) => {
let result = parse_crate_attrs(sess, input);
match result {
Ok(attrs) => Some(attrs),
Err(mut parse_error) => {
parse_error.emit();
return Compilation::Stop;
}
}
}
};
for req in &sess.opts.prints {
match *req {
PrintRequest::TargetList => {
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ pub fn parse_expr_from_source_str<'a>(name: String,
p.parse_expr()
}

/// Parses an item.
///
/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and`Err`
/// when a syntax error occurred.
pub fn parse_item_from_source_str<'a>(name: String,
source: String,
cfg: ast::CrateConfig,
Expand Down

0 comments on commit 11e0ba4

Please sign in to comment.