Skip to content

Commit 82d31c4

Browse files
improve suggestions output and add ui test
1 parent 9c63817 commit 82d31c4

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/librustc_typeck/check/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
147147
if no_argument_methods.len() > 0 {
148148
no_argument_methods.iter()
149149
.take(5)
150-
.map(|method| format!("{}", method.name()))
150+
.map(|method| format!(".{}()", method.name()))
151151
.collect::<Vec<String>>()
152152
.join("\n - ")
153153
} else {
154154
methods.iter()
155155
.take(5)
156-
.map(|method| format!("{}", method.name()))
156+
.map(|method| format!(".{}()", method.name()))
157157
.collect::<Vec<String>>()
158158
.join("\n - ")
159159
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coerce-suggestions.rs:17:20
3+
|
4+
17 | let x: usize = String::new();
5+
| ^^^^^^^^^^^^^ expected usize, found struct `std::string::String`
6+
|
7+
= note: expected type `usize`
8+
= note: found type `std::string::String`
9+
= help: here are some functions which might fulfill your needs:
10+
- .capacity()
11+
- .len()
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/coerce-suggestions.rs:23:19
15+
|
16+
23 | let x: &str = String::new();
17+
| ^^^^^^^^^^^^^ expected &str, found struct `std::string::String`
18+
|
19+
= note: expected type `&str`
20+
= note: found type `std::string::String`
21+
= help: try with `&String::new()`
22+
23+
error[E0308]: mismatched types
24+
--> $DIR/coerce-suggestions.rs:30:10
25+
|
26+
30 | test(&y);
27+
| ^^ types differ in mutability
28+
|
29+
= note: expected type `&mut std::string::String`
30+
= note: found type `&std::string::String`
31+
= help: try with `&mut y`
32+
33+
error[E0308]: mismatched types
34+
--> $DIR/coerce-suggestions.rs:36:11
35+
|
36+
36 | test2(&y);
37+
| ^^ types differ in mutability
38+
|
39+
= note: expected type `&mut i32`
40+
= note: found type `&std::string::String`
41+
42+
error[E0308]: mismatched types
43+
--> $DIR/coerce-suggestions.rs:42:9
44+
|
45+
42 | f = box f;
46+
| ^^^^^ cyclic type of infinite size
47+
|
48+
= note: expected type `_`
49+
= note: found type `Box<_>`
50+
51+
error: aborting due to 5 previous errors
52+

0 commit comments

Comments
 (0)