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