Skip to content

Commit

Permalink
not use capture_cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
mu001999 committed Oct 27, 2023
1 parent 903cf7e commit c1613c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 38 deletions.
8 changes: 2 additions & 6 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2496,15 +2496,11 @@ impl<'a> Parser<'a> {
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| {
if p.capture_cfg {
e.cancel();
} else {
e.emit();
}
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 {
if starts_with_paren {
p.eat_noexpect(&token::CloseDelim(Delimiter::Parenthesis));
}
// Create a placeholder argument for proper arg count (issue #34264).
Expand Down
41 changes: 16 additions & 25 deletions tests/ui/parser/inverted-parameters.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,25 @@ error: expected one of `:` or `|`, found `(`
LL | fn pattern((i32, i32) (a, b)) {}
| ^ expected one of `:` or `|`

error: expected one of `:`, `@`, or `|`, found `)`
--> $DIR/inverted-parameters.rs:21:12
error: expected parameter name, found `{`
--> $DIR/inverted-parameters.rs:18:31
|
LL | fn fizz(i32) {}
| ^ expected one of `:`, `@`, or `|`
|
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a `self` type, give it a parameter name
|
LL | fn fizz(self: i32) {}
| +++++
help: if this is a parameter name, give it a type
|
LL | fn fizz(i32: TypeName) {}
| ++++++++++
help: if this is a type, explicitly ignore the parameter name
LL | fn pattern((i32, i32) (a, b)) {}
| ^ expected parameter name

error: expected one of `)` or `,`, found `{`
--> $DIR/inverted-parameters.rs:18:31
|
LL | fn fizz(_: i32) {}
| ++
LL | fn pattern((i32, i32) (a, b)) {}
| -^ expected one of `)` or `,`
| |
| help: missing `,`

error: expected one of `:`, `@`, or `|`, found `S`
--> $DIR/inverted-parameters.rs:27:23
error: expected one of `)`, `,`, `->`, `where`, or `{`, found `<eof>`
--> $DIR/inverted-parameters.rs:32:12
|
LL | fn missing_colon(quux S) {}
| -----^
| | |
| | expected one of `:`, `@`, or `|`
| help: declare the type after the parameter binding: `<identifier>: <type>`
LL | fn main() {}
| ^ expected one of `)`, `,`, `->`, `where`, or `{`

error: aborting due to 6 previous errors
error: aborting due to 7 previous errors

2 changes: 1 addition & 1 deletion tests/ui/parser/issue-116781.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
struct Foo {
#[cfg(all())]
field: fn(($),), //~ ERROR expected pattern, found `$`
//~^ ERROR expected identifier, found `)`
//~^ ERROR expected pattern, found `$`
}

fn main() {}
11 changes: 5 additions & 6 deletions tests/ui/parser/issue-116781.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ error: expected pattern, found `$`
LL | field: fn(($),),
| ^ expected pattern

error: expected identifier, found `)`
--> $DIR/issue-116781.rs:4:19
error: expected pattern, found `$`
--> $DIR/issue-116781.rs:4:16
|
LL | struct Foo {
| --- while parsing this struct
LL | #[cfg(all())]
LL | field: fn(($),),
| ^ expected identifier
| ^ expected pattern
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

0 comments on commit c1613c0

Please sign in to comment.