about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2022-08-13 12:50:53 +0800
committeryukang <moorekang@gmail.com>2022-08-13 12:50:53 +0800
commit52a15180d2bc193aceea7302dd175f2c872df340 (patch)
treee60af4ee907de224f279b78c403d0b1bb85441b3 /compiler/rustc_parse/src
parent1603a70f82240ba2d27f72f964e36614d7620ad3 (diff)
downloadrust-52a15180d2bc193aceea7302dd175f2c872df340.tar.gz
rust-52a15180d2bc193aceea7302dd175f2c872df340.zip
give a helpful diagnostic even when the next struct field has an attribute
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 72c23776d33..e8c097d0d56 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -1539,8 +1539,12 @@ impl<'a> Parser<'a> {
                     }
                 }
 
-                if self.token.is_ident() {
-                    // This is likely another field; emit the diagnostic and keep going
+                if self.token.is_ident()
+                    || (self.token.kind == TokenKind::Pound
+                        && (self.look_ahead(1, |t| t == &token::OpenDelim(Delimiter::Bracket))))
+                {
+                    // This is likely another field, TokenKind::Pound is used for `#[..]` attribute for next field,
+                    // emit the diagnostic and keep going
                     err.span_suggestion(
                         sp,
                         "try adding a comma",