Skip to content

Incorrect error position in compiler error message for E0277 #67135

Closed
@igozali

Description

@igozali

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:

   1fn foo(xs: Vec<String>) {}
   2fn main() {
   3let xs: Vec<String> = "a,b,c".split(",").collect();
   4foo(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:

   1fn foo(xs: Vec<String>) {}
   2fn main() {
   3let 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions