Improve match statements

This commit is contained in:
ayushmishra2005 2021-05-14 08:57:33 +05:30
parent 17f30e5451
commit 34055a932b
3 changed files with 3 additions and 12 deletions

View File

@ -170,10 +170,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
}
fn is_switch<'tcx>(terminator: &Terminator<'tcx>) -> bool {
match terminator.kind {
TerminatorKind::SwitchInt { .. } => true,
_ => false,
}
matches!(terminator.kind, TerminatorKind::SwitchInt { .. })
}
struct Helper<'a, 'tcx> {

View File

@ -628,10 +628,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
// But `asm!(...)` could abort the program,
// so we cannot assume that the `unreachable` terminator itself is reachable.
// FIXME(Centril): use a normalization pass instead of a check.
|| bb.statements.iter().any(|stmt| match stmt.kind {
StatementKind::LlvmInlineAsm(..) => true,
_ => false,
})
|| bb.statements.iter().any(|stmt| matches!(stmt.kind, StatementKind::LlvmInlineAsm(..)))
})
.peekable();

View File

@ -31,10 +31,7 @@ fn option_as_ref_deref() {
}
fn match_like_matches() {
let _y = match Some(5) {
Some(0) => true,
_ => false,
};
let _y = matches!(Some(5), Some(0));
}
fn match_same_arms() {