Skip to content

Commit dc925be

Browse files
estebankpietroalbini
authored andcommitted
Handle errors during error recovery gracefully
1 parent 6a8b495 commit dc925be

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7454,10 +7454,13 @@ impl<'a> Parser<'a> {
74547454
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
74557455
let ident = self.parse_ident().unwrap();
74567456
self.bump(); // `(`
7457-
let kw_name = if let Ok(Some(_)) = self.parse_self_arg_with_attrs() {
7458-
"method"
7459-
} else {
7460-
"function"
7457+
let kw_name = match self.parse_self_arg_with_attrs() {
7458+
Ok(Some(_)) => "method",
7459+
Ok(None) => "function",
7460+
Err(mut err) => {
7461+
err.cancel();
7462+
"function"
7463+
}
74617464
};
74627465
self.consume_block(token::Paren);
74637466
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) {

src/test/ui/parser/issue-62546.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub t(#
2+
//~^ ERROR missing `fn` or `struct` for function or struct definition
3+
//~ ERROR this file contains an un-closed delimiter

src/test/ui/parser/issue-62546.stderr

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: this file contains an un-closed delimiter
2+
--> $DIR/issue-62546.rs:3:53
3+
|
4+
LL | pub t(#
5+
| - un-closed delimiter
6+
LL |
7+
LL |
8+
| ^
9+
10+
error: missing `fn` or `struct` for function or struct definition
11+
--> $DIR/issue-62546.rs:1:4
12+
|
13+
LL | pub t(#
14+
| ---^- help: if you meant to call a macro, try: `t!`
15+
16+
error: aborting due to 2 previous errors
17+

0 commit comments

Comments
 (0)