@@ -78,7 +78,7 @@ impl<'tcx> ConstValue<'tcx> {
78
78
}
79
79
80
80
pub fn try_to_scalar_int ( & self ) -> Option < ScalarInt > {
81
- self . try_to_scalar ( ) ?. to_int ( ) . ok ( )
81
+ Some ( self . try_to_scalar ( ) ?. assert_int ( ) )
82
82
}
83
83
84
84
pub fn try_to_bits ( & self , size : Size ) -> Option < u128 > {
@@ -367,13 +367,16 @@ impl<'tcx, Tag> Scalar<Tag> {
367
367
#[ inline]
368
368
fn to_bits ( self , target_size : Size ) -> InterpResult < ' tcx , u128 > {
369
369
assert_ne ! ( target_size. bytes( ) , 0 , "you should never look at the bits of a ZST" ) ;
370
- self . to_int ( ) ?. to_bits ( target_size) . map_err ( |size| {
371
- err_ub ! ( ScalarSizeMismatch {
372
- target_size: target_size. bytes( ) ,
373
- data_size: size. bytes( ) ,
374
- } )
375
- . into ( )
376
- } )
370
+ match self {
371
+ Scalar :: Int ( int) => int. to_bits ( target_size) . map_err ( |size| {
372
+ err_ub ! ( ScalarSizeMismatch {
373
+ target_size: target_size. bytes( ) ,
374
+ data_size: size. bytes( ) ,
375
+ } )
376
+ . into ( )
377
+ } ) ,
378
+ Scalar :: Ptr ( _) => throw_unsup ! ( ReadPointerAsBytes ) ,
379
+ }
377
380
}
378
381
379
382
#[ inline( always) ]
@@ -383,7 +386,10 @@ impl<'tcx, Tag> Scalar<Tag> {
383
386
384
387
#[ inline]
385
388
pub fn assert_int ( self ) -> ScalarInt {
386
- self . to_int ( ) . expect ( "expected an int but got an abstract pointer" )
389
+ match self {
390
+ Scalar :: Ptr ( _) => bug ! ( "expected an int but got an abstract pointer" ) ,
391
+ Scalar :: Int ( int) => int,
392
+ }
387
393
}
388
394
389
395
#[ inline]
@@ -518,14 +524,6 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
518
524
}
519
525
}
520
526
521
- impl TryFrom < Scalar > for ScalarInt {
522
- type Error = super :: InterpErrorInfo < ' static > ;
523
- #[ inline]
524
- fn try_from ( scalar : Scalar ) -> InterpResult < ' static , Self > {
525
- scalar. to_int ( )
526
- }
527
- }
528
-
529
527
impl < Tag > From < ScalarInt > for Scalar < Tag > {
530
528
#[ inline( always) ]
531
529
fn from ( ptr : ScalarInt ) -> Self {
0 commit comments