about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_parse/src/parser/pat.rs22
-rw-r--r--tests/ui/parser/attribute/attr-pat-struct-rest.rs8
-rw-r--r--tests/ui/parser/attribute/attr-pat-struct-rest.stderr10
3 files changed, 29 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs
index 64bcb1a5a36..8ce749ec814 100644
--- a/compiler/rustc_parse/src/parser/pat.rs
+++ b/compiler/rustc_parse/src/parser/pat.rs
@@ -1472,17 +1472,6 @@ impl<'a> Parser<'a> {
         let mut last_non_comma_dotdot_span = None;
 
         while self.token != token::CloseDelim(Delimiter::Brace) {
-            let attrs = match self.parse_outer_attributes() {
-                Ok(attrs) => attrs,
-                Err(err) => {
-                    if let Some(delayed) = delayed_err {
-                        delayed.emit();
-                    }
-                    return Err(err);
-                }
-            };
-            let lo = self.token.span;
-
             // check that a comma comes after every field
             if !ate_comma {
                 let err = if self.token == token::At {
@@ -1585,6 +1574,17 @@ impl<'a> Parser<'a> {
                 }
             }
 
+            let attrs = match self.parse_outer_attributes() {
+                Ok(attrs) => attrs,
+                Err(err) => {
+                    if let Some(delayed) = delayed_err {
+                        delayed.emit();
+                    }
+                    return Err(err);
+                }
+            };
+            let lo = self.token.span;
+
             let field = self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| {
                 let field = match this.parse_pat_field(lo, attrs) {
                     Ok(field) => Ok(field),
diff --git a/tests/ui/parser/attribute/attr-pat-struct-rest.rs b/tests/ui/parser/attribute/attr-pat-struct-rest.rs
new file mode 100644
index 00000000000..b2bfcf82df8
--- /dev/null
+++ b/tests/ui/parser/attribute/attr-pat-struct-rest.rs
@@ -0,0 +1,8 @@
+// #81282: Attributes are not allowed on struct field rest patterns (the ..).
+
+struct S {}
+
+fn main() {
+    let S { #[cfg(any())] .. } = S {};
+    //~^ ERROR expected identifier, found `..`
+}
diff --git a/tests/ui/parser/attribute/attr-pat-struct-rest.stderr b/tests/ui/parser/attribute/attr-pat-struct-rest.stderr
new file mode 100644
index 00000000000..f72c54973fc
--- /dev/null
+++ b/tests/ui/parser/attribute/attr-pat-struct-rest.stderr
@@ -0,0 +1,10 @@
+error: expected identifier, found `..`
+  --> $DIR/attr-pat-struct-rest.rs:6:27
+   |
+LL |     let S { #[cfg(any())] .. } = S {};
+   |         -                 ^^ expected identifier
+   |         |
+   |         while parsing the fields for this pattern
+
+error: aborting due to 1 previous error
+