about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2025-08-22 20:35:21 +0000
committerJosh Stone <jistone@redhat.com>2025-09-08 14:26:03 -0700
commit6694a010befab52670db26ad17116d91bec43005 (patch)
tree603366c4baa5f77079397c082f99d40d1b5e993c
parent052861f115b52031f0a9be06c8e4386d30d6f5fc (diff)
downloadrust-6694a010befab52670db26ad17116d91bec43005.tar.gz
rust-6694a010befab52670db26ad17116d91bec43005.zip
add regression test for issue 142488
there are a lot of MCVEs there, so this is only a few of them, not all
duplicates that were opened

(cherry picked from commit 5a2b70b2027d00823659a85c2791d7611bcf1989)
-rw-r--r--tests/ui/methods/tuple-suggestions-issue-142488.rs48
-rw-r--r--tests/ui/methods/tuple-suggestions-issue-142488.stderr61
2 files changed, 109 insertions, 0 deletions
diff --git a/tests/ui/methods/tuple-suggestions-issue-142488.rs b/tests/ui/methods/tuple-suggestions-issue-142488.rs
new file mode 100644
index 00000000000..f6c58fce9a1
--- /dev/null
+++ b/tests/ui/methods/tuple-suggestions-issue-142488.rs
@@ -0,0 +1,48 @@
+// Regression test for issue #142488, a diagnostics ICE when trying to suggest missing methods
+// present in similar tuple types.
+// This is a few of the MCVEs from the issues and its many duplicates.
+
+// 1
+fn main() {
+    for a in x {
+        //~^ ERROR: cannot find value `x` in this scope
+        (a,).to_string()
+        //~^ ERROR: the method `to_string` exists for tuple
+    }
+}
+
+// 2
+trait Trait {
+    fn meth(self);
+}
+
+impl<T, U: Trait> Trait for (T, U) {
+    fn meth(self) {}
+}
+
+fn mcve2() {
+    ((), std::collections::HashMap::new()).meth()
+    //~^ ERROR: the method `meth` exists for tuple
+}
+
+// 3
+trait I {}
+
+struct Struct;
+impl I for Struct {}
+
+trait Tr {
+    fn f<A>(self) -> (A,)
+    where
+        Self: Sized,
+    {
+        loop {}
+    }
+}
+
+impl<T> Tr for T where T: I {}
+
+fn mcve3() {
+    Struct.f().f();
+    //~^ ERROR: the method `f` exists for tuple
+}
diff --git a/tests/ui/methods/tuple-suggestions-issue-142488.stderr b/tests/ui/methods/tuple-suggestions-issue-142488.stderr
new file mode 100644
index 00000000000..f9363bb216f
--- /dev/null
+++ b/tests/ui/methods/tuple-suggestions-issue-142488.stderr
@@ -0,0 +1,61 @@
+error[E0425]: cannot find value `x` in this scope
+  --> $DIR/tuple-suggestions-issue-142488.rs:7:14
+   |
+LL |     for a in x {
+   |              ^ not found in this scope
+
+error[E0599]: the method `to_string` exists for tuple `(_,)`, but its trait bounds were not satisfied
+  --> $DIR/tuple-suggestions-issue-142488.rs:9:14
+   |
+LL |         (a,).to_string()
+   |              ^^^^^^^^^ method cannot be called on `(_,)` due to unsatisfied trait bounds
+   |
+   = note: the following trait bounds were not satisfied:
+           `(_,): std::fmt::Display`
+           which is required by `(_,): ToString`
+
+error[E0599]: the method `meth` exists for tuple `((), HashMap<_, _>)`, but its trait bounds were not satisfied
+  --> $DIR/tuple-suggestions-issue-142488.rs:24:44
+   |
+LL |     ((), std::collections::HashMap::new()).meth()
+   |                                            ^^^^ method cannot be called on `((), HashMap<_, _>)` due to unsatisfied trait bounds
+   |
+note: trait bound `HashMap<_, _>: Trait` was not satisfied
+  --> $DIR/tuple-suggestions-issue-142488.rs:19:12
+   |
+LL | impl<T, U: Trait> Trait for (T, U) {
+   |            ^^^^^  -----     ------
+   |            |
+   |            unsatisfied trait bound introduced here
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Trait` defines an item `meth`, perhaps you need to implement it
+  --> $DIR/tuple-suggestions-issue-142488.rs:15:1
+   |
+LL | trait Trait {
+   | ^^^^^^^^^^^
+
+error[E0599]: the method `f` exists for tuple `(_,)`, but its trait bounds were not satisfied
+  --> $DIR/tuple-suggestions-issue-142488.rs:46:16
+   |
+LL |     Struct.f().f();
+   |                ^ method cannot be called on `(_,)` due to unsatisfied trait bounds
+   |
+note: the following trait bounds were not satisfied:
+      `&(_,): I`
+      `&mut (_,): I`
+      `(_,): I`
+  --> $DIR/tuple-suggestions-issue-142488.rs:43:27
+   |
+LL | impl<T> Tr for T where T: I {}
+   |         --     -          ^ unsatisfied trait bound introduced here
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Tr` defines an item `f`, perhaps you need to implement it
+  --> $DIR/tuple-suggestions-issue-142488.rs:34:1
+   |
+LL | trait Tr {
+   | ^^^^^^^^
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0425, E0599.
+For more information about an error, try `rustc --explain E0425`.