Skip to content

Commit 53f5294

Browse files
authored
Rollup merge of #129340 - stephen-lazaro:u/slazaro/issue-129274, r=compiler-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.
2 parents d4d4b6b + e91f328 commit 53f5294

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
678678
let inits = &self.move_data.init_path_map[mpi];
679679
let move_path = &self.move_data.move_paths[mpi];
680680
let decl_span = self.body.local_decls[move_path.place.local].source_info.span;
681-
let mut spans = vec![];
681+
let mut spans_set = FxIndexSet::default();
682682
for init_idx in inits {
683683
let init = &self.move_data.inits[*init_idx];
684684
let span = init.span(self.body);
685685
if !span.is_dummy() {
686-
spans.push(span);
686+
spans_set.insert(span);
687687
}
688688
}
689+
let spans: Vec<_> = spans_set.into_iter().collect();
689690

690691
let (name, desc) = match self.describe_place_with_options(
691692
moved_place,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main() {
2+
fn test() {
3+
loop {
4+
let blah: Option<String>;
5+
if true {
6+
blah = Some("".to_string());
7+
}
8+
if let Some(blah) = blah.as_ref() { //~ ERROR E0381
9+
}
10+
}
11+
}
12+
println!("{:?}", test())
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0381]: used binding `blah` is possibly-uninitialized
2+
--> $DIR/duplicate-label-E0381-issue-129274.rs:8:33
3+
|
4+
LL | let blah: Option<String>;
5+
| ---- binding declared here but left uninitialized
6+
LL | if true {
7+
LL | blah = Some("".to_string());
8+
| ---- binding initialized here in some conditions
9+
LL | }
10+
LL | if let Some(blah) = blah.as_ref() {
11+
| ^^^^ `blah` used here but it is possibly-uninitialized
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0381`.

0 commit comments

Comments
 (0)