mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Deduplicate Spans in Uninitialized Check
Prevents reporting labels or diagnostics on spans that are produced multiple times.
This commit is contained in:
parent
4d5b3b1962
commit
e91f32829c
@ -678,14 +678,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
|||||||
let inits = &self.move_data.init_path_map[mpi];
|
let inits = &self.move_data.init_path_map[mpi];
|
||||||
let move_path = &self.move_data.move_paths[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 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 {
|
for init_idx in inits {
|
||||||
let init = &self.move_data.inits[*init_idx];
|
let init = &self.move_data.inits[*init_idx];
|
||||||
let span = init.span(self.body);
|
let span = init.span(self.body);
|
||||||
if !span.is_dummy() {
|
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(
|
let (name, desc) = match self.describe_place_with_options(
|
||||||
moved_place,
|
moved_place,
|
||||||
|
13
tests/ui/duplicate-label-E0381-issue-129274.rs
Normal file
13
tests/ui/duplicate-label-E0381-issue-129274.rs
Normal file
@ -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
tests/ui/duplicate-label-E0381-issue-129274.stderr
Normal file
15
tests/ui/duplicate-label-E0381-issue-129274.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user