about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2025-08-01 15:31:16 +0200
committerFolkert de Vries <folkert@folkertdev.nl>2025-08-04 19:23:10 +0200
commit9916ce362f712b7aa91cd7576a5dcfc575ffd621 (patch)
treefa529fefb31311b16f4a87664ac4613095741a06 /tests
parent7cd950546b4ce68843b4cbdb1ab3a43776202d3a (diff)
downloadrust-9916ce362f712b7aa91cd7576a5dcfc575ffd621.tar.gz
rust-9916ce362f712b7aa91cd7576a5dcfc575ffd621.zip
fix `#[loop_match]` on diverging loop
this generated invalid MIR before
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/loop-match/diverges.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/ui/loop-match/diverges.rs b/tests/ui/loop-match/diverges.rs
new file mode 100644
index 00000000000..f1b3ffb2076
--- /dev/null
+++ b/tests/ui/loop-match/diverges.rs
@@ -0,0 +1,44 @@
+//@ build-pass
+//@ compile-flags: -Zvalidate-mir
+#![allow(incomplete_features)]
+#![feature(loop_match)]
+#![crate_type = "lib"]
+
+// Test that a #[loop_match] without an explicit break from the loop generates valid MIR.
+
+fn break_to_block_unit() -> u8 {
+    let mut state = 0;
+    #[loop_match]
+    loop {
+        state = 'blk: {
+            match state {
+                _ => 'b: {
+                    break 'b 2;
+                }
+            }
+        }
+    }
+}
+
+fn break_to_block_value() -> u8 {
+    let mut state = 0u8;
+    #[loop_match]
+    'a: loop {
+        state = 'blk: {
+            match state {
+                _ => break 'blk state,
+            }
+        }
+    }
+}
+
+fn infinite_a(mut state: u8) {
+    #[loop_match]
+    loop {
+        state = 'blk: {
+            match state {
+                a => a,
+            }
+        }
+    }
+}