Skip to content

Commit f1ea9ef

Browse files
committed
Remove ty_to_primitive
1 parent 879d8f7 commit f1ea9ef

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,13 +1265,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
12651265
}
12661266
}
12671267

1268-
pub fn ty_to_primitive(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, layout::Primitive> {
1269-
match self.layout_of(ty)?.abi {
1270-
layout::Abi::Scalar(ref scalar) => Ok(scalar.value),
1271-
_ => err!(TypeNotPrimitive(ty)),
1272-
}
1273-
}
1274-
12751268
fn ensure_valid_value(&self, val: Scalar, ty: Ty<'tcx>) -> EvalResult<'tcx> {
12761269
match ty.sty {
12771270
ty::TyBool => val.to_bool().map(|_| ()),

src/librustc_mir/interpret/operator.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::mir;
2-
use rustc::ty::{self, Ty};
2+
use rustc::ty::{self, Ty, layout};
33
use syntax::ast::FloatTy;
44
use rustc::ty::layout::LayoutOf;
55
use rustc_apfloat::ieee::{Double, Single};
@@ -68,8 +68,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
6868
) -> EvalResult<'tcx, (Scalar, bool)> {
6969
use rustc::mir::BinOp::*;
7070

71-
let left_kind = self.ty_to_primitive(left_ty)?;
72-
let right_kind = self.ty_to_primitive(right_ty)?;
71+
let left_layout = self.layout_of(left_ty)?;
72+
let right_layout = self.layout_of(right_ty)?;
73+
74+
let left_kind = match left_layout.abi {
75+
layout::Abi::Scalar(ref scalar) => scalar.value,
76+
_ => return err!(TypeNotPrimitive(left_ty)),
77+
};
78+
let right_kind = match right_layout.abi {
79+
layout::Abi::Scalar(ref scalar) => scalar.value,
80+
_ => return err!(TypeNotPrimitive(right_ty)),
81+
};
7382
trace!("Running binary op {:?}: {:?} ({:?}), {:?} ({:?})", bin_op, left, left_kind, right, right_kind);
7483

7584
// I: Handle operations that support pointers
@@ -79,9 +88,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
7988
}
8089
}
8190

82-
let left_layout = self.layout_of(left_ty)?;
83-
let right_layout = self.layout_of(right_ty)?;
84-
8591
// II: From now on, everything must be bytes, no pointers
8692
let l = left.to_bits(left_layout.size)?;
8793
let r = right.to_bits(right_layout.size)?;

0 commit comments

Comments
 (0)