@@ -244,37 +244,24 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
244
244
) -> InterpResult < ' tcx , Scalar < M :: PointerTag > > {
245
245
use rustc:: ty:: TyKind :: * ;
246
246
247
- fn int_size < ' tcx > ( layout : TyLayout < ' tcx > ) -> Option < usize > {
248
- match layout. ty . sty {
249
- Int ( i) => i. bit_width ( ) ,
250
- Uint ( i) => i. bit_width ( ) ,
251
- _ => bug ! ( "Not an integer" ) ,
252
- }
253
- }
254
-
255
247
match dest_layout. ty . sty {
256
248
// Casting to a reference or fn pointer is not permitted by rustc,
257
249
// no need to support it here.
258
250
RawPtr ( _) => Ok ( ptr. into ( ) ) ,
259
251
Int ( IntTy :: Isize ) | Uint ( UintTy :: Usize ) => {
260
- let size = self . memory . pointer_size ( ) ;
261
-
262
- if let Ok ( bits) = self . force_bits ( Scalar :: Ptr ( ptr) , size) {
252
+ if let Ok ( bits) = self . force_bits ( Scalar :: Ptr ( ptr) , self . memory . pointer_size ( ) ) {
263
253
self . cast_from_int ( bits, src_layout, dest_layout)
264
254
} else {
265
255
Ok ( ptr. into ( ) )
266
256
}
267
257
}
268
258
Int ( _) | Uint ( _) => {
269
- let size = Size :: from_bits ( int_size ( dest_layout) . unwrap ( ) as u64 ) ;
270
-
271
- if let Ok ( bits) = self . force_bits ( Scalar :: Ptr ( ptr) , size) {
259
+ if let Ok ( bits) = self . force_bits ( Scalar :: Ptr ( ptr) , self . memory . pointer_size ( ) ) {
272
260
self . cast_from_int ( bits, src_layout, dest_layout)
273
261
} else {
274
262
err ! ( ReadPointerAsBytes )
275
263
}
276
- } ,
277
- // Casting to any other type is not implemented
264
+ }
278
265
_ => return err ! ( Unimplemented ( format!( "ptr to {:?} cast" , dest_layout. ty) ) ) ,
279
266
}
280
267
}
0 commit comments