@@ -216,14 +216,32 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
216
216
Ok ( self )
217
217
}
218
218
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 > {
220
220
match * ty. kind ( ) {
221
221
// Print all nominal types as paths (unlike `pretty_print_type`).
222
222
ty:: FnDef ( def_id, substs)
223
223
| ty:: Opaque ( def_id, substs)
224
224
| ty:: Projection ( ty:: ProjectionTy { item_def_id : def_id, substs } )
225
225
| ty:: Closure ( def_id, substs)
226
226
| 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
+
227
245
_ => self . pretty_print_type ( ty) ,
228
246
}
229
247
}
@@ -245,12 +263,22 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
245
263
246
264
fn print_const ( self , ct : ty:: Const < ' tcx > ) -> Result < Self :: Const , Self :: Error > {
247
265
// 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
+ ) ?;
251
279
}
280
+ _ => self . write_str ( "_" ) ?,
252
281
}
253
- self . write_str ( "_" ) ?;
254
282
Ok ( self )
255
283
}
256
284
0 commit comments