make it more accurate by parsing ty

This commit is contained in:
yukang 2023-05-06 02:27:32 +08:00
parent 6b76588222
commit 0e8703da3e

View File

@ -1274,18 +1274,28 @@ impl<'a> Parser<'a> {
(thin_vec![], false)
} else {
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");
|mut err| {
err.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,
);
let snapshot = self.create_snapshot_for_diagnostic();
self.bump();
match self.parse_ty() {
Ok(_) => {
err.span_suggestion_verbose(
prev_span,
"perhaps you meant to use `struct` here",
"struct".to_string(),
Applicability::MaybeIncorrect,
);
}
Err(e) => {
e.cancel();
}
}
self.restore_snapshot(snapshot);
}
self.recover_stmt();
e
err
},
)?
};