2022-08-20 23:47:53 -05:00
|
|
|
// unit-test: MatchBranchSimplification
|
|
|
|
|
2022-09-05 00:35:47 -05:00
|
|
|
|
2020-08-10 21:36:32 -05:00
|
|
|
// EMIT_MIR matches_reduce_branches.foo.MatchBranchSimplification.diff
|
2020-08-14 19:00:00 -05:00
|
|
|
// EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
|
2020-10-20 19:00:00 -05:00
|
|
|
// EMIT_MIR matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff
|
2020-08-10 18:11:05 -05:00
|
|
|
|
|
|
|
fn foo(bar: Option<()>) {
|
|
|
|
if matches!(bar, None) {
|
2020-10-03 04:18:24 -05:00
|
|
|
()
|
2020-08-10 18:11:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-14 19:00:00 -05:00
|
|
|
fn bar(i: i32) -> (bool, bool, bool, bool) {
|
|
|
|
let a;
|
|
|
|
let b;
|
|
|
|
let c;
|
|
|
|
let d;
|
|
|
|
|
|
|
|
match i {
|
|
|
|
7 => {
|
|
|
|
a = false;
|
|
|
|
b = true;
|
|
|
|
c = false;
|
|
|
|
d = true;
|
|
|
|
()
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
a = true;
|
|
|
|
b = false;
|
|
|
|
c = false;
|
|
|
|
d = true;
|
|
|
|
()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
(a, b, c, d)
|
|
|
|
}
|
|
|
|
|
2020-10-20 19:00:00 -05:00
|
|
|
fn match_nested_if() -> bool {
|
|
|
|
let val = match () {
|
2020-10-03 04:18:24 -05:00
|
|
|
() if if if if true { true } else { false } { true } else { false } {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
} =>
|
|
|
|
{
|
|
|
|
true
|
|
|
|
}
|
2020-10-20 19:00:00 -05:00
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
val
|
|
|
|
}
|
2020-08-14 19:00:00 -05:00
|
|
|
|
2020-08-10 18:11:05 -05:00
|
|
|
fn main() {
|
2020-10-03 04:18:24 -05:00
|
|
|
let _ = foo(None);
|
|
|
|
let _ = foo(Some(()));
|
|
|
|
let _ = bar(0);
|
|
|
|
let _ = match_nested_if();
|
2020-08-10 18:11:05 -05:00
|
|
|
}
|