From 52a15180d2bc193aceea7302dd175f2c872df340 Mon Sep 17 00:00:00 2001 From: yukang Date: Sat, 13 Aug 2022 12:50:53 +0800 Subject: give a helpful diagnostic even when the next struct field has an attribute --- compiler/rustc_parse/src/parser/item.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_parse/src/parser') 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", -- cgit 1.4.1-3-g733a5