Skip to content

Commit 8c745db

Browse files
committed
Add diff test for MatchBranchSimplification
1 parent 9fa0146 commit 8c745db

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
- // MIR for `my_is_some` before MatchBranchSimplification
2+
+ // MIR for `my_is_some` after MatchBranchSimplification
3+
4+
fn my_is_some(_1: Option<T>) -> 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+
drop(_1) -> [return: bb5, unwind unreachable];
30+
}
31+
32+
bb5: {
33+
return;
34+
}
35+
}
36+

tests/mir-opt/matches_reduce_branches.rs

Lines changed: 15 additions & 0 deletions
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<T>(bar: Option<T>) -> 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,7 @@ 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);
668+
let _ = my_is_some(Some(()));
654669
}

0 commit comments

Comments
 (0)