diff options
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/parser/issues/issue-52496.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/parser/issues/issue-62973.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/parser/removed-syntax-with-2.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/parser/removed-syntax-with-2.stderr | 4 |
5 files changed, 12 insertions, 7 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) { diff --git a/src/test/ui/parser/issues/issue-52496.stderr b/src/test/ui/parser/issues/issue-52496.stderr index 9dbf26ef4b6..cf5c621020f 100644 --- a/src/test/ui/parser/issues/issue-52496.stderr +++ b/src/test/ui/parser/issues/issue-52496.stderr @@ -4,11 +4,11 @@ error: float literals must have an integer part LL | let _ = Foo { bar: .5, baz: 42 }; | ^^ help: must have an integer part: `0.5` -error: expected one of `,` or `}`, found `.` +error: expected one of `,`, `:`, or `}`, found `.` --> $DIR/issue-52496.rs:8:22 | LL | let _ = Foo { bar.into(), bat: -1, . }; - | --- ^ expected one of `,` or `}` + | --- ^ expected one of `,`, `:`, or `}` | | | while parsing this struct diff --git a/src/test/ui/parser/issues/issue-62973.stderr b/src/test/ui/parser/issues/issue-62973.stderr index bc3358fc6ba..d526c9d0bcc 100644 --- a/src/test/ui/parser/issues/issue-62973.stderr +++ b/src/test/ui/parser/issues/issue-62973.stderr @@ -20,11 +20,11 @@ LL | LL | | ^ -error: expected one of `,` or `}`, found `{` +error: expected one of `,`, `:`, or `}`, found `{` --> $DIR/issue-62973.rs:6:8 | LL | fn p() { match s { v, E { [) {) } - | ^ - -^ expected one of `,` or `}` + | ^ - -^ expected one of `,`, `:`, or `}` | | | | | | | help: `}` may belong here | | while parsing this struct diff --git a/src/test/ui/parser/removed-syntax-with-2.rs b/src/test/ui/parser/removed-syntax-with-2.rs index 8a489e71990..451057c66a1 100644 --- a/src/test/ui/parser/removed-syntax-with-2.rs +++ b/src/test/ui/parser/removed-syntax-with-2.rs @@ -6,6 +6,6 @@ fn main() { let a = S { foo: (), bar: () }; let b = S { foo: (), with a }; - //~^ ERROR expected one of `,` or `}`, found `a` + //~^ ERROR expected one of `,`, `:`, or `}`, found `a` //~| ERROR missing field `bar` in initializer of `S` } diff --git a/src/test/ui/parser/removed-syntax-with-2.stderr b/src/test/ui/parser/removed-syntax-with-2.stderr index 2c96dceb587..c6ae1ce674f 100644 --- a/src/test/ui/parser/removed-syntax-with-2.stderr +++ b/src/test/ui/parser/removed-syntax-with-2.stderr @@ -1,8 +1,8 @@ -error: expected one of `,` or `}`, found `a` +error: expected one of `,`, `:`, or `}`, found `a` --> $DIR/removed-syntax-with-2.rs:8:31 | LL | let b = S { foo: (), with a }; - | - ^ expected one of `,` or `}` + | - ^ expected one of `,`, `:`, or `}` | | | while parsing this struct |
