Skip to content

Commit

Permalink
eat close paren if capture_cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
mu001999 committed Oct 27, 2023
1 parent 6433879 commit 903cf7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2494,11 +2494,19 @@ 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 starts_with_paren = p.check_noexpect(&token::OpenDelim(Delimiter::Parenthesis));
let param = p.parse_param_general(req_name, first_param).or_else(|mut e| {
e.emit();
if p.capture_cfg {
e.cancel();
} else {
e.emit();
}
let lo = p.prev_token.span;
// Skip every token until next possible arg or end.
p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(Delimiter::Parenthesis)]);
if p.capture_cfg && starts_with_paren {
p.eat_noexpect(&token::CloseDelim(Delimiter::Parenthesis));
}
// Create a placeholder argument for proper arg count (issue #34264).
Ok(dummy_arg(Ident::new(kw::Empty, lo.to(p.prev_token.span))))
});
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 identifier, found `)`
}

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

error: expected identifier, found `)`
--> $DIR/issue-116781.rs:4:19
|
LL | struct Foo {
| --- while parsing this struct
LL | #[cfg(all())]
LL | field: fn(($),),
| ^ expected identifier

error: aborting due to 2 previous errors

0 comments on commit 903cf7e

Please sign in to comment.