Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b3488b2

Browse files
committedJan 5, 2023
Suggest changing argument on type error
1 parent 7da7342 commit b3488b2

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-rustfix
2+
fn main() {
3+
let mut v = Vec::new();
4+
v.push(0i32);
5+
//~^ NOTE this is of type `i32`, which makes `v` to be inferred as `Vec<i32>`
6+
v.push(0);
7+
v.push(1i32); //~ ERROR mismatched types
8+
//~^ NOTE expected `i32`, found `u32`
9+
//~| NOTE arguments to this function are incorrect
10+
//~| NOTE associated function defined here
11+
//~| HELP change the type of the numeric literal from `u32` to `i32`
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
// run-rustfix
12
fn main() {
2-
let v = Vec::new();
3+
let mut v = Vec::new();
4+
v.push(0i32);
5+
//~^ NOTE this is of type `i32`, which makes `v` to be inferred as `Vec<i32>`
36
v.push(0);
4-
//~^ NOTE this is of type `{integer}`, which makes `v` to be inferred as `Vec<{integer}>`
5-
v.push(0);
6-
v.push(""); //~ ERROR mismatched types
7-
//~^ NOTE expected integer, found `&str`
7+
v.push(1u32); //~ ERROR mismatched types
8+
//~^ NOTE expected `i32`, found `u32`
89
//~| NOTE arguments to this function are incorrect
910
//~| NOTE associated function defined here
11+
//~| HELP change the type of the numeric literal from `u32` to `i32`
1012
}

‎src/test/ui/type/type-check/point-at-inference-3.stderr

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
error[E0308]: mismatched types
2-
--> $DIR/point-at-inference-3.rs:6:12
2+
--> $DIR/point-at-inference-3.rs:7:12
33
|
4-
LL | v.push(0);
5-
| - this is of type `{integer}`, which makes `v` to be inferred as `Vec<{integer}>`
4+
LL | v.push(0i32);
5+
| ---- this is of type `i32`, which makes `v` to be inferred as `Vec<i32>`
66
...
7-
LL | v.push("");
8-
| ---- ^^ expected integer, found `&str`
7+
LL | v.push(1u32);
8+
| ---- ^^^^ expected `i32`, found `u32`
99
| |
1010
| arguments to this function are incorrect
1111
|
1212
note: associated function defined here
1313
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
14+
help: change the type of the numeric literal from `u32` to `i32`
15+
|
16+
LL | v.push(1i32);
17+
| ~~~
1418

1519
error: aborting due to previous error
1620

0 commit comments

Comments
 (0)
Please sign in to comment.