about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-07-07 14:59:54 -0700
committerMichael Howell <michael@notriddle.com>2022-07-07 14:59:54 -0700
commitd496a4f8bb26709e58ce8821de07f7078d2f615d (patch)
tree20912216cf48250460738b220a3955f4f56ceb9c /compiler/rustc_parse/src/parser/expr.rs
parent0f573a0c5474ad65bc9f0b0fd3a94d1b06dcfdfa (diff)
downloadrust-d496a4f8bb26709e58ce8821de07f7078d2f615d.tar.gz
rust-d496a4f8bb26709e58ce8821de07f7078d2f615d.zip
diagnostics: mention the `:` token when struct fields fail to parse
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 2c43563b104..36d63378550 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -3012,6 +3012,11 @@ impl<'a> Parser<'a> {
                 }
             };
 
+            let is_shorthand = parsed_field.as_ref().map_or(false, |f| f.ident.span == f.expr.span);
+            // A shorthand field can be turned into a full field with `:`.
+            // We should point this out.
+            self.check_or_expected(!is_shorthand, TokenType::Token(token::Colon));
+
             match self.expect_one_of(&[token::Comma], &[token::CloseDelim(close_delim)]) {
                 Ok(_) => {
                     if let Some(f) = parsed_field.or(recovery_field) {