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 compiler error message on mismatched types #43420

Closed
isaacg1 opened this issue Jul 23, 2017 · 0 comments
Closed

Incorrect compiler error message on mismatched types #43420

isaacg1 opened this issue Jul 23, 2017 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@isaacg1
Copy link

isaacg1 commented Jul 23, 2017

I ran cargo build with some code that did not compile due to a type mismatch, error E0308. Help text was displayed, which was false/very misleading.

Here's a reduced test case:

fn foo(b: &[u16]) {}

fn main() {
    let a: Vec<u8> = Vec::new();
    foo(&a);
}

After running cargo build, the error displayed was:

   Compiling test-compile v0.1.0 (file:///home/isaac/prog/rust/test-compile)
error[E0308]: mismatched types
 --> src/main.rs:5:9
  |
5 |     foo(&a);
  |         ^^ expected slice, found struct `std::vec::Vec`
  |
  = note: expected type `&[u16]`
             found type `&std::vec::Vec<u8>`
  = help: here are some functions which might fulfill your needs:
          - .as_slice()

error: aborting due to previous error(s)

error: Could not compile `test-compile`.

Focusing in on the line: expected slice, found struct std::vec::Vec

This is incorrect, because std::vec::Vec dereferences into slice. The actual type mismatch, which should have been displayed, is between u16 and u8. I would expect the error to say:

expected u16, found u8

Meta:

I discovered this on nightly, but reproduced it on stable.

rustc --version --verbose:

rustc 1.19.0 (0ade339 2017-07-17)
binary: rustc
commit-hash: 0ade339
commit-date: 2017-07-17
host: x86_64-unknown-linux-gnu
release: 1.19.0
LLVM version: 4.0

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 26, 2017
@bors bors closed this as completed in de0e695 Aug 30, 2017
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-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

2 participants