about summary refs log tree commit diff
path: root/src/test/ui/parser
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-07-13 19:32:35 +0530
committerGitHub <noreply@github.com>2022-07-13 19:32:35 +0530
commit980579a5e9f5fcad63ef71f536efec15ccd56511 (patch)
tree97af1124c9f5ff63987ced8fce1cf941f2a1fa29 /src/test/ui/parser
parent1e7d04b23b6e9d177e7d879b05b4ce3f00ee5a0e (diff)
parent9fcb9c6648331f372ee58ce4489d3d43a0723c59 (diff)
downloadrust-980579a5e9f5fcad63ef71f536efec15ccd56511.tar.gz
rust-980579a5e9f5fcad63ef71f536efec15ccd56511.zip
Rollup merge of #99030 - rust-lang:notriddle/field-recovery, r=petrochenkov
diagnostics: error messages when struct literals fail to parse

If an expression is supplied where a field is expected, the parser can become convinced that it's a shorthand field syntax when it's not.

This PR addresses it by explicitly recording the permitted `:` token immediately after the identifier, and also adds a suggestion to insert the name of the field if it looks like a complex expression.

Fixes #98917
Diffstat (limited to 'src/test/ui/parser')
-rw-r--r--src/test/ui/parser/issues/issue-52496.stderr7
-rw-r--r--src/test/ui/parser/issues/issue-62973.stderr16
-rw-r--r--src/test/ui/parser/removed-syntax-with-2.rs2
-rw-r--r--src/test/ui/parser/removed-syntax-with-2.stderr4
4 files changed, 19 insertions, 10 deletions
diff --git a/src/test/ui/parser/issues/issue-52496.stderr b/src/test/ui/parser/issues/issue-52496.stderr
index 9dbf26ef4b6..77335c64c21 100644
--- a/src/test/ui/parser/issues/issue-52496.stderr
+++ b/src/test/ui/parser/issues/issue-52496.stderr
@@ -4,12 +4,13 @@ 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 `}`
+   |             |     |
+   |             |     help: try naming a field: `bar:`
    |             while parsing this struct
 
 error: expected identifier, found `.`
diff --git a/src/test/ui/parser/issues/issue-62973.stderr b/src/test/ui/parser/issues/issue-62973.stderr
index bc3358fc6ba..4737bc71860 100644
--- a/src/test/ui/parser/issues/issue-62973.stderr
+++ b/src/test/ui/parser/issues/issue-62973.stderr
@@ -20,15 +20,23 @@ 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 `}`
-   |        |       |       |
-   |        |       |       help: `}` may belong here
+   |        ^       -        ^ expected one of `,`, `:`, or `}`
+   |        |       |
    |        |       while parsing this struct
    |        unclosed delimiter
+   |
+help: `}` may belong here
+   |
+LL | fn p() { match s { v, E} { [) {) }
+   |                        +
+help: try naming a field
+   |
+LL | fn p() { match s { v, E: E { [) {) }
+   |                       ++
 
 error: struct literals are not allowed here
   --> $DIR/issue-62973.rs:6:16
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