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 authored Oct 18, 2023
1 parent 6433879 commit 48676a5
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 meet_left_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 && meet_left_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(($id1), $id2), //~ 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(($id1), $id2),
| ^ expected pattern

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

error: aborting due to 2 previous errors

0 comments on commit 48676a5

Please sign in to comment.