@@ -78,7 +78,7 @@ impl<'tcx> ConstValue<'tcx> {
7878 }
7979
8080 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 ( ) )
8282 }
8383
8484 pub fn try_to_bits ( & self , size : Size ) -> Option < u128 > {
@@ -367,13 +367,16 @@ impl<'tcx, Tag> Scalar<Tag> {
367367 #[ inline]
368368 fn to_bits ( self , target_size : Size ) -> InterpResult < ' tcx , u128 > {
369369 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+ }
377380 }
378381
379382 #[ inline( always) ]
@@ -383,7 +386,10 @@ impl<'tcx, Tag> Scalar<Tag> {
383386
384387 #[ inline]
385388 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+ }
387393 }
388394
389395 #[ inline]
@@ -518,14 +524,6 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
518524 }
519525}
520526
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-
529527impl < Tag > From < ScalarInt > for Scalar < Tag > {
530528 #[ inline( always) ]
531529 fn from ( ptr : ScalarInt ) -> Self {
0 commit comments