Do less panicking in general

This commit is contained in:
Jonas Schievink 2016-02-19 14:43:13 +01:00
parent 3a872782d3
commit 11e0ba4340
3 changed files with 24 additions and 2 deletions

View file

@ -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,

View file

@ -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 => {

View file

@ -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,