diff options
author | yukang <moorekang@gmail.com> | 2023-05-06 02:27:32 +0800 |
---|---|---|
committer | yukang <moorekang@gmail.com> | 2023-05-08 15:07:36 +0800 |
commit | 0e8703da3e33a76d12186e36a23c87870bc5d7bb (patch) | |
tree | 27e3555b8ce6508fa96b151fe9a2db16162593b3 /compiler/rustc_parse | |
parent | 6b76588222eb1a69f681c00f9d073edb43401ba7 (diff) | |
download | rust-0e8703da3e33a76d12186e36a23c87870bc5d7bb.tar.gz |
make it more accurate by parsing ty
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 2a47711a8d3..49e05efd39d 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -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 }, )? }; |