about summary refs log tree commit diff
path: root/tests/ui/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-02 05:03:46 +0000
committerbors <bors@rust-lang.org>2024-03-02 05:03:46 +0000
commit4cdd20584ccb75890d7d9bfae266054abfae5d46 (patch)
treed9b0b65bb0610b950e674720a90c5d5515e3be88 /tests/ui/parser
parent1dc5f73c138bc316218c99cda09bcb12bf90e26e (diff)
parentbde2dfb127a524321d6629607df5f3008921327e (diff)
downloadrust-4cdd20584ccb75890d7d9bfae266054abfae5d46.tar.gz
rust-4cdd20584ccb75890d7d9bfae266054abfae5d46.zip
Auto merge of #121657 - estebank:issue-119665, r=davidtwco
Detect more cases of `=` to `:` typo

When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`.

```
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
 --> file.rs:2:32
  |
2 |     let _: std::env::temp_dir().join("foo");
  |          -                     ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
  |          |
  |          while parsing the type for `_`
  |          help: use `=` if you meant to assign
```

Fix #119665.
Diffstat (limited to 'tests/ui/parser')
-rw-r--r--tests/ui/parser/better-expected.stderr6
-rw-r--r--tests/ui/parser/issues/issue-84117.stderr14
-rw-r--r--tests/ui/parser/missing-closing-angle-bracket-eq-constraint.stderr18
-rw-r--r--tests/ui/parser/nested-missing-closing-angle-bracket.stderr2
-rw-r--r--tests/ui/parser/recover/recover-colon-instead-of-eq-in-local.rs3
-rw-r--r--tests/ui/parser/recover/recover-colon-instead-of-eq-in-local.stderr11
-rw-r--r--tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.stderr4
7 files changed, 37 insertions, 21 deletions
diff --git a/tests/ui/parser/better-expected.stderr b/tests/ui/parser/better-expected.stderr
index 6cb9a49605f..f4ec933be16 100644
--- a/tests/ui/parser/better-expected.stderr
+++ b/tests/ui/parser/better-expected.stderr
@@ -2,9 +2,9 @@ error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `]`, found `3`
   --> $DIR/better-expected.rs:2:19
    |
 LL |     let x: [isize 3];
-   |         -         ^ expected one of 7 possible tokens
-   |         |
-   |         while parsing the type for `x`
+   |          -        ^ expected one of 7 possible tokens
+   |          |
+   |          while parsing the type for `x`
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/parser/issues/issue-84117.stderr b/tests/ui/parser/issues/issue-84117.stderr
index 958f3b40bb0..9f603b84434 100644
--- a/tests/ui/parser/issues/issue-84117.stderr
+++ b/tests/ui/parser/issues/issue-84117.stderr
@@ -2,9 +2,9 @@ error: expected one of `>`, a const expression, lifetime, or type, found `}`
   --> $DIR/issue-84117.rs:2:67
    |
 LL |     let outer_local:e_outer<&str, { let inner_local:e_inner<&str, }
-   |                                         -----------               ^ expected one of `>`, a const expression, lifetime, or type
-   |                                         |
-   |                                         while parsing the type for `inner_local`
+   |                                                    -              ^ expected one of `>`, a const expression, lifetime, or type
+   |                                                    |
+   |                                                    while parsing the type for `inner_local`
    |
 help: you might have meant to end the type parameters here
    |
@@ -25,7 +25,7 @@ error: expected one of `,` or `>`, found `}`
   --> $DIR/issue-84117.rs:8:1
    |
 LL |     let outer_local:e_outer<&str, { let inner_local:e_inner<&str, }
-   |         ----------- while parsing the type for `outer_local`       - expected one of `,` or `>`
+   |                    - while parsing the type for `outer_local`      - expected one of `,` or `>`
 ...
 LL | }
    | ^ unexpected token
@@ -43,9 +43,9 @@ error: expected one of `>`, a const expression, lifetime, or type, found `}`
   --> $DIR/issue-84117.rs:2:67
    |
 LL |     let outer_local:e_outer<&str, { let inner_local:e_inner<&str, }
-   |                                         -----------               ^ expected one of `>`, a const expression, lifetime, or type
-   |                                         |
-   |                                         while parsing the type for `inner_local`
+   |                                                    -              ^ expected one of `>`, a const expression, lifetime, or type
+   |                                                    |
+   |                                                    while parsing the type for `inner_local`
    |
    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
 help: you might have meant to end the type parameters here
diff --git a/tests/ui/parser/missing-closing-angle-bracket-eq-constraint.stderr b/tests/ui/parser/missing-closing-angle-bracket-eq-constraint.stderr
index b21e788aa73..f01da7a38f3 100644
--- a/tests/ui/parser/missing-closing-angle-bracket-eq-constraint.stderr
+++ b/tests/ui/parser/missing-closing-angle-bracket-eq-constraint.stderr
@@ -2,9 +2,9 @@ error: expected one of `,`, `:`, or `>`, found `=`
   --> $DIR/missing-closing-angle-bracket-eq-constraint.rs:7:23
    |
 LL |   let v : Vec<(u32,_) = vec![];
-   |       -               ^ expected one of `,`, `:`, or `>`
-   |       |
-   |       while parsing the type for `v`
+   |         -             ^ expected one of `,`, `:`, or `>`
+   |         |
+   |         while parsing the type for `v`
    |
 help: you might have meant to end the type parameters here
    |
@@ -15,9 +15,9 @@ error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `{`
   --> $DIR/missing-closing-angle-bracket-eq-constraint.rs:13:32
    |
 LL |   let foo : Foo::<T1, T2 = Foo {_a : arg1, _b : arg2};
-   |       ---                      ^ expected one of 7 possible tokens
-   |       |
-   |       while parsing the type for `foo`
+   |           -                    ^ expected one of 7 possible tokens
+   |           |
+   |           while parsing the type for `foo`
    |
 help: you might have meant to end the type parameters here
    |
@@ -28,9 +28,9 @@ error: expected one of `,`, `:`, or `>`, found `=`
   --> $DIR/missing-closing-angle-bracket-eq-constraint.rs:18:18
    |
 LL |   let v : Vec<'a = vec![];
-   |       -          ^ expected one of `,`, `:`, or `>`
-   |       |
-   |       while parsing the type for `v`
+   |         -        ^ expected one of `,`, `:`, or `>`
+   |         |
+   |         while parsing the type for `v`
    |
 help: you might have meant to end the type parameters here
    |
diff --git a/tests/ui/parser/nested-missing-closing-angle-bracket.stderr b/tests/ui/parser/nested-missing-closing-angle-bracket.stderr
index 8d69125f8e9..2541d9af184 100644
--- a/tests/ui/parser/nested-missing-closing-angle-bracket.stderr
+++ b/tests/ui/parser/nested-missing-closing-angle-bracket.stderr
@@ -2,7 +2,7 @@ error: expected one of `,` or `>`, found `;`
   --> $DIR/nested-missing-closing-angle-bracket.rs:2:46
    |
 LL |   let v : Vec::<Vec<(u32,_,_)> = vec![vec![]];
-   |       - while parsing the type for `v`       ^ expected one of `,` or `>`
+   |         - while parsing the type for `v`     ^ expected one of `,` or `>`
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/parser/recover/recover-colon-instead-of-eq-in-local.rs b/tests/ui/parser/recover/recover-colon-instead-of-eq-in-local.rs
new file mode 100644
index 00000000000..ed4de58cd23
--- /dev/null
+++ b/tests/ui/parser/recover/recover-colon-instead-of-eq-in-local.rs
@@ -0,0 +1,3 @@
+fn main() {
+    let _: std::env::temp_dir().join("foo"); //~ ERROR expected one of
+}
diff --git a/tests/ui/parser/recover/recover-colon-instead-of-eq-in-local.stderr b/tests/ui/parser/recover/recover-colon-instead-of-eq-in-local.stderr
new file mode 100644
index 00000000000..d03f3ae0283
--- /dev/null
+++ b/tests/ui/parser/recover/recover-colon-instead-of-eq-in-local.stderr
@@ -0,0 +1,11 @@
+error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
+  --> $DIR/recover-colon-instead-of-eq-in-local.rs:2:32
+   |
+LL |     let _: std::env::temp_dir().join("foo");
+   |          -                     ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
+   |          |
+   |          while parsing the type for `_`
+   |          help: use `=` if you meant to assign
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.stderr b/tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.stderr
index 0d377416700..c089e0ba969 100644
--- a/tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.stderr
+++ b/tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.stderr
@@ -8,7 +8,9 @@ error: expected one of `->`, `;`, or `=`, found `~`
   --> $DIR/removed-syntax-fn-sigil.rs:2:14
    |
 LL |     let x: fn~() = || ();
-   |              ^ expected one of `->`, `;`, or `=`
+   |          -   ^ expected one of `->`, `;`, or `=`
+   |          |
+   |          while parsing the type for `x`
 
 error: aborting due to 2 previous errors