Skip to content

Commit 3f09a20

Browse files
committed
Do not allow attributes on struct field rest patterns
This removes support for attributes on struct field rest patterns (the `..`) from the parser. Previously they were being parsed but dropped from the AST, so didn't work and were deleted by rustfmt.
1 parent 01a26c0 commit 3f09a20

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

compiler/rustc_parse/src/parser/pat.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1472,17 +1472,6 @@ impl<'a> Parser<'a> {
14721472
let mut last_non_comma_dotdot_span = None;
14731473

14741474
while self.token != token::CloseDelim(Delimiter::Brace) {
1475-
let attrs = match self.parse_outer_attributes() {
1476-
Ok(attrs) => attrs,
1477-
Err(err) => {
1478-
if let Some(delayed) = delayed_err {
1479-
delayed.emit();
1480-
}
1481-
return Err(err);
1482-
}
1483-
};
1484-
let lo = self.token.span;
1485-
14861475
// check that a comma comes after every field
14871476
if !ate_comma {
14881477
let err = if self.token == token::At {
@@ -1585,6 +1574,17 @@ impl<'a> Parser<'a> {
15851574
}
15861575
}
15871576

1577+
let attrs = match self.parse_outer_attributes() {
1578+
Ok(attrs) => attrs,
1579+
Err(err) => {
1580+
if let Some(delayed) = delayed_err {
1581+
delayed.emit();
1582+
}
1583+
return Err(err);
1584+
}
1585+
};
1586+
let lo = self.token.span;
1587+
15881588
let field = self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| {
15891589
let field = match this.parse_pat_field(lo, attrs) {
15901590
Ok(field) => Ok(field),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// #81282: Attributes are not allowed on struct field rest patterns (the ..).
2+
3+
struct S {}
4+
5+
fn main() {
6+
let S { #[cfg(any())] .. } = S {};
7+
//~^ ERROR expected identifier, found `..`
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected identifier, found `..`
2+
--> $DIR/attr-pat-struct-rest.rs:6:27
3+
|
4+
LL | let S { #[cfg(any())] .. } = S {};
5+
| - ^^ expected identifier
6+
| |
7+
| while parsing the fields for this pattern
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)