Closed
Description
Given the following code:
fn bar(_: Vec<i32>) {}
fn main() {
let v: Vec<i32> = vec![1, 2, 3, 4, 5];
let mut foo = vec![];
for i in &v {
foo.push(i);
}
bar(foo);
}
The current output is:
error[E0308]: mismatched types
--> src/main.rs:8:9
|
8 | bar(foo);
| --- ^^^ expected `i32`, found `&i32`
| |
| arguments to this function are incorrect
|
= note: expected struct `Vec<i32>`
found struct `Vec<&i32>`
note: function defined here
--> src/main.rs:1:4
|
1 | fn bar(_: Vec<i32>) {}
| ^^^ -----------
The error should point at line 6, where the type of foo
is resolved to be Vec<&i32>
, along the lines of
error[E0308]: mismatched types
--> src/main.rs:8:9
|
8 | bar(foo);
| --- ^^^ expected `i32`, found `&i32`
| |
| arguments to this function are incorrect
|
= note: expected struct `Vec<i32>`
found struct `Vec<&i32>`
note:
|
4 | let mut foo = vec![];
| --- `foo` is of type `Vec<_>` here
5 | for i in &v {
6 | foo.push(i);
| ^^^ - `i` is of type `&i32` here
| |
| `foo` is of type `Vec<&i32>` here
|
note: function defined here
--> src/main.rs:1:4
|
1 | fn bar(_: Vec<i32>) {}
| ^^^ -----------