about summary refs log tree commit diff
path: root/tests/ui/error-codes
diff options
context:
space:
mode:
authorSpencer <spencer3035@gmail.com>2025-03-13 18:07:37 -0600
committerSpencer <spencer3035@gmail.com>2025-03-15 10:52:07 -0600
commit62075593a8077ef7fb123ab6f36522b526b93e47 (patch)
tree5b3b9167dc4f86150a6346bcc303556dba362023 /tests/ui/error-codes
parent9f06585c0e93f835c9e0ceb199d71b8f5679d9d1 (diff)
downloadrust-62075593a8077ef7fb123ab6f36522b526b93e47.tar.gz
rust-62075593a8077ef7fb123ab6f36522b526b93e47.zip
improves duplicate label test
Diffstat (limited to 'tests/ui/error-codes')
-rw-r--r--tests/ui/error-codes/E0381-duplicated-label.rs16
-rw-r--r--tests/ui/error-codes/E0381-duplicated-label.stderr15
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/error-codes/E0381-duplicated-label.rs b/tests/ui/error-codes/E0381-duplicated-label.rs
new file mode 100644
index 00000000000..84a85caa65d
--- /dev/null
+++ b/tests/ui/error-codes/E0381-duplicated-label.rs
@@ -0,0 +1,16 @@
+//! Regression test for duplicated label in E0381 error message.
+//!
+//! Issue: <https://github.com/rust-lang/rust/issues/129274>
+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/error-codes/E0381-duplicated-label.stderr b/tests/ui/error-codes/E0381-duplicated-label.stderr
new file mode 100644
index 00000000000..36e6d966f09
--- /dev/null
+++ b/tests/ui/error-codes/E0381-duplicated-label.stderr
@@ -0,0 +1,15 @@
+error[E0381]: used binding `blah` is possibly-uninitialized
+  --> $DIR/E0381-duplicated-label.rs:11: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`.