Skip to content

Commit fe00cfe

Browse files
committed
restore snapshot when parse_param_general
1 parent 6433879 commit fe00cfe

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

compiler/rustc_parse/src/parser/item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2494,9 +2494,11 @@ impl<'a> Parser<'a> {
24942494
// Parse the arguments, starting out with `self` being allowed...
24952495
let (mut params, _) = self.parse_paren_comma_seq(|p| {
24962496
p.recover_diff_marker();
2497+
let snapshot = p.create_snapshot_for_diagnostic();
24972498
let param = p.parse_param_general(req_name, first_param).or_else(|mut e| {
24982499
e.emit();
24992500
let lo = p.prev_token.span;
2501+
p.restore_snapshot(snapshot);
25002502
// Skip every token until next possible arg or end.
25012503
p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(Delimiter::Parenthesis)]);
25022504
// Create a placeholder argument for proper arg count (issue #34264).

tests/ui/parser/issue-116781.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[derive(Debug)]
2+
struct Foo {
3+
#[cfg(all())]
4+
field: fn(($),), //~ ERROR expected pattern, found `$`
5+
//~^ ERROR expected pattern, found `$`
6+
}
7+
8+
fn main() {}

tests/ui/parser/issue-116781.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: expected pattern, found `$`
2+
--> $DIR/issue-116781.rs:4:16
3+
|
4+
LL | field: fn(($),),
5+
| ^ expected pattern
6+
7+
error: expected pattern, found `$`
8+
--> $DIR/issue-116781.rs:4:16
9+
|
10+
LL | field: fn(($),),
11+
| ^ expected pattern
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error: aborting due to 2 previous errors
16+

0 commit comments

Comments
 (0)