about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Baikov <manpacket@gmail.com>2024-06-30 07:12:26 -0400
committerMichael Baikov <manpacket@gmail.com>2024-06-30 07:12:26 -0400
commit8a0e1ab565346491f932612508e57c225ddbb34c (patch)
tree3293f887b1bb7ac4c25735a9d390463439db06ca
parent716752ebe6974b5c6ab9b34b894e075f3e4a4b1e (diff)
downloadrust-8a0e1ab565346491f932612508e57c225ddbb34c.tar.gz
rust-8a0e1ab565346491f932612508e57c225ddbb34c.zip
Add a regression test for #123630
compiler should not suggest nonsensical signatures, original suggestion was

error[E0308]: mismatched types
 --> src/lib.rs:3:31
  |
3 | fn select<F, I>(filter: F) -> Select<F, I> {
  |    ------                     ^^^^^^^^^^^^ expected `Select<F, I>`, found `()`
  |    |
  |    implicitly returns `()` as its body has no tail or `return` expression
  |
  = note: expected struct `Select<F, I>`
          found unit type `()`

error[E0282]: type annotations needed for `Select<{closure@src/lib.rs:8:22: 8:25}, I>`
 --> src/lib.rs:8:9
  |
8 |     let lit = select(|x| match x {
  |         ^^^
  |
help: consider giving `lit` an explicit type, where the type for type parameter `I` is specified
  |
8 |     let lit: Select<{closure@src/lib.rs:8:22: 8:25}, I> = select(|x| match x {
  |            ++++++++++++++++++++++++++++++++++++++++++++

Some errors have detailed explanations: E0282, E0308.
For more information about an error, try `rustc --explain E0282`.
-rw-r--r--tests/ui/suggestions/types/dont-suggest-path-names.rs17
-rw-r--r--tests/ui/suggestions/types/dont-suggest-path-names.stderr26
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/suggestions/types/dont-suggest-path-names.rs b/tests/ui/suggestions/types/dont-suggest-path-names.rs
new file mode 100644
index 00000000000..d160e49cd03
--- /dev/null
+++ b/tests/ui/suggestions/types/dont-suggest-path-names.rs
@@ -0,0 +1,17 @@
+// This is a regression test for #123630
+//
+// Prior to #123703 this was resulting in compiler suggesting add a type signature
+// for `lit` containing path to a file containing `Select` - something obviously invalid.
+
+struct Select<F, I>(F, I);
+fn select<F, I>(filter: F) -> Select<F, I> {}
+//~^ 7:31: 7:43: mismatched types [E0308]
+
+fn parser1() {
+    let lit = select(|x| match x {
+        //~^ 11:23: 11:24: type annotations needed [E0282]
+        _ => (),
+    });
+}
+
+fn main() {}
diff --git a/tests/ui/suggestions/types/dont-suggest-path-names.stderr b/tests/ui/suggestions/types/dont-suggest-path-names.stderr
new file mode 100644
index 00000000000..5c71e350f81
--- /dev/null
+++ b/tests/ui/suggestions/types/dont-suggest-path-names.stderr
@@ -0,0 +1,26 @@
+error[E0308]: mismatched types
+  --> $DIR/dont-suggest-path-names.rs:7:31
+   |
+LL | fn select<F, I>(filter: F) -> Select<F, I> {}
+   |    ------                     ^^^^^^^^^^^^ expected `Select<F, I>`, found `()`
+   |    |
+   |    implicitly returns `()` as its body has no tail or `return` expression
+   |
+   = note: expected struct `Select<F, I>`
+           found unit type `()`
+
+error[E0282]: type annotations needed
+  --> $DIR/dont-suggest-path-names.rs:11:23
+   |
+LL |     let lit = select(|x| match x {
+   |                       ^        - type must be known at this point
+   |
+help: consider giving this closure parameter an explicit type
+   |
+LL |     let lit = select(|x: /* Type */| match x {
+   |                        ++++++++++++
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0282, E0308.
+For more information about an error, try `rustc --explain E0282`.