Skip to content

Commit 88ae8c9

Browse files
committed
Auto merge of #116889 - MU001999:master, r=petrochenkov
Eat close paren if capture_cfg to avoid unbalanced parens Fixes #116781
2 parents 83c9732 + fe00cfe commit 88ae8c9

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
@@ -2501,9 +2501,11 @@ impl<'a> Parser<'a> {
25012501
// Parse the arguments, starting out with `self` being allowed...
25022502
let (mut params, _) = self.parse_paren_comma_seq(|p| {
25032503
p.recover_diff_marker();
2504+
let snapshot = p.create_snapshot_for_diagnostic();
25042505
let param = p.parse_param_general(req_name, first_param).or_else(|mut e| {
25052506
e.emit();
25062507
let lo = p.prev_token.span;
2508+
p.restore_snapshot(snapshot);
25072509
// Skip every token until next possible arg or end.
25082510
p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(Delimiter::Parenthesis)]);
25092511
// 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)