Skip to content

Commit

Permalink
Handle errors during error recovery gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jul 11, 2019
1 parent 4bb6b4a commit e1c7747
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7408,10 +7408,13 @@ impl<'a> Parser<'a> {
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
let ident = self.parse_ident().unwrap();
self.bump(); // `(`
let kw_name = if let Ok(Some(_)) = self.parse_self_arg_with_attrs() {
"method"
} else {
"function"
let kw_name = match self.parse_self_arg_with_attrs() {
Ok(Some(_)) => "method",
Ok(None) => "function",
Err(mut err) => {
err.cancel();
"function"
}
};
self.consume_block(token::Paren);
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) {
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/parser/issue-62546.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub t(#
//~^ ERROR missing `fn` or `struct` for function or struct definition
//~ ERROR this file contains an un-closed delimiter
17 changes: 17 additions & 0 deletions src/test/ui/parser/issue-62546.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: this file contains an un-closed delimiter
--> $DIR/issue-62546.rs:3:53
|
LL | pub t(#
| - un-closed delimiter
LL |
LL |
| ^

error: missing `fn` or `struct` for function or struct definition
--> $DIR/issue-62546.rs:1:4
|
LL | pub t(#
| ---^- help: if you meant to call a macro, try: `t!`

error: aborting due to 2 previous errors

0 comments on commit e1c7747

Please sign in to comment.