Skip to content

Commit e393046

Browse files
Simplify code since CEnum is always immediate now.
1 parent 08290b2 commit e393046

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

src/librustc_trans/mir/rvalue.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -260,37 +260,24 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
260260
let r_t_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
261261
let ll_t_in = type_of::immediate_type_of(bcx.ccx, operand.ty);
262262
let ll_t_out = type_of::immediate_type_of(bcx.ccx, cast_ty);
263-
let (llval, signed) = if let CastTy::Int(IntTy::CEnum) = r_t_in {
264-
let l = bcx.ccx.layout_of(operand.ty);
265-
let discr = match operand.val {
266-
OperandValue::Immediate(llval) => llval,
267-
OperandValue::Ref(llptr) => {
268-
adt::trans_get_discr(&bcx, operand.ty, llptr, None, true)
269-
}
270-
OperandValue::Pair(..) => bug!("Unexpected Pair operand")
271-
};
272-
let (signed, min, max) = match l {
273-
&Layout::CEnum { signed, min, max, .. } => {
274-
(signed, min, max)
275-
}
276-
_ => bug!("CEnum {:?} is not an enum", operand)
277-
};
278-
263+
let llval = operand.immediate();
264+
let l = bcx.ccx.layout_of(operand.ty);
265+
let signed = if let Layout::CEnum { signed, min, max, .. } = *l {
279266
if max > min {
280267
// We want `table[e as usize]` to not
281268
// have bound checks, and this is the most
282269
// convenient place to put the `assume`.
283270

284271
base::call_assume(&bcx, bcx.icmp(
285272
llvm::IntULE,
286-
discr,
287-
C_integral(common::val_ty(discr), max, false)
288-
))
273+
llval,
274+
C_integral(common::val_ty(llval), max, false)
275+
));
289276
}
290277

291-
(discr, signed)
278+
signed
292279
} else {
293-
(operand.immediate(), operand.ty.is_signed())
280+
operand.ty.is_signed()
294281
};
295282

296283
let newval = match (r_t_in, r_t_out) {

0 commit comments

Comments
 (0)