@@ -346,16 +346,13 @@ impl<'tcx, Tag> Scalar<Tag> {
346
346
#[ inline]
347
347
fn to_bits ( self , target_size : Size ) -> InterpResult < ' tcx , u128 > {
348
348
assert_ne ! ( target_size. bytes( ) , 0 , "you should never look at the bits of a ZST" ) ;
349
- match self {
350
- Scalar :: Int ( int) => int. to_bits ( target_size) . map_err ( |size| {
351
- err_ub ! ( ScalarSizeMismatch {
352
- target_size: target_size. bytes( ) ,
353
- data_size: size. bytes( ) ,
354
- } )
355
- . into ( )
356
- } ) ,
357
- Scalar :: Ptr ( _) => throw_unsup ! ( ReadPointerAsBytes ) ,
358
- }
349
+ self . to_int ( ) ?. to_bits ( target_size) . map_err ( |size| {
350
+ err_ub ! ( ScalarSizeMismatch {
351
+ target_size: target_size. bytes( ) ,
352
+ data_size: size. bytes( ) ,
353
+ } )
354
+ . into ( )
355
+ } )
359
356
}
360
357
361
358
#[ inline( always) ]
@@ -364,13 +361,18 @@ impl<'tcx, Tag> Scalar<Tag> {
364
361
}
365
362
366
363
#[ inline]
367
- pub fn assert_int ( self ) -> ScalarInt {
364
+ pub fn to_int ( self ) -> InterpResult < ' tcx , ScalarInt > {
368
365
match self {
369
- Scalar :: Ptr ( _) => bug ! ( "expected an int but got an abstract pointer" ) ,
370
- Scalar :: Int ( int) => int,
366
+ Scalar :: Ptr ( _) => throw_unsup ! ( ReadPointerAsBytes ) ,
367
+ Scalar :: Int ( int) => Ok ( int) ,
371
368
}
372
369
}
373
370
371
+ #[ inline]
372
+ pub fn assert_int ( self ) -> ScalarInt {
373
+ self . to_int ( ) . expect ( "expected an int but got an abstract pointer" )
374
+ }
375
+
374
376
#[ inline]
375
377
pub fn assert_ptr ( self ) -> Pointer < Tag > {
376
378
match self {
0 commit comments