]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/early_otherwise_branch.rs
Rollup merge of #99084 - RalfJung:write_bytes, r=thomcc
[rust.git] / src / test / mir-opt / early_otherwise_branch.rs
1 // unit-test: EarlyOtherwiseBranch
2 // EMIT_MIR early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff
3 fn opt1(x: Option<u32>, y: Option<u32>) -> u32 {
4     match (x, y) {
5         (Some(a), Some(b)) => 0,
6         _ => 1,
7     }
8 }
9
10 // EMIT_MIR early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff
11 fn opt2(x: Option<u32>, y: Option<u32>) -> u32 {
12     match (x, y) {
13         (Some(a), Some(b)) => 0,
14         (None, None) => 0,
15         _ => 1,
16     }
17 }
18
19 // optimize despite different types
20 // EMIT_MIR early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
21 fn opt3(x: Option<u32>, y: Option<bool>) -> u32 {
22     match (x, y) {
23         (Some(a), Some(b)) => 0,
24         _ => 1,
25     }
26 }
27
28 fn main() {
29     opt1(None, Some(0));
30     opt2(None, Some(0));
31     opt3(None, Some(false));
32 }