Skip to content

Commit 11e0ba4

Browse files
Do less panicking in general
1 parent 3a87278 commit 11e0ba4

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/librustc_driver/driver.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ pub fn compile_input(sess: &Session,
8484
// possible to keep the peak memory usage low
8585
let (outputs, trans) = {
8686
let (outputs, expanded_crate, id) = {
87-
let krate = panictry!(phase_1_parse_input(sess, cfg, input));
87+
let krate = match phase_1_parse_input(sess, cfg, input) {
88+
Ok(krate) => krate,
89+
Err(mut parse_error) => {
90+
parse_error.emit();
91+
return Err(1);
92+
}
93+
};
8894

8995
controller_entry_point!(after_parse,
9096
sess,

src/librustc_driver/lib.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,19 @@ impl RustcDefaultCalls {
529529
return Compilation::Continue;
530530
}
531531

532-
let attrs = input.map(|input| panictry!(parse_crate_attrs(sess, input)));
532+
let attrs = match input {
533+
None => None,
534+
Some(input) => {
535+
let result = parse_crate_attrs(sess, input);
536+
match result {
537+
Ok(attrs) => Some(attrs),
538+
Err(mut parse_error) => {
539+
parse_error.emit();
540+
return Compilation::Stop;
541+
}
542+
}
543+
}
544+
};
533545
for req in &sess.opts.prints {
534546
match *req {
535547
PrintRequest::TargetList => {

src/libsyntax/parse/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ pub fn parse_expr_from_source_str<'a>(name: String,
120120
p.parse_expr()
121121
}
122122

123+
/// Parses an item.
124+
///
125+
/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and`Err`
126+
/// when a syntax error occurred.
123127
pub fn parse_item_from_source_str<'a>(name: String,
124128
source: String,
125129
cfg: ast::CrateConfig,

0 commit comments

Comments
 (0)