Skip to content

Commit

Permalink
Rollup merge of #129340 - stephen-lazaro:u/slazaro/issue-129274, r=co…
Browse files Browse the repository at this point in the history
…mpiler-errors

Remove Duplicate E0381 Label

Aims to resolve #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.
  • Loading branch information
matthiaskrgr authored Aug 26, 2024
2 parents d4d4b6b + e91f328 commit 53f5294
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
let inits = &self.move_data.init_path_map[mpi];
let move_path = &self.move_data.move_paths[mpi];
let decl_span = self.body.local_decls[move_path.place.local].source_info.span;
let mut spans = vec![];
let mut spans_set = FxIndexSet::default();
for init_idx in inits {
let init = &self.move_data.inits[*init_idx];
let span = init.span(self.body);
if !span.is_dummy() {
spans.push(span);
spans_set.insert(span);
}
}
let spans: Vec<_> = spans_set.into_iter().collect();

let (name, desc) = match self.describe_place_with_options(
moved_place,
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/duplicate-label-E0381-issue-129274.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
fn test() {
loop {
let blah: Option<String>;
if true {
blah = Some("".to_string());
}
if let Some(blah) = blah.as_ref() { //~ ERROR E0381
}
}
}
println!("{:?}", test())
}
15 changes: 15 additions & 0 deletions tests/ui/duplicate-label-E0381-issue-129274.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0381]: used binding `blah` is possibly-uninitialized
--> $DIR/duplicate-label-E0381-issue-129274.rs:8:33
|
LL | let blah: Option<String>;
| ---- binding declared here but left uninitialized
LL | if true {
LL | blah = Some("".to_string());
| ---- binding initialized here in some conditions
LL | }
LL | if let Some(blah) = blah.as_ref() {
| ^^^^ `blah` used here but it is possibly-uninitialized

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0381`.

0 comments on commit 53f5294

Please sign in to comment.