Skip to content

Commit a71df24

Browse files
committed
Add diff test for MatchBranchSimplification
1 parent 3002af6 commit a71df24

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
+ let mut _3: isize;
9+
10+
bb0: {
11+
_2 = discriminant((*_1));
12+
- switchInt(move _2) -> [1: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- _0 = const false;
17+
- goto -> bb3;
18+
- }
19+
-
20+
- bb2: {
21+
- _0 = const true;
22+
- goto -> bb3;
23+
- }
24+
-
25+
- bb3: {
26+
+ StorageLive(_3);
27+
+ _3 = move _2;
28+
+ _0 = Eq(copy _3, const 1_isize);
29+
+ StorageDead(_3);
30+
return;
31+
}
32+
}
33+

tests/mir-opt/matches_reduce_branches.rs

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

22+
// EMIT_MIR matches_reduce_branches.my_is_some.MatchBranchSimplification.diff
23+
fn my_is_some<T>(bar: &Option<T>) -> bool {
24+
matches!(bar, Some(_))
25+
}
26+
2227
// EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
2328
fn bar(i: i32) -> (bool, bool, bool, bool) {
2429
// CHECK-LABEL: fn bar(
@@ -651,4 +656,7 @@ fn main() {
651656
let _: u8 = match_trunc_u16_u8_failed(EnumAu16::u0_0x0000);
652657

653658
let _ = match_i128_u128(EnumAi128::A);
659+
660+
let _ = my_is_some::<()>(&None);
661+
let _ = my_is_some(&Some(()));
654662
}

0 commit comments

Comments
 (0)