Skip to content

Commit a9470d0

Browse files
committed
Simplify assert terminator only if condition evaluates to expected value
1 parent 22e6b9c commit a9470d0

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)