Skip to content

Commit 86c07a4

Browse files
Rollup merge of #78198 - tmiasko:assert, r=davidtwco
Simplify assert terminator only if condition evaluates to expected value
2 parents d9acd7d + a9470d0 commit 86c07a4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

compiler/rustc_mir/src/transform/simplify_branches.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranches {
4949
}
5050
TerminatorKind::Assert {
5151
target, cond: Operand::Constant(ref c), expected, ..
52-
} if (c.literal.try_eval_bool(tcx, param_env) == Some(true)) == expected => {
53-
TerminatorKind::Goto { target }
54-
}
52+
} => match c.literal.try_eval_bool(tcx, param_env) {
53+
Some(v) if v == expected => TerminatorKind::Goto { target },
54+
_ => continue,
55+
},
5556
TerminatorKind::FalseEdge { real_target, .. } => {
5657
TerminatorKind::Goto { target: real_target }
5758
}

0 commit comments

Comments
 (0)