Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eat close paren if capture_cfg to avoid unbalanced parens #116889

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2494,9 +2494,11 @@ impl<'a> Parser<'a> {
// Parse the arguments, starting out with `self` being allowed...
let (mut params, _) = self.parse_paren_comma_seq(|p| {
p.recover_diff_marker();
let snapshot = p.create_snapshot_for_diagnostic();
let param = p.parse_param_general(req_name, first_param).or_else(|mut e| {
e.emit();
let lo = p.prev_token.span;
p.restore_snapshot(snapshot);
// Skip every token until next possible arg or end.
p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(Delimiter::Parenthesis)]);
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
// Create a placeholder argument for proper arg count (issue #34264).
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/parser/issue-116781.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[derive(Debug)]
struct Foo {
#[cfg(all())]
field: fn(($),), //~ ERROR expected pattern, found `$`
//~^ ERROR expected pattern, found `$`
}

fn main() {}
16 changes: 16 additions & 0 deletions tests/ui/parser/issue-116781.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: expected pattern, found `$`
--> $DIR/issue-116781.rs:4:16
|
LL | field: fn(($),),
| ^ expected pattern

error: expected pattern, found `$`
--> $DIR/issue-116781.rs:4:16
|
LL | field: fn(($),),
| ^ expected pattern
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

Loading