Skip to content

Commit e1c7747

Browse files
committed
Handle errors during error recovery gracefully
1 parent 4bb6b4a commit e1c7747

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/libsyntax/parse/parser.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -7408,10 +7408,13 @@ impl<'a> Parser<'a> {
74087408
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
74097409
let ident = self.parse_ident().unwrap();
74107410
self.bump(); // `(`
7411-
let kw_name = if let Ok(Some(_)) = self.parse_self_arg_with_attrs() {
7412-
"method"
7413-
} else {
7414-
"function"
7411+
let kw_name = match self.parse_self_arg_with_attrs() {
7412+
Ok(Some(_)) => "method",
7413+
Ok(None) => "function",
7414+
Err(mut err) => {
7415+
err.cancel();
7416+
"function"
7417+
}
74157418
};
74167419
self.consume_block(token::Paren);
74177420
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) {

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

+3
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

+17
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)