1
Fork 0

suggest struct when we get colon in fileds in enum

This commit is contained in:
yukang 2023-05-03 10:40:08 +08:00
parent 04c53444df
commit 6b76588222
4 changed files with 37 additions and 5 deletions

View file

@ -1262,6 +1262,7 @@ impl<'a> Parser<'a> {
}
}
let prev_span = self.prev_token.span;
let id = self.parse_ident()?;
let mut generics = self.parse_generics()?;
generics.where_clause = self.parse_where_clause()?;
@ -1275,6 +1276,14 @@ impl<'a> Parser<'a> {
self.parse_delim_comma_seq(Delimiter::Brace, |p| p.parse_enum_variant()).map_err(
|mut e| {
e.span_label(id.span, "while parsing this enum");
if self.token == token::Colon {
e.span_suggestion_verbose(
prev_span,
"perhaps you meant to use `struct` here",
"struct".to_string(),
Applicability::MaybeIncorrect,
);
}
self.recover_stmt();
e
},