Skip to content

Commit 11f7e30

Browse files
committed
Add diff test for MatchBranchSimplification
1 parent 19e75f4 commit 11f7e30

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- // MIR for `my_is_some` before MatchBranchSimplification
2+
+ // MIR for `my_is_some` after MatchBranchSimplification
3+
4+
fn my_is_some(_1: Option<()>) -> bool {
5+
debug bar => _1;
6+
let mut _0: bool;
7+
let mut _2: isize;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const false;
20+
goto -> bb4;
21+
}
22+
23+
bb3: {
24+
_0 = const true;
25+
goto -> bb4;
26+
}
27+
28+
bb4: {
29+
return;
30+
}
31+
}
32+

tests/mir-opt/matches_reduce_branches.rs

+14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ fn foo(bar: Option<()>) {
1919
}
2020
}
2121

22+
// EMIT_MIR matches_reduce_branches.my_is_some.MatchBranchSimplification.diff
23+
// Test for #131219.
24+
fn my_is_some(bar: Option<()>) -> bool {
25+
// CHECK-LABEL: fn my_is_some(
26+
// CHECK: switchInt
27+
// CHECK: return
28+
match bar {
29+
Some(_) => true,
30+
None => false,
31+
}
32+
}
33+
2234
// EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
2335
fn bar(i: i32) -> (bool, bool, bool, bool) {
2436
// CHECK-LABEL: fn bar(
@@ -651,4 +663,6 @@ fn main() {
651663
let _: u8 = match_trunc_u16_u8_failed(EnumAu16::u0_0x0000);
652664

653665
let _ = match_i128_u128(EnumAi128::A);
666+
667+
let _ = my_is_some(None);
654668
}

0 commit comments

Comments
 (0)