about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-08-27 00:42:00 +0200
committerGitHub <noreply@github.com>2024-08-27 00:42:00 +0200
commit53f5294c0fe409cb83a6b993d495b6881729648b (patch)
tree5dad6d0e9d92ffe6f60ae08e5f3bfe0b335301ff
parentd4d4b6b4fa76f67d2577f4f659891ce263d91bd5 (diff)
parente91f32829ccfb60e13fcb07dab4947c382a376c9 (diff)
downloadrust-53f5294c0fe409cb83a6b993d495b6881729648b.tar.gz
rust-53f5294c0fe409cb83a6b993d495b6881729648b.zip
Rollup merge of #129340 - stephen-lazaro:u/slazaro/issue-129274, r=compiler-errors
Remove Duplicate E0381 Label

Aims to resolve https://github.com/rust-lang/rust/issues/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.
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs5
-rw-r--r--tests/ui/duplicate-label-E0381-issue-129274.rs13
-rw-r--r--tests/ui/duplicate-label-E0381-issue-129274.stderr15
3 files changed, 31 insertions, 2 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index cd35427b914..aaeedde2bed 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -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,
diff --git a/tests/ui/duplicate-label-E0381-issue-129274.rs b/tests/ui/duplicate-label-E0381-issue-129274.rs
new file mode 100644
index 00000000000..b2156e630c8
--- /dev/null
+++ b/tests/ui/duplicate-label-E0381-issue-129274.rs
@@ -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())
+}
diff --git a/tests/ui/duplicate-label-E0381-issue-129274.stderr b/tests/ui/duplicate-label-E0381-issue-129274.stderr
new file mode 100644
index 00000000000..7f8bddb17c5
--- /dev/null
+++ b/tests/ui/duplicate-label-E0381-issue-129274.stderr
@@ -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`.