Skip to content
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

Duplicated label on E0381 #129274

Closed
estebank opened this issue Aug 19, 2024 · 1 comment · Fixed by #129340
Closed

Duplicated label on E0381 #129274

estebank opened this issue Aug 19, 2024 · 1 comment · Fixed by #129340
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Aug 19, 2024

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

@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Aug 19, 2024
@stephen-lazaro
Copy link
Contributor

@rustbot claim

@bors bors closed this as completed in 53f5294 Aug 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 27, 2024
Rollup merge of rust-lang#129340 - stephen-lazaro:u/slazaro/issue-129274, r=compiler-errors

Remove Duplicate E0381 Label

Aims to resolve rust-lang#129274, and adds a test for the case.

Essentially, we are duplicating this span for some reason. For now, I'm just using a set to collect the spans rather than the vec. I imagine there's probably no real reason to inspect duplicates in this area, but if I'm wrong I can adjust to collect "seen spans" in just the point where this label is applied.

I'm not sure why it's producing duplicate spans. Looks like this has been this way for a while? I think it gives the duplicate label on 1.75.0 for example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants