@@ -703,7 +703,7 @@ pub trait PrettyPrinter<'tcx>:
703703 // array length anon const, rustc will (with debug assertions) print the
704704 // constant's path. Which will end up here again.
705705 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 ) {
707707 p ! ( write( "{}" , n) ) ;
708708 } else {
709709 p ! ( write( "_" ) ) ;
@@ -916,26 +916,23 @@ pub trait PrettyPrinter<'tcx>:
916916 define_scoped_cx ! ( self ) ;
917917
918918 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- }
926919 // Byte strings (&[u8; N])
927920 ( Scalar :: Ptr ( ptr) , ty:: Ref ( _, ty:: TyS { kind : ty:: Array ( t, n) , .. } , _) )
928921 if * t == self . tcx ( ) . types . u8 =>
929922 {
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+ }
939936 }
940937 // Bool
941938 ( Scalar :: Raw { data : 0 , .. } , ty:: Bool ) => p ! ( write( "false" ) ) ,
@@ -961,12 +958,11 @@ pub trait PrettyPrinter<'tcx>:
961958 } ;
962959 }
963960 ( 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 ;
965963 let min = 1u128 << ( bit_size - 1 ) ;
966964 let max = min - 1 ;
967965
968- let ty = self . tcx ( ) . lift ( & ty) . unwrap ( ) ;
969- let size = self . tcx ( ) . layout_of ( ty:: ParamEnv :: empty ( ) . and ( ty) ) . unwrap ( ) . size ;
970966 let i_str = i. name_str ( ) ;
971967 match data {
972968 d if d == min => p ! ( write( "std::{}::MIN" , i_str) ) ,
@@ -1092,8 +1088,9 @@ pub trait PrettyPrinter<'tcx>:
10921088 Ok ( self )
10931089 }
10941090 ( 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 ) ;
10971094 let ptr = Pointer :: new ( AllocId ( 0 ) , offset) ;
10981095
10991096 let byte_str = alloc. get_bytes ( & self . tcx ( ) , ptr, n) . unwrap ( ) ;
0 commit comments