1
Fork 0

diagnostics: suggest naming a field after failing to parse

This commit is contained in:
Michael Howell 2022-07-07 15:20:08 -07:00
parent d496a4f8bb
commit 6713dde898
3 changed files with 27 additions and 5 deletions

View file

@ -3037,6 +3037,19 @@ impl<'a> Parser<'a> {
",",
Applicability::MachineApplicable,
);
} else if is_shorthand
&& (AssocOp::from_token(&self.token).is_some()
|| matches!(&self.token.kind, token::OpenDelim(_))
|| self.token.kind == token::Dot)
{
// Looks like they tried to write a shorthand, complex expression.
let ident = parsed_field.expect("is_shorthand implies Some").ident;
e.span_suggestion(
ident.span.shrink_to_lo(),
"try naming a field",
&format!("{ident}: "),
Applicability::HasPlaceholders,
);
}
}
if !recover {