Skip to content

Commit 903cf7e

Browse files
committed
eat close paren if capture_cfg
1 parent 6433879 commit 903cf7e

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

compiler/rustc_parse/src/parser/item.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -2494,11 +2494,19 @@ 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 starts_with_paren = p.check_noexpect(&token::OpenDelim(Delimiter::Parenthesis));
24972498
let param = p.parse_param_general(req_name, first_param).or_else(|mut e| {
2498-
e.emit();
2499+
if p.capture_cfg {
2500+
e.cancel();
2501+
} else {
2502+
e.emit();
2503+
}
24992504
let lo = p.prev_token.span;
25002505
// Skip every token until next possible arg or end.
25012506
p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(Delimiter::Parenthesis)]);
2507+
if p.capture_cfg && starts_with_paren {
2508+
p.eat_noexpect(&token::CloseDelim(Delimiter::Parenthesis));
2509+
}
25022510
// Create a placeholder argument for proper arg count (issue #34264).
25032511
Ok(dummy_arg(Ident::new(kw::Empty, lo.to(p.prev_token.span))))
25042512
});

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 identifier, found `)`
6+
}
7+
8+
fn main() {}

tests/ui/parser/issue-116781.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: expected pattern, found `$`
2+
--> $DIR/issue-116781.rs:4:16
3+
|
4+
LL | field: fn(($),),
5+
| ^ expected pattern
6+
7+
error: expected identifier, found `)`
8+
--> $DIR/issue-116781.rs:4:19
9+
|
10+
LL | struct Foo {
11+
| --- while parsing this struct
12+
LL | #[cfg(all())]
13+
LL | field: fn(($),),
14+
| ^ expected identifier
15+
16+
error: aborting due to 2 previous errors
17+

0 commit comments

Comments
 (0)