-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Confusing error message due to type parameter name #35030
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
Comments
One solution would be to add detail after the expected/found lines if primitive shadowing has come into play. This would not change the language, but make the error look like:
|
estebank
added a commit
to estebank/rust
that referenced
this issue
Sep 16, 2016
When a type parameter shadows a primitive type, the error message was non obvious. For example, given the file `file.rs`: ```rust trait Parser<T> { fn parse(text: &str) -> Option<T>; } impl<bool> Parser<bool> for bool { fn parse(text: &str) -> Option<bool> { Some(true) } } fn main() { println!("{}", bool::parse("ok").unwrap_or(false)); } ``` The output was: ```bash % rustc file.rs error[E0308]: mismatched types --> file.rs:7:14 | 7 | Some(true) | ^^^^ expected type parameter, found bool | = note: expected type `bool` = note: found type `bool` error: aborting due to previous error ``` We now show extra information about the type: ```bash % rustc file.rs error[E0308]: mismatched types --> file.rs:7:14 | 7 | Some(true) | ^^^^ expected type parameter, found bool | = note: expected type `bool` (type parameter) = note: found type `bool` (bool) error: aborting due to previous error ``` Fixes rust-lang#35030
bors
added a commit
that referenced
this issue
Sep 16, 2016
Be more specific when type parameter shadows primitive type When a type parameter shadows a primitive type, the error message was non obvious. For example, given the file `file.rs`: ```rust trait Parser<T> { fn parse(text: &str) -> Option<T>; } impl<bool> Parser<bool> for bool { fn parse(text: &str) -> Option<bool> { Some(true) } } fn main() { println!("{}", bool::parse("ok").unwrap_or(false)); } ``` The output was: ```bash % rustc file.rs error[E0308]: mismatched types --> file.rs:7:14 | 7 | Some(true) | ^^^^ expected type parameter, found bool a | = note: expected type `bool` = note: found type `bool` error: aborting due to previous error ``` We now show extra information about the type: ```bash % rustc file.rs error[E0308]: mismatched types --> file.rs:7:14 | 7 | Some(true) | ^^^^ expected type parameter, found bool a | = note: expected type `bool` (type parameter) = note: found type `bool` (bool) error: aborting due to previous error ``` Fixes #35030
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is wrong, but the error message is confusing:
Because I used
bool
accidentally as a type name when not using the right syntax ... this is pretty confusing:The text was updated successfully, but these errors were encountered: