@@ -703,7 +703,7 @@ pub trait PrettyPrinter<'tcx>:
703
703
// array length anon const, rustc will (with debug assertions) print the
704
704
// constant's path. Which will end up here again.
705
705
p ! ( write( "_" ) ) ;
706
- } else if let Some ( n) = sz. try_eval_usize ( self . tcx ( ) , ty :: ParamEnv :: empty ( ) ) {
706
+ } else if let Some ( n) = sz. val . try_to_bits ( self . tcx ( ) . data_layout . pointer_size ) {
707
707
p ! ( write( "{}" , n) ) ;
708
708
} else {
709
709
p ! ( write( "_" ) ) ;
@@ -916,26 +916,23 @@ pub trait PrettyPrinter<'tcx>:
916
916
define_scoped_cx ! ( self ) ;
917
917
918
918
match ( scalar, & ty. kind ) {
919
- // Single element arrays print their element (they are `#[transparent]`) enclosed in
920
- // square brackets.
921
- ( _, ty:: Array ( t, n) ) if n. eval_usize ( self . tcx ( ) , ty:: ParamEnv :: empty ( ) ) == 1 => {
922
- p ! ( write( "[" ) ) ;
923
- self = self . pretty_print_const_scalar ( scalar, t, print_ty) ?;
924
- p ! ( write( "]" ) ) ;
925
- }
926
919
// Byte strings (&[u8; N])
927
920
( Scalar :: Ptr ( ptr) , ty:: Ref ( _, ty:: TyS { kind : ty:: Array ( t, n) , .. } , _) )
928
921
if * t == self . tcx ( ) . types . u8 =>
929
922
{
930
- let n = n. eval_usize ( self . tcx ( ) , ty:: ParamEnv :: empty ( ) ) ;
931
- let byte_str = self
932
- . tcx ( )
933
- . alloc_map
934
- . lock ( )
935
- . unwrap_memory ( ptr. alloc_id )
936
- . get_bytes ( & self . tcx ( ) , ptr, Size :: from_bytes ( n) )
937
- . unwrap ( ) ;
938
- p ! ( pretty_print_byte_str( byte_str) ) ;
923
+ match n. val . try_to_bits ( self . tcx ( ) . data_layout . pointer_size ) {
924
+ Some ( n) => {
925
+ let byte_str = self
926
+ . tcx ( )
927
+ . alloc_map
928
+ . lock ( )
929
+ . unwrap_memory ( ptr. alloc_id )
930
+ . get_bytes ( & self . tcx ( ) , ptr, Size :: from_bytes ( n as u64 ) )
931
+ . unwrap ( ) ;
932
+ p ! ( pretty_print_byte_str( byte_str) ) ;
933
+ }
934
+ None => self . write_str ( "_" ) ?,
935
+ }
939
936
}
940
937
// Bool
941
938
( Scalar :: Raw { data : 0 , .. } , ty:: Bool ) => p ! ( write( "false" ) ) ,
@@ -961,12 +958,11 @@ pub trait PrettyPrinter<'tcx>:
961
958
} ;
962
959
}
963
960
( Scalar :: Raw { data, .. } , ty:: Int ( i) ) => {
964
- let bit_size = Integer :: from_attr ( & self . tcx ( ) , SignedInt ( * i) ) . size ( ) . bits ( ) as u128 ;
961
+ let size = Integer :: from_attr ( & self . tcx ( ) , SignedInt ( * i) ) . size ( ) ;
962
+ let bit_size = size. bits ( ) as u128 ;
965
963
let min = 1u128 << ( bit_size - 1 ) ;
966
964
let max = min - 1 ;
967
965
968
- let ty = self . tcx ( ) . lift ( & ty) . unwrap ( ) ;
969
- let size = self . tcx ( ) . layout_of ( ty:: ParamEnv :: empty ( ) . and ( ty) ) . unwrap ( ) . size ;
970
966
let i_str = i. name_str ( ) ;
971
967
match data {
972
968
d if d == min => p ! ( write( "std::{}::MIN" , i_str) ) ,
@@ -1092,8 +1088,9 @@ pub trait PrettyPrinter<'tcx>:
1092
1088
Ok ( self )
1093
1089
}
1094
1090
( ConstValue :: ByRef { alloc, offset } , ty:: Array ( t, n) ) if * t == u8_type => {
1095
- let n = n. eval_usize ( self . tcx ( ) , ty:: ParamEnv :: empty ( ) ) ;
1096
- let n = Size :: from_bytes ( n) ;
1091
+ let n = n. val . try_to_bits ( self . tcx ( ) . data_layout . pointer_size ) . unwrap ( ) ;
1092
+ // cast is ok because we already checked for pointer size (32 or 64 bit) above
1093
+ let n = Size :: from_bytes ( n as u64 ) ;
1097
1094
let ptr = Pointer :: new ( AllocId ( 0 ) , offset) ;
1098
1095
1099
1096
let byte_str = alloc. get_bytes ( & self . tcx ( ) , ptr, n) . unwrap ( ) ;
0 commit comments