@@ -216,14 +216,32 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
216216 Ok ( self )
217217 }
218218
219- fn print_type ( self , ty : Ty < ' tcx > ) -> Result < Self :: Type , Self :: Error > {
219+ fn print_type ( mut self , ty : Ty < ' tcx > ) -> Result < Self :: Type , Self :: Error > {
220220 match * ty. kind ( ) {
221221 // Print all nominal types as paths (unlike `pretty_print_type`).
222222 ty:: FnDef ( def_id, substs)
223223 | ty:: Opaque ( def_id, substs)
224224 | ty:: Projection ( ty:: ProjectionTy { item_def_id : def_id, substs } )
225225 | ty:: Closure ( def_id, substs)
226226 | ty:: Generator ( def_id, substs, _) => self . print_def_path ( def_id, substs) ,
227+
228+ // The `pretty_print_type` formatting of array size depends on
229+ // -Zverbose flag, so we cannot reuse it here.
230+ ty:: Array ( ty, size) => {
231+ self . write_str ( "[" ) ?;
232+ self = self . print_type ( ty) ?;
233+ self . write_str ( "; " ) ?;
234+ if let Some ( size) = size. val ( ) . try_to_bits ( self . tcx ( ) . data_layout . pointer_size ) {
235+ write ! ( self , "{}" , size) ?
236+ } else if let ty:: ConstKind :: Param ( param) = size. val ( ) {
237+ self = param. print ( self ) ?
238+ } else {
239+ self . write_str ( "_" ) ?
240+ }
241+ self . write_str ( "]" ) ?;
242+ Ok ( self )
243+ }
244+
227245 _ => self . pretty_print_type ( ty) ,
228246 }
229247 }
@@ -245,12 +263,22 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
245263
246264 fn print_const ( self , ct : ty:: Const < ' tcx > ) -> Result < Self :: Const , Self :: Error > {
247265 // only print integers
248- if let ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: Int { .. } ) ) = ct. val ( ) {
249- if ct. ty ( ) . is_integral ( ) {
250- return self . pretty_print_const ( ct, true ) ;
266+ match ( ct. val ( ) , ct. ty ( ) . kind ( ) ) {
267+ (
268+ ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: Int ( scalar) ) ) ,
269+ ty:: Int ( _) | ty:: Uint ( _) ,
270+ ) => {
271+ // The `pretty_print_const` formatting depends on -Zverbose
272+ // flag, so we cannot reuse it here.
273+ let signed = matches ! ( ct. ty( ) . kind( ) , ty:: Int ( _) ) ;
274+ write ! (
275+ self ,
276+ "{:#?}" ,
277+ ty:: ConstInt :: new( scalar, signed, ct. ty( ) . is_ptr_sized_integral( ) )
278+ ) ?;
251279 }
280+ _ => self . write_str ( "_" ) ?,
252281 }
253- self . write_str ( "_" ) ?;
254282 Ok ( self )
255283 }
256284
0 commit comments