diff options
| author | Michael Howell <michael@notriddle.com> | 2022-07-07 15:20:08 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2022-07-07 15:20:08 -0700 |
| commit | 6713dde898ef81042a51d940d36150c52cb697b6 (patch) | |
| tree | b188e771ae70c770fa730a17d23cecd2855f6ef0 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | d496a4f8bb26709e58ce8821de07f7078d2f615d (diff) | |
| download | rust-6713dde898ef81042a51d940d36150c52cb697b6.tar.gz rust-6713dde898ef81042a51d940d36150c52cb697b6.zip | |
diagnostics: suggest naming a field after failing to parse
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 36d63378550..f2765e4997c 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -3037,6 +3037,19 @@ impl<'a> Parser<'a> { ",", Applicability::MachineApplicable, ); + } else if is_shorthand + && (AssocOp::from_token(&self.token).is_some() + || matches!(&self.token.kind, token::OpenDelim(_)) + || self.token.kind == token::Dot) + { + // Looks like they tried to write a shorthand, complex expression. + let ident = parsed_field.expect("is_shorthand implies Some").ident; + e.span_suggestion( + ident.span.shrink_to_lo(), + "try naming a field", + &format!("{ident}: "), + Applicability::HasPlaceholders, + ); } } if !recover { |
