2022-04-13 09:20:46 +00:00
|
|
|
// unit-test: EarlyOtherwiseBranch
|
2020-08-01 23:47:52 +00:00
|
|
|
// EMIT_MIR early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff
|
2020-09-19 21:38:54 +00:00
|
|
|
fn opt1(x: Option<u32>, y: Option<u32>) -> u32 {
|
|
|
|
match (x, y) {
|
2020-08-01 23:47:52 +00:00
|
|
|
(Some(a), Some(b)) => 0,
|
2020-09-19 21:38:54 +00:00
|
|
|
_ => 1,
|
2020-08-01 23:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff
|
2020-09-19 21:38:54 +00:00
|
|
|
fn opt2(x: Option<u32>, y: Option<u32>) -> u32 {
|
|
|
|
match (x, y) {
|
2020-08-01 23:47:52 +00:00
|
|
|
(Some(a), Some(b)) => 0,
|
|
|
|
(None, None) => 0,
|
2020-09-19 21:38:54 +00:00
|
|
|
_ => 1,
|
2020-08-01 23:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-12 21:53:15 +00: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 23:47:52 +00:00
|
|
|
fn main() {
|
|
|
|
opt1(None, Some(0));
|
|
|
|
opt2(None, Some(0));
|
2021-12-12 21:53:15 +00:00
|
|
|
opt3(None, Some(false));
|
2020-08-01 23:47:52 +00:00
|
|
|
}
|