Skip to content

Commit 64bebff

Browse files
authored
Rollup merge of rust-lang#127028 - Nadrieril:fix-or-pat-expansion, r=matthewjasper
Fix regression in the MIR lowering of or-patterns In rust-lang#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 🙏
2 parents a2d5819 + 834f043 commit 64bebff

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

compiler/rustc_mir_build/src/build/matches/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14681468
break;
14691469
}
14701470
}
1471+
if expand_until != 0 {
1472+
expand_until = i + 1;
1473+
}
14711474
}
14721475
let (candidates_to_expand, remaining_candidates) = candidates.split_at_mut(expand_until);
14731476

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// MIR for `match_enum` after built
2+
3+
fn match_enum(_1: E1) -> bool {
4+
debug x => _1;
5+
let mut _0: bool;
6+
let mut _2: isize;
7+
8+
bb0: {
9+
PlaceMention(_1);
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb3, 1: bb5, 2: bb7, otherwise: bb2];
12+
}
13+
14+
bb1: {
15+
FakeRead(ForMatchedPlace(None), _1);
16+
unreachable;
17+
}
18+
19+
bb2: {
20+
goto -> bb1;
21+
}
22+
23+
bb3: {
24+
goto -> bb9;
25+
}
26+
27+
bb4: {
28+
goto -> bb2;
29+
}
30+
31+
bb5: {
32+
goto -> bb9;
33+
}
34+
35+
bb6: {
36+
goto -> bb2;
37+
}
38+
39+
bb7: {
40+
_0 = const false;
41+
goto -> bb11;
42+
}
43+
44+
bb8: {
45+
goto -> bb2;
46+
}
47+
48+
bb9: {
49+
falseEdge -> [real: bb10, imaginary: bb7];
50+
}
51+
52+
bb10: {
53+
_0 = const true;
54+
goto -> bb11;
55+
}
56+
57+
bb11: {
58+
return;
59+
}
60+
}

tests/mir-opt/building/match/simple_match.rs

+14
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,18 @@ fn match_bool(x: bool) -> usize {
99
}
1010
}
1111

12+
pub enum E1 {
13+
V1,
14+
V2,
15+
V3,
16+
}
17+
18+
// EMIT_MIR simple_match.match_enum.built.after.mir
19+
pub fn match_enum(x: E1) -> bool {
20+
match x {
21+
E1::V1 | E1::V2 => true,
22+
E1::V3 => false,
23+
}
24+
}
25+
1226
fn main() {}

0 commit comments

Comments
 (0)