Rollup merge of #100475 - chenyukang:fix-100461, r=fee1-dead

Give a helpful diagnostic when the next struct field has an attribute

Fixes #100461
This commit is contained in:
Michael Goulet 2022-08-13 14:10:12 -07:00 committed by GitHub
commit 29f905bfaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 2 deletions

View file

@ -1544,8 +1544,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",