Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect error position in compiler error message for E0277 #67135

Closed
igozali opened this issue Dec 8, 2019 · 1 comment
Closed

Incorrect error position in compiler error message for E0277 #67135

igozali opened this issue Dec 8, 2019 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@igozali
Copy link

igozali commented Dec 8, 2019

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
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 8, 2019
@VirrageS
Copy link
Contributor

I think this is already fixed in 1.42.0-nightly: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=fd69e5c39cc9d3c6ed4f9feb5028dd32
with #67354

@estebank estebank closed this as completed Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants