Skip to content

Commit e91f328

Browse files
Deduplicate Spans in Uninitialized Check
Prevents reporting labels or diagnostics on spans that are produced multiple times.
1 parent 4d5b3b1 commit e91f328

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)