about summary refs log tree commit diff
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
parent7cd950546b4ce68843b4cbdb1ab3a43776202d3a (diff)
downloadrust-9916ce362f712b7aa91cd7576a5dcfc575ffd621.tar.gz
rust-9916ce362f712b7aa91cd7576a5dcfc575ffd621.zip
fix `#[loop_match]` on diverging loop
this generated invalid MIR before
-rw-r--r--compiler/rustc_mir_build/src/builder/expr/into.rs2
-rw-r--r--tests/ui/loop-match/diverges.rs44
2 files changed, 45 insertions, 1 deletions
diff --git a/compiler/rustc_mir_build/src/builder/expr/into.rs b/compiler/rustc_mir_build/src/builder/expr/into.rs
index 82b883a99a1..ac87f671699 100644
--- a/compiler/rustc_mir_build/src/builder/expr/into.rs
+++ b/compiler/rustc_mir_build/src/builder/expr/into.rs
@@ -345,7 +345,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                                         expr_span,
                                         |this| {
                                             this.lower_match_arms(
-                                                destination,
+                                                state_place,
                                                 scrutinee_place_builder,
                                                 scrutinee_span,
                                                 arms,
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,
+            }
+        }
+    }
+}