You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect compiler error message on mismatched types #43420
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.
Activity
Check the substituted return type in return type suggestions.