mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 12:13:43 +00:00
Update to pick Eq or Ne
This commit is contained in:
parent
bce5eb0c08
commit
f51422b474
@ -52,11 +52,8 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
|
|||||||
if let Some(f_c) = f_c.literal.try_eval_bool(tcx, param_env) {
|
if let Some(f_c) = f_c.literal.try_eval_bool(tcx, param_env) {
|
||||||
// This should also be a bool because it's writing to the same place
|
// This should also be a bool because it's writing to the same place
|
||||||
let s_c = s_c.literal.try_eval_bool(tcx, param_env).unwrap();
|
let s_c = s_c.literal.try_eval_bool(tcx, param_env).unwrap();
|
||||||
// Check that only const assignments of opposite bool values are
|
assert_ne!(f_c, s_c, "Unexpected match would've compared eq earlier");
|
||||||
// permitted.
|
continue;
|
||||||
if f_c != s_c {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
@ -70,14 +67,19 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
|
|||||||
bbs[bb_idx].terminator_mut().kind = TerminatorKind::Goto { target: first };
|
bbs[bb_idx].terminator_mut().kind = TerminatorKind::Goto { target: first };
|
||||||
for s in bbs[first].statements.iter_mut() {
|
for s in bbs[first].statements.iter_mut() {
|
||||||
if let StatementKind::Assign(box (_, ref mut rhs)) = s.kind {
|
if let StatementKind::Assign(box (_, ref mut rhs)) = s.kind {
|
||||||
let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size;
|
if let Rvalue::Use(Operand::Constant(c)) = rhs {
|
||||||
let const_cmp = Operand::const_from_scalar(
|
let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size;
|
||||||
tcx,
|
let const_cmp = Operand::const_from_scalar(
|
||||||
switch_ty,
|
tcx,
|
||||||
crate::interpret::Scalar::from_uint(val, size),
|
switch_ty,
|
||||||
rustc_span::DUMMY_SP,
|
crate::interpret::Scalar::from_uint(val, size),
|
||||||
);
|
rustc_span::DUMMY_SP,
|
||||||
*rhs = Rvalue::BinaryOp(BinOp::Eq, Operand::Move(discr), const_cmp);
|
);
|
||||||
|
if let Some(c) = c.literal.try_eval_bool(tcx, param_env) {
|
||||||
|
let op = if c { BinOp::Eq } else { BinOp::Ne };
|
||||||
|
*rhs = Rvalue::BinaryOp(op, Operand::Move(discr), const_cmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user