diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2023-11-07 00:09:33 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2023-11-29 18:47:32 +0000 |
| commit | 4e524386e9afb232783a3bcaecd1d39620d5fb5f (patch) | |
| tree | 1a7ab63e30fb2c7406bb491c28214f94d5805b0b /compiler/rustc_parse/src/parser | |
| parent | 1575e6e96e1b61fef2d82fbb320881813e0a4173 (diff) | |
| download | rust-4e524386e9afb232783a3bcaecd1d39620d5fb5f.tar.gz rust-4e524386e9afb232783a3bcaecd1d39620d5fb5f.zip | |
Always emit help when failing to parse enum variant
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 5e73472c842..ab18e40482e 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1450,6 +1450,8 @@ impl<'a> Parser<'a> { self.recover_diff_marker(); let variant_attrs = self.parse_outer_attributes()?; self.recover_diff_marker(); + let help = "enum variants can be `Variant`, `Variant = <integer>`, \ + `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`"; self.collect_tokens_trailing_token( variant_attrs, ForceCollect::No, @@ -1486,6 +1488,7 @@ impl<'a> Parser<'a> { this.eat_to_tokens(&[&token::CloseDelim(Delimiter::Brace)]); this.bump(); // } err.span_label(span, "while parsing this enum"); + err.help(help); err.emit(); (thin_vec![], true) } @@ -1502,6 +1505,7 @@ impl<'a> Parser<'a> { this.eat_to_tokens(&[&token::CloseDelim(Delimiter::Parenthesis)]); this.bump(); // ) err.span_label(span, "while parsing this enum"); + err.help(help); err.emit(); thin_vec![] } @@ -1527,8 +1531,9 @@ impl<'a> Parser<'a> { Ok((Some(vr), TrailingToken::MaybeComma)) }, - ).map_err(|mut err| { - err.help("enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`"); + ) + .map_err(|mut err| { + err.help(help); err }) } |
