2023-10-16 12:36:39 -05:00
|
|
|
// skip-filecheck
|
2022-04-13 04:20:46 -05:00
|
|
|
// unit-test: EarlyOtherwiseBranch
|
2020-08-01 18:47:52 -05:00
|
|
|
// EMIT_MIR early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff
|
2020-09-19 16:38:54 -05:00
|
|
|
fn opt1(x: Option<u32>, y: Option<u32>) -> u32 {
|
|
|
|
match (x, y) {
|
2020-08-01 18:47:52 -05:00
|
|
|
(Some(a), Some(b)) => 0,
|
2020-09-19 16:38:54 -05:00
|
|
|
_ => 1,
|
2020-08-01 18:47:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff
|
2020-09-19 16:38:54 -05:00
|
|
|
fn opt2(x: Option<u32>, y: Option<u32>) -> u32 {
|
|
|
|
match (x, y) {
|
2020-08-01 18:47:52 -05:00
|
|
|
(Some(a), Some(b)) => 0,
|
|
|
|
(None, None) => 0,
|
2020-09-19 16:38:54 -05:00
|
|
|
_ => 1,
|
2020-08-01 18:47:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:53:15 -06:00
|
|
|
// optimize despite different types
|
|
|
|
// EMIT_MIR early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
|
|
|
|
fn opt3(x: Option<u32>, y: Option<bool>) -> u32 {
|
|
|
|
match (x, y) {
|
|
|
|
(Some(a), Some(b)) => 0,
|
|
|
|
_ => 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-01 18:47:52 -05:00
|
|
|
fn main() {
|
|
|
|
opt1(None, Some(0));
|
|
|
|
opt2(None, Some(0));
|
2021-12-12 15:53:15 -06:00
|
|
|
opt3(None, Some(false));
|
2020-08-01 18:47:52 -05:00
|
|
|
}
|