about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-07-07 19:55:35 +0200
committerGitHub <noreply@github.com>2025-07-07 19:55:35 +0200
commitf5df1f562c5261415a7dd5c0fec9230440b2a09f (patch)
tree7064e210fcc9f95b8da7f8b04bd3783d78d421a5
parent7ed6bd98a248b62b3c490fb813bf4c29d9d57ae4 (diff)
parent6d58a88c3ca2eefc24654700db522bfed668e1cb (diff)
downloadrust-f5df1f562c5261415a7dd5c0fec9230440b2a09f.tar.gz
rust-f5df1f562c5261415a7dd5c0fec9230440b2a09f.zip
Rollup merge of #143583 - folkertdev:loop-match-no-terminator-on-block, r=bjorn3
`loop_match`: fix 'no terminator on block'

tracking issue: https://github.com/rust-lang/rust/issues/132306
fixes https://github.com/rust-lang/rust/issues/143435

The argument `block` was not properly closed on an error path.

r? `@bjorn3`
-rw-r--r--compiler/rustc_mir_build/src/builder/scope.rs4
-rw-r--r--tests/ui/loop-match/panic-in-const.rs22
-rw-r--r--tests/ui/loop-match/panic-in-const.stderr9
3 files changed, 34 insertions, 1 deletions
diff --git a/compiler/rustc_mir_build/src/builder/scope.rs b/compiler/rustc_mir_build/src/builder/scope.rs
index 405d47c7c79..5a5456aedc2 100644
--- a/compiler/rustc_mir_build/src/builder/scope.rs
+++ b/compiler/rustc_mir_build/src/builder/scope.rs
@@ -936,7 +936,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
 
                 valtree
             }
-            Err(ErrorHandled::Reported(..)) => return self.cfg.start_new_block().unit(),
+            Err(ErrorHandled::Reported(..)) => {
+                return block.unit();
+            }
             Err(ErrorHandled::TooGeneric(_)) => {
                 self.tcx.dcx().emit_fatal(ConstContinueBadConst { span: constant.span });
             }
diff --git a/tests/ui/loop-match/panic-in-const.rs b/tests/ui/loop-match/panic-in-const.rs
new file mode 100644
index 00000000000..2ae67445496
--- /dev/null
+++ b/tests/ui/loop-match/panic-in-const.rs
@@ -0,0 +1,22 @@
+#![allow(incomplete_features)]
+#![feature(loop_match)]
+#![crate_type = "lib"]
+
+const CONST_THAT_PANICS: u8 = panic!("diverge!");
+//~^ ERROR: evaluation panicked: diverge!
+
+fn test(mut state: u8) {
+    #[loop_match]
+    loop {
+        state = 'blk: {
+            match state {
+                0 => {
+                    #[const_continue]
+                    break 'blk CONST_THAT_PANICS;
+                }
+
+                _ => unreachable!(),
+            }
+        }
+    }
+}
diff --git a/tests/ui/loop-match/panic-in-const.stderr b/tests/ui/loop-match/panic-in-const.stderr
new file mode 100644
index 00000000000..b6ed3177883
--- /dev/null
+++ b/tests/ui/loop-match/panic-in-const.stderr
@@ -0,0 +1,9 @@
+error[E0080]: evaluation panicked: diverge!
+  --> $DIR/panic-in-const.rs:5:31
+   |
+LL | const CONST_THAT_PANICS: u8 = panic!("diverge!");
+   |                               ^^^^^^^^^^^^^^^^^^ evaluation of `CONST_THAT_PANICS` failed here
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0080`.