Skip to content

Commit

Permalink
make it more accurate by parsing ty
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed May 8, 2023
1 parent 6b76588 commit 0e8703d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)?
};
Expand Down

0 comments on commit 0e8703d

Please sign in to comment.