Skip to content

Commit

Permalink
Fold an if on a match returning a bool directly into the match
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 15, 2019
1 parent 1b93eda commit b3731ee
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,13 @@ fn op_to_const<'tcx>(
op: OpTy<'tcx>,
) -> EvalResult<'tcx, ty::Const<'tcx>> {
// We do not normalize just any data. Only scalar layout and slices.
let normalize = match op.layout.abi {
layout::Abi::Scalar(..) => true,
layout::Abi::ScalarPair(..) => op.layout.ty.is_slice(),
_ => false,
};
let normalized_op = if normalize {
ecx.try_read_immediate(op)?
} else {
match *op {
let normalized_op = match op.layout.abi {
layout::Abi::Scalar(..) => ecx.try_read_immediate(op)?,
layout::Abi::ScalarPair(..) if op.layout.ty.is_slice() => ecx.try_read_immediate(op)?,
_ => match *op {
Operand::Indirect(mplace) => Err(mplace),
Operand::Immediate(val) => Ok(val)
}
},
};
let (val, alloc) = match normalized_op {
Err(MemPlace { ptr, align, meta }) => {
Expand Down

0 comments on commit b3731ee

Please sign in to comment.