Skip to content

Commit 5a2b70b

Browse files
committed
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
1 parent 1f587e4 commit 5a2b70b

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Regression test for issue #142488, a diagnostics ICE when trying to suggest missing methods
2+
// present in similar tuple types.
3+
// This is a few of the MCVEs from the issues and its many duplicates.
4+
5+
// 1
6+
fn main() {
7+
for a in x {
8+
//~^ ERROR: cannot find value `x` in this scope
9+
(a,).to_string()
10+
//~^ ERROR: the method `to_string` exists for tuple
11+
}
12+
}
13+
14+
// 2
15+
trait Trait {
16+
fn meth(self);
17+
}
18+
19+
impl<T, U: Trait> Trait for (T, U) {
20+
fn meth(self) {}
21+
}
22+
23+
fn mcve2() {
24+
((), std::collections::HashMap::new()).meth()
25+
//~^ ERROR: the method `meth` exists for tuple
26+
}
27+
28+
// 3
29+
trait I {}
30+
31+
struct Struct;
32+
impl I for Struct {}
33+
34+
trait Tr {
35+
fn f<A>(self) -> (A,)
36+
where
37+
Self: Sized,
38+
{
39+
loop {}
40+
}
41+
}
42+
43+
impl<T> Tr for T where T: I {}
44+
45+
fn mcve3() {
46+
Struct.f().f();
47+
//~^ ERROR: the method `f` exists for tuple
48+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
error[E0425]: cannot find value `x` in this scope
2+
--> $DIR/tuple-suggestions-issue-142488.rs:7:14
3+
|
4+
LL | for a in x {
5+
| ^ not found in this scope
6+
7+
error[E0599]: the method `to_string` exists for tuple `(_,)`, but its trait bounds were not satisfied
8+
--> $DIR/tuple-suggestions-issue-142488.rs:9:14
9+
|
10+
LL | (a,).to_string()
11+
| ^^^^^^^^^ method cannot be called on `(_,)` due to unsatisfied trait bounds
12+
|
13+
= note: the following trait bounds were not satisfied:
14+
`(_,): std::fmt::Display`
15+
which is required by `(_,): ToString`
16+
17+
error[E0599]: the method `meth` exists for tuple `((), HashMap<_, _>)`, but its trait bounds were not satisfied
18+
--> $DIR/tuple-suggestions-issue-142488.rs:24:44
19+
|
20+
LL | ((), std::collections::HashMap::new()).meth()
21+
| ^^^^ method cannot be called on `((), HashMap<_, _>)` due to unsatisfied trait bounds
22+
|
23+
note: trait bound `HashMap<_, _>: Trait` was not satisfied
24+
--> $DIR/tuple-suggestions-issue-142488.rs:19:12
25+
|
26+
LL | impl<T, U: Trait> Trait for (T, U) {
27+
| ^^^^^ ----- ------
28+
| |
29+
| unsatisfied trait bound introduced here
30+
= help: items from traits can only be used if the trait is implemented and in scope
31+
note: `Trait` defines an item `meth`, perhaps you need to implement it
32+
--> $DIR/tuple-suggestions-issue-142488.rs:15:1
33+
|
34+
LL | trait Trait {
35+
| ^^^^^^^^^^^
36+
37+
error[E0599]: the method `f` exists for tuple `(_,)`, but its trait bounds were not satisfied
38+
--> $DIR/tuple-suggestions-issue-142488.rs:46:16
39+
|
40+
LL | Struct.f().f();
41+
| ^ method cannot be called on `(_,)` due to unsatisfied trait bounds
42+
|
43+
note: the following trait bounds were not satisfied:
44+
`&(_,): I`
45+
`&mut (_,): I`
46+
`(_,): I`
47+
--> $DIR/tuple-suggestions-issue-142488.rs:43:27
48+
|
49+
LL | impl<T> Tr for T where T: I {}
50+
| -- - ^ unsatisfied trait bound introduced here
51+
= help: items from traits can only be used if the trait is implemented and in scope
52+
note: `Tr` defines an item `f`, perhaps you need to implement it
53+
--> $DIR/tuple-suggestions-issue-142488.rs:34:1
54+
|
55+
LL | trait Tr {
56+
| ^^^^^^^^
57+
58+
error: aborting due to 4 previous errors
59+
60+
Some errors have detailed explanations: E0425, E0599.
61+
For more information about an error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)