Skip to content

Commit e177921

Browse files
committed
Allow for reparsing failure when reparsing a pasted metavar.
Fixes #139445. The additional errors aren't great but the first one is still good and it's the most important, and imperfect errors are better than ICEing.
1 parent eb5d892 commit e177921

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

Diff for: compiler/rustc_parse/src/parser/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,16 @@ impl<'a> Parser<'a> {
782782
// Recovery is disabled when parsing macro arguments, so it must
783783
// also be disabled when reparsing pasted macro arguments,
784784
// otherwise we get inconsistent results (e.g. #137874).
785-
let res = self.with_recovery(Recovery::Forbidden, |this| {
786-
f(this).expect("failed to reparse {mv_kind:?}")
787-
});
785+
let res = self.with_recovery(Recovery::Forbidden, |this| f(this));
786+
787+
let res = match res {
788+
Ok(res) => res,
789+
Err(err) => {
790+
// This can occur in unusual error cases, e.g. #139445.
791+
err.delay_as_bug();
792+
return None;
793+
}
794+
};
788795

789796
if let token::CloseDelim(delim) = self.token.kind
790797
&& let Delimiter::Invisible(InvisibleOrigin::MetaVar(mv_kind)) = delim

Diff for: tests/ui/macros/failed-to-reparse-issue-139445.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
assert_eq!(3, 'a,)
3+
//~^ ERROR expected `while`, `for`, `loop` or `{` after a label
4+
//~| ERROR expected `while`, `for`, `loop` or `{` after a label
5+
//~| ERROR expected expression, found ``
6+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: expected `while`, `for`, `loop` or `{` after a label
2+
--> $DIR/failed-to-reparse-issue-139445.rs:2:21
3+
|
4+
LL | assert_eq!(3, 'a,)
5+
| ^ expected `while`, `for`, `loop` or `{` after a label
6+
7+
error: expected `while`, `for`, `loop` or `{` after a label
8+
--> $DIR/failed-to-reparse-issue-139445.rs:2:5
9+
|
10+
LL | assert_eq!(3, 'a,)
11+
| ^^^^^^^^^^^^^^^^^^ expected `while`, `for`, `loop` or `{` after a label
12+
|
13+
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
14+
15+
error: expected expression, found ``
16+
--> $DIR/failed-to-reparse-issue-139445.rs:2:5
17+
|
18+
LL | assert_eq!(3, 'a,)
19+
| ^^^^^^^^^^^^^^^^^^ expected expression
20+
|
21+
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
error: aborting due to 3 previous errors
24+

0 commit comments

Comments
 (0)