about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-07-09 16:33:59 +0000
committerbors <bors@rust-lang.org>2024-07-09 16:33:59 +0000
commit9dcaa7f92cf3ed0a9d2e93824025243533bb5541 (patch)
tree10c69badb2df8b5e69dad22bc14dead060a068d9
parentf25e92bd42b14e45440c0a30a4ed751ea502f430 (diff)
parent834f043a0878dda17118129e4ac8930d4d00fc6f (diff)
downloadrust-9dcaa7f92cf3ed0a9d2e93824025243533bb5541.tar.gz
rust-9dcaa7f92cf3ed0a9d2e93824025243533bb5541.zip
Auto merge of #127028 - Nadrieril:fix-or-pat-expansion, r=matthewjasper
Fix regression in the MIR lowering of or-patterns

In https://github.com/rust-lang/rust/pull/126553 I made a silly indexing mistake and regressed the MIR lowering of or-patterns. This fixes it.

r? `@compiler-errors` because I'd like this to be merged quickly :pray:
-rw-r--r--compiler/rustc_mir_build/src/build/matches/mod.rs3
-rw-r--r--tests/mir-opt/building/match/simple_match.match_enum.built.after.mir60
-rw-r--r--tests/mir-opt/building/match/simple_match.rs14
3 files changed, 77 insertions, 0 deletions
diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs
index e435e2f9288..5695c881ecc 100644
--- a/compiler/rustc_mir_build/src/build/matches/mod.rs
+++ b/compiler/rustc_mir_build/src/build/matches/mod.rs
@@ -1468,6 +1468,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     break;
                 }
             }
+            if expand_until != 0 {
+                expand_until = i + 1;
+            }
         }
         let (candidates_to_expand, remaining_candidates) = candidates.split_at_mut(expand_until);
 
diff --git a/tests/mir-opt/building/match/simple_match.match_enum.built.after.mir b/tests/mir-opt/building/match/simple_match.match_enum.built.after.mir
new file mode 100644
index 00000000000..905aa19da70
--- /dev/null
+++ b/tests/mir-opt/building/match/simple_match.match_enum.built.after.mir
@@ -0,0 +1,60 @@
+// MIR for `match_enum` after built
+
+fn match_enum(_1: E1) -> bool {
+    debug x => _1;
+    let mut _0: bool;
+    let mut _2: isize;
+
+    bb0: {
+        PlaceMention(_1);
+        _2 = discriminant(_1);
+        switchInt(move _2) -> [0: bb3, 1: bb5, 2: bb7, otherwise: bb2];
+    }
+
+    bb1: {
+        FakeRead(ForMatchedPlace(None), _1);
+        unreachable;
+    }
+
+    bb2: {
+        goto -> bb1;
+    }
+
+    bb3: {
+        goto -> bb9;
+    }
+
+    bb4: {
+        goto -> bb2;
+    }
+
+    bb5: {
+        goto -> bb9;
+    }
+
+    bb6: {
+        goto -> bb2;
+    }
+
+    bb7: {
+        _0 = const false;
+        goto -> bb11;
+    }
+
+    bb8: {
+        goto -> bb2;
+    }
+
+    bb9: {
+        falseEdge -> [real: bb10, imaginary: bb7];
+    }
+
+    bb10: {
+        _0 = const true;
+        goto -> bb11;
+    }
+
+    bb11: {
+        return;
+    }
+}
diff --git a/tests/mir-opt/building/match/simple_match.rs b/tests/mir-opt/building/match/simple_match.rs
index 61c337822c8..c8b3d90748a 100644
--- a/tests/mir-opt/building/match/simple_match.rs
+++ b/tests/mir-opt/building/match/simple_match.rs
@@ -9,4 +9,18 @@ fn match_bool(x: bool) -> usize {
     }
 }
 
+pub enum E1 {
+    V1,
+    V2,
+    V3,
+}
+
+// EMIT_MIR simple_match.match_enum.built.after.mir
+pub fn match_enum(x: E1) -> bool {
+    match x {
+        E1::V1 | E1::V2 => true,
+        E1::V3 => false,
+    }
+}
+
 fn main() {}