diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 2f45347d113c..f9a771c7af7c 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -60,14 +60,12 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { TyUint(UintTy::U128) => Ok(PrimVal::Bytes(v)), TyInt(IntTy::Is) => { - let int_ty = self.tcx.sess.target.int_type; - let ty = self.tcx.mk_mach_int(int_ty); + let ty = self.tcx.types.isize; self.cast_from_int(v, ty, negative) } TyUint(UintTy::Us) => { - let uint_ty = self.tcx.sess.target.uint_type; - let ty = self.tcx.mk_mach_uint(uint_ty); + let ty = self.tcx.types.usize; self.cast_from_int(v, ty, negative) } diff --git a/src/librustc_mir/interpret/const_eval.rs b/src/librustc_mir/interpret/const_eval.rs index 82795340ddaf..c6483ff17833 100644 --- a/src/librustc_mir/interpret/const_eval.rs +++ b/src/librustc_mir/interpret/const_eval.rs @@ -92,7 +92,7 @@ pub fn eval_body_as_integer<'a, 'tcx>( TyInt(IntTy::I64) => ConstInt::I64(prim as i128 as i64), TyInt(IntTy::I128) => ConstInt::I128(prim as i128), TyInt(IntTy::Is) => ConstInt::Isize( - ConstIsize::new(prim as i128 as i64, tcx.sess.target.int_type) + ConstIsize::new(prim as i128 as i64, tcx.sess.target.isize_ty) .expect("miri should already have errored"), ), TyUint(UintTy::U8) => ConstInt::U8(prim as u8), @@ -101,7 +101,7 @@ pub fn eval_body_as_integer<'a, 'tcx>( TyUint(UintTy::U64) => ConstInt::U64(prim as u64), TyUint(UintTy::U128) => ConstInt::U128(prim), TyUint(UintTy::Us) => ConstInt::Usize( - ConstUsize::new(prim as u64, tcx.sess.target.uint_type) + ConstUsize::new(prim as u64, tcx.sess.target.usize_ty) .expect("miri should already have errored"), ), _ => { diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index bd7a42cca1fe..231bfa92ccd7 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -245,12 +245,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { } Variant(_) => unimplemented!(), - Struct(_) => unimplemented!(), - Tuple(_) => unimplemented!(), // function items are zero sized and thus have no readable value Function(..) => PrimVal::Undef, - Array(_) => unimplemented!(), - Repeat(_, _) => unimplemented!(), }; Ok(Value::ByVal(primval)) @@ -817,7 +813,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { Repeat(ref operand, _) => { let (elem_ty, length) = match dest_ty.sty { - ty::TyArray(elem_ty, n) => (elem_ty, n as u64), + ty::TyArray(elem_ty, n) => (elem_ty, n.val.to_const_int().unwrap().to_u64().unwrap()), _ => { bug!( "tried to assign array-repeat to non-array type {:?}", @@ -1920,7 +1916,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { let ptr = src.into_ptr(&self.memory)?; // u64 cast is from usize to u64, which is always good let valty = ValTy { - value: ptr.to_value_with_len(length as u64), + value: ptr.to_value_with_len(length.val.to_const_int().unwrap().to_u64().unwrap() ), ty: dest_ty, }; self.write_value(valty, dest) diff --git a/src/librustc_mir/interpret/lvalue.rs b/src/librustc_mir/interpret/lvalue.rs index 3342be7300e7..ba0f5fafa747 100644 --- a/src/librustc_mir/interpret/lvalue.rs +++ b/src/librustc_mir/interpret/lvalue.rs @@ -75,7 +75,7 @@ impl<'tcx> Lvalue { pub(super) fn elem_ty_and_len(self, ty: Ty<'tcx>) -> (Ty<'tcx>, u64) { match ty.sty { - ty::TyArray(elem, n) => (elem, n as u64), + ty::TyArray(elem, n) => (elem, n.val.to_const_int().unwrap().to_u64().unwrap() as u64), ty::TySlice(elem) => { match self { @@ -266,7 +266,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { let field = field_index as u64; let elem_size = match base_ty.sty { ty::TyArray(elem_ty, n) => { - assert!(field < n as u64); + assert!(field < n.val.to_const_int().unwrap().to_u64().unwrap() as u64); self.type_size(elem_ty)?.expect("array elements are sized") as u64 } _ => { diff --git a/src/librustc_mir/interpret/validation.rs b/src/librustc_mir/interpret/validation.rs index 9a16a4ec1509..1f9de6785fd2 100644 --- a/src/librustc_mir/interpret/validation.rs +++ b/src/librustc_mir/interpret/validation.rs @@ -525,6 +525,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { Ok(()) } TyArray(elem_ty, len) => { + let len = len.val.to_const_int().unwrap().to_u64().unwrap(); for i in 0..len { let inner_lvalue = self.lvalue_index(query.lval, query.ty, i as u64)?; self.validate(