-
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-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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 blah() {
loop {
let blah: Option<String>;
if true {
blah = Some("".to_string());
}
if let Some(blah) = blah.as_ref() {
// ...
}
}
}
Current output
error[E0381]: used binding `blah` is possibly-uninitialized
--> src/lib.rs:8:29
|
3 | let blah: Option<String>;
| ---- binding declared here but left uninitialized
4 | if true {
5 | blah = Some("".to_string());
| ----
| |
| binding initialized here in some conditions
| binding initialized here in some conditions
...
8 | if let Some(blah) = blah.as_ref() {
| ^^^^ `blah` used here but it is possibly-uninitialized
Desired output
error[E0381]: used binding `blah` is possibly-uninitialized
--> src/lib.rs:8:29
|
3 | let blah: Option<String>;
| ---- binding declared here but left uninitialized
4 | if true {
5 | blah = Some("".to_string());
| ---- binding initialized here in some conditions
...
8 | if let Some(blah) = blah.as_ref() {
| ^^^^ `blah` used here but it is possibly-uninitialized
Rationale and extra context
The duplicated labels are unnecessary given that they point at the exact same place, as far as the code the user wrote is concerned.
Other cases
Noticed when looking at #57553 (comment)
Rust Version
At least from 1.80 to current 1.82.
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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.