Skip to content

Commit 4edf33e

Browse files
committed
Add tests for turbofish suggestions
1 parent 07a63e6 commit 4edf33e

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
mod a {
2+
fn foo() {
3+
vec![1, 2, 3].into_iter().collect(); //~ ERROR type annotations needed
4+
}
5+
fn bar() {
6+
vec!["a", "b", "c"].into_iter().collect(); //~ ERROR type annotations needed
7+
}
8+
fn qux() {
9+
vec!['a', 'b', 'c'].into_iter().collect(); //~ ERROR type annotations needed
10+
}
11+
}
12+
mod b {
13+
fn foo() {
14+
let _ = vec![1, 2, 3].into_iter().collect(); //~ ERROR type annotations needed
15+
}
16+
fn bar() {
17+
let _ = vec!["a", "b", "c"].into_iter().collect(); //~ ERROR type annotations needed
18+
}
19+
fn qux() {
20+
let _ = vec!['a', 'b', 'c'].into_iter().collect(); //~ ERROR type annotations needed
21+
}
22+
}
23+
24+
trait T: Sized {
25+
fn new() -> Self;
26+
}
27+
fn x<X: T>() -> X {
28+
T::new()
29+
}
30+
struct S;
31+
impl T for S {
32+
fn new() -> Self {
33+
S
34+
}
35+
}
36+
37+
fn foo() {
38+
x(); //~ ERROR type annotations needed
39+
}
40+
41+
fn bar() {
42+
let _ = x(); //~ ERROR type annotations needed
43+
}
44+
45+
fn main() {}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/appropriate-type-param-turbofish.rs:3:35
3+
|
4+
LL | vec![1, 2, 3].into_iter().collect();
5+
| ^^^^^^^ cannot infer type for type parameter `B` declared on the associated function `collect`
6+
|
7+
= note: cannot satisfy `_: std::iter::FromIterator<i32>`
8+
help: consider specifying the type argument in the method call
9+
|
10+
LL | vec![1, 2, 3].into_iter().collect::<B>();
11+
| ^^^^^
12+
13+
error[E0283]: type annotations needed
14+
--> $DIR/appropriate-type-param-turbofish.rs:6:41
15+
|
16+
LL | vec!["a", "b", "c"].into_iter().collect();
17+
| ^^^^^^^ cannot infer type for type parameter `B` declared on the associated function `collect`
18+
|
19+
= note: cannot satisfy `_: std::iter::FromIterator<&str>`
20+
help: consider specifying the type argument in the method call
21+
|
22+
LL | vec!["a", "b", "c"].into_iter().collect::<B>();
23+
| ^^^^^
24+
25+
error[E0283]: type annotations needed
26+
--> $DIR/appropriate-type-param-turbofish.rs:9:41
27+
|
28+
LL | vec!['a', 'b', 'c'].into_iter().collect();
29+
| ^^^^^^^ cannot infer type for type parameter `B` declared on the associated function `collect`
30+
|
31+
= note: cannot satisfy `_: std::iter::FromIterator<char>`
32+
help: consider specifying the type argument in the method call
33+
|
34+
LL | vec!['a', 'b', 'c'].into_iter().collect::<B>();
35+
| ^^^^^
36+
37+
error[E0283]: type annotations needed
38+
--> $DIR/appropriate-type-param-turbofish.rs:14:43
39+
|
40+
LL | let _ = vec![1, 2, 3].into_iter().collect();
41+
| - ^^^^^^^ cannot infer type for type parameter `B` declared on the associated function `collect`
42+
| |
43+
| consider giving this pattern a type
44+
|
45+
= note: cannot satisfy `_: std::iter::FromIterator<i32>`
46+
47+
error[E0283]: type annotations needed
48+
--> $DIR/appropriate-type-param-turbofish.rs:17:49
49+
|
50+
LL | let _ = vec!["a", "b", "c"].into_iter().collect();
51+
| - ^^^^^^^ cannot infer type for type parameter `B` declared on the associated function `collect`
52+
| |
53+
| consider giving this pattern a type
54+
|
55+
= note: cannot satisfy `_: std::iter::FromIterator<&str>`
56+
57+
error[E0283]: type annotations needed
58+
--> $DIR/appropriate-type-param-turbofish.rs:20:49
59+
|
60+
LL | let _ = vec!['a', 'b', 'c'].into_iter().collect();
61+
| - ^^^^^^^ cannot infer type for type parameter `B` declared on the associated function `collect`
62+
| |
63+
| consider giving this pattern a type
64+
|
65+
= note: cannot satisfy `_: std::iter::FromIterator<char>`
66+
67+
error[E0283]: type annotations needed
68+
--> $DIR/appropriate-type-param-turbofish.rs:38:5
69+
|
70+
LL | fn x<X: T>() -> X {
71+
| - required by this bound in `x`
72+
...
73+
LL | x();
74+
| ^ cannot infer type for type parameter `X` declared on the function `x`
75+
|
76+
= note: cannot satisfy `_: T`
77+
help: consider specifying the type argument in the function call
78+
|
79+
LL | x::<X>();
80+
| ^^^^^
81+
82+
error[E0283]: type annotations needed
83+
--> $DIR/appropriate-type-param-turbofish.rs:42:13
84+
|
85+
LL | fn x<X: T>() -> X {
86+
| - required by this bound in `x`
87+
...
88+
LL | let _ = x();
89+
| - ^ cannot infer type for type parameter `X` declared on the function `x`
90+
| |
91+
| consider giving this pattern a type
92+
|
93+
= note: cannot satisfy `_: T`
94+
help: consider specifying the type argument in the function call
95+
|
96+
LL | let _ = x::<X>();
97+
| ^^^^^
98+
99+
error: aborting due to 8 previous errors
100+
101+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)