Closed
Description
Summary
Compiler seems to point to an incorrect line number/column number when describing the error.
Actual
When I try to compile the following short code:
1 │ fn foo(xs: Vec<String>) {}
2 │ fn main() {
3 │ let xs: Vec<String> = "a,b,c".split(",").collect();
4 │ foo(xs);
5 │ }
I get the following error message:
error[E0277]: a value of type `std::vec::Vec<std::string::String>` cannot be built from an iterator over elements of type `&str`
--> main.rs:4:9
|
4 | foo(xs);
| ^^ value of type `std::vec::Vec<std::string::String>` cannot be built from `std::iter::Iterator<Item=&str>`
|
= help: the trait `std::iter::FromIterator<&str>` is not implemented for `std::vec::Vec<std::string::String>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
Expected
I expected the compiler to error out on line 3, since I've declared the type of xs
to be Vec<String>
. I can get the expected behavior by commenting out line 4:
1 │ fn foo(xs: Vec<String>) {}
2 │ fn main() {
3 │ let xs: Vec<String> = "a,b,c".split(",").collect();
4 │ //foo(xs);
5 │ }
Which gives me:
error[E0277]: a value of type `std::vec::Vec<std::string::String>` cannot be built from an iterator over elements of type `&str`
--> main.rs:3:46
|
3 | let xs: Vec<String> = "a,b,c".split(",").collect();
| ^^^^^^^ value of type `std::vec::Vec<std::string::String>` cannot be built from `std::iter::Iterator<Item=&str>`
|
= help: the trait `std::iter::FromIterator<&str>` is not implemented for `std::vec::Vec<std::string::String>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
Meta
$ rustup run nightly rustc -V --verbose
rustc 1.41.0-nightly (ae1b871cc 2019-12-06)
binary: rustc
commit-hash: ae1b871cca56613b1af1a5121dd24ac810ff4b89
commit-date: 2019-12-06
host: x86_64-apple-darwin
release: 1.41.0-nightly
LLVM version: 9.0