-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
jieyouxu, fmease, surechen and linyihai
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.