diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 0fa38366e1c..9789c1f0b2a 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -12,10 +12,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { src_ty: Ty<'tcx>, dest_ty: Ty<'tcx> ) -> EvalResult<'tcx, PrimVal> { - let kind = self.ty_to_primval_kind(src_ty)?; + let src_kind = self.ty_to_primval_kind(src_ty)?; use value::PrimValKind::*; - match kind { + match src_kind { F32 => self.cast_float(val.to_f32()? as f64, dest_ty), F64 => self.cast_float(val.to_f64()?, dest_ty), @@ -81,7 +81,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { TyChar => Err(EvalError::InvalidChar(v)), // No alignment check needed for raw pointers - TyRawPtr(_) => Ok(PrimVal::Bytes(v % (1 << self.memory.pointer_size()))), + TyRawPtr(_) => Ok(PrimVal::Bytes(v % (1 << (self.memory.pointer_size()*8)))), _ => Err(EvalError::Unimplemented(format!("int to {:?} cast", ty))), } diff --git a/tests/run-pass/ptr_int_casts.rs b/tests/run-pass/ptr_int_casts.rs index 88fb16e069e..b1b06263056 100644 --- a/tests/run-pass/ptr_int_casts.rs +++ b/tests/run-pass/ptr_int_casts.rs @@ -29,4 +29,7 @@ fn main() { let x : fn() -> i32 = unsafe { mem::transmute(y as *mut u8) }; assert_eq!(x(), 42); } + + // involving types other than usize + assert_eq!((-1i32) as usize as *const i32 as usize, (-1i32) as usize); }