Auto merge of #116889 - MU001999:master, r=petrochenkov

Eat close paren if capture_cfg to avoid unbalanced parens

Fixes #116781
This commit is contained in:
bors 2023-10-29 16:46:47 +00:00
commit 88ae8c9385
3 changed files with 26 additions and 0 deletions

View File

@ -2501,9 +2501,11 @@ pub(super) fn parse_fn_params(&mut self, req_name: ReqName) -> PResult<'a, ThinV
// Parse the arguments, starting out with `self` being allowed... // Parse the arguments, starting out with `self` being allowed...
let (mut params, _) = self.parse_paren_comma_seq(|p| { let (mut params, _) = self.parse_paren_comma_seq(|p| {
p.recover_diff_marker(); 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| { let param = p.parse_param_general(req_name, first_param).or_else(|mut e| {
e.emit(); e.emit();
let lo = p.prev_token.span; let lo = p.prev_token.span;
p.restore_snapshot(snapshot);
// Skip every token until next possible arg or end. // Skip every token until next possible arg or end.
p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(Delimiter::Parenthesis)]); p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(Delimiter::Parenthesis)]);
// Create a placeholder argument for proper arg count (issue #34264). // Create a placeholder argument for proper arg count (issue #34264).

View File

@ -0,0 +1,8 @@
#[derive(Debug)]
struct Foo {
#[cfg(all())]
field: fn(($),), //~ ERROR expected pattern, found `$`
//~^ ERROR expected pattern, found `$`
}
fn main() {}

View File

@ -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