Open
Description
openedon Apr 6, 2024
Code
fn main() {
let x = Some(3);
let y = vec![1, 2];
if let Some(y) = x {
y.push(y);
}
}
Current output
error[E0599]: no method named `push` found for type `{integer}` in the current scope
--> src/main.rs:5:11
|
5 | y.push(y);
| ^^^^ method not found in `{integer}`
Desired output
error[E0599]: no method named `push` found for type `{integer}` in the current scope
--> src/main.rs:5:11
|
5 | y.push(y);
| ^^^^ method not found in `{integer}`
note: there's an earlier shadowed binding `y` of type `Vec<{integer}>` that *has* method `push` available
|
3 | let y = vec![1, 2];
| ^ `y` of type `Vec<{integer}>` that has method `push` defined earlier here
4 | if let Some(y) = x {
| ^ earlier `y` shadowed here with type `{integer}`
Rationale and extra context
Shadowed bindings can sometimes confuse the user as to why they don't have the expected type. Pointing out shadowed bindings in type and trait errors can help avoid that.
Other cases
E0308 would present similar situations.
Rust Version
rustc 1.78.0-nightly (3b1717c05 2024-03-10)
Anything else?
No response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.Relevant to the compiler team, which will review and decide on the PR/issue.