Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors during error recovery gracefully #62604

Merged
merged 1 commit into from
Jul 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use .map_err(|e| e.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