about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2025-06-15 18:48:03 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2025-06-15 21:12:17 +0000
commit89b079d844454d0288fbce1160dab129987a4921 (patch)
treea56c741d5b76c90b00f4a481971b00a215a15152
parent75e7cf5f85aad82331a38deff24845b63eaf30f3 (diff)
downloadrust-89b079d844454d0288fbce1160dab129987a4921.tar.gz
rust-89b079d844454d0288fbce1160dab129987a4921.zip
Only traverse reachable blocks in JumpThreading.
-rw-r--r--compiler/rustc_mir_transform/src/jump_threading.rs2
-rw-r--r--tests/ui/mir/unreachable-loop-jump-threading.rs (renamed from tests/crashes/131451.rs)3
-rw-r--r--tests/ui/mir/unreachable-loop-jump-threading.stderr10
3 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs
index 48db536c122..b45bff2af44 100644
--- a/compiler/rustc_mir_transform/src/jump_threading.rs
+++ b/compiler/rustc_mir_transform/src/jump_threading.rs
@@ -89,7 +89,7 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading {
             opportunities: Vec::new(),
         };
 
-        for bb in body.basic_blocks.indices() {
+        for (bb, _) in traversal::preorder(body) {
             finder.start_from_switch(bb);
         }
 
diff --git a/tests/crashes/131451.rs b/tests/ui/mir/unreachable-loop-jump-threading.rs
index cd5b44bad8a..8403906bb5c 100644
--- a/tests/crashes/131451.rs
+++ b/tests/ui/mir/unreachable-loop-jump-threading.rs
@@ -1,9 +1,10 @@
-//@ known-bug: #131451
+//@ build-pass
 //@ needs-rustc-debug-assertions
 //@ compile-flags: -Zmir-enable-passes=+GVN -Zmir-enable-passes=+JumpThreading --crate-type=lib
 
 pub fn fun(terminate: bool) {
     while true {}
+    //~^ WARN denote infinite loops with `loop { ... }`
 
     while !terminate {}
 }
diff --git a/tests/ui/mir/unreachable-loop-jump-threading.stderr b/tests/ui/mir/unreachable-loop-jump-threading.stderr
new file mode 100644
index 00000000000..21b174c8021
--- /dev/null
+++ b/tests/ui/mir/unreachable-loop-jump-threading.stderr
@@ -0,0 +1,10 @@
+warning: denote infinite loops with `loop { ... }`
+  --> $DIR/unreachable-loop-jump-threading.rs:6:5
+   |
+LL |     while true {}
+   |     ^^^^^^^^^^ help: use `loop`
+   |
+   = note: `#[warn(while_true)]` on by default
+
+warning: 1 warning emitted
+