summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2023-05-03 10:40:08 +0800
committeryukang <moorekang@gmail.com>2023-05-08 14:58:09 +0800
commit6b76588222eb1a69f681c00f9d073edb43401ba7 (patch)
treec8ef38f46d6e423f3bfb7e9edcdeba8fe82d7f65 /compiler/rustc_parse/src/parser
parent04c53444dff325a0a3a4cb88cb952fbf341861ec (diff)
downloadrust-6b76588222eb1a69f681c00f9d073edb43401ba7.tar.gz
rust-6b76588222eb1a69f681c00f9d073edb43401ba7.zip
suggest struct when we get colon in fileds in enum
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 6ca88200dc5..2a47711a8d3 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -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
                 },