1
+ use hir:: def:: Namespace ;
1
2
use hir:: def_id:: DefId ;
2
3
use hir:: map:: definitions:: DefPathData ;
3
4
use middle:: region;
@@ -285,26 +286,12 @@ impl<F: fmt::Write> PrintCx<'a, 'gcx, 'tcx, FmtPrinter<F>> {
285
286
286
287
fn parameterized (
287
288
& mut self ,
288
- mut def_id : DefId ,
289
+ def_id : DefId ,
289
290
substs : & Substs < ' tcx > ,
291
+ ns : Namespace ,
290
292
projections : impl Iterator < Item = ty:: ExistentialProjection < ' tcx > > ,
291
293
) -> fmt:: Result {
292
- let mut key = self . tcx . def_key ( def_id) ;
293
- let is_value_ns = match key. disambiguated_data . data {
294
- DefPathData :: ValueNs ( _) |
295
- DefPathData :: EnumVariant ( _) => true ,
296
-
297
- // Skip `StructCtor` so that `Struct::<T>` will be printed,
298
- // instead of the less pretty `Struct<T>::{{constructor}}`.
299
- DefPathData :: StructCtor => {
300
- def_id. index = key. parent . unwrap ( ) ;
301
- key = self . tcx . def_key ( def_id) ;
302
- true
303
- }
304
-
305
- _ => false ,
306
- } ;
307
-
294
+ let key = self . tcx . def_key ( def_id) ;
308
295
let generics = self . tcx . generics_of ( def_id) ;
309
296
310
297
if let Some ( parent_def_id) = generics. parent {
@@ -315,13 +302,20 @@ impl<F: fmt::Write> PrintCx<'a, 'gcx, 'tcx, FmtPrinter<F>> {
315
302
parent_generics. has_self && parent_generics. parent_count == 0 ;
316
303
if parent_has_own_self {
317
304
print ! ( self , write( "<" ) , print_display( substs. type_at( 0 ) ) , write( " as " ) ) ?;
318
- }
319
- self . parameterized ( parent_def_id, substs, iter:: empty ( ) ) ?;
320
- if parent_has_own_self {
305
+ self . parameterized ( parent_def_id, substs, Namespace :: TypeNS , iter:: empty ( ) ) ?;
321
306
print ! ( self , write( ">" ) ) ?;
307
+ } else {
308
+ self . parameterized ( parent_def_id, substs, ns, iter:: empty ( ) ) ?;
322
309
}
323
310
324
- print ! ( self , write( "::{}" , key. disambiguated_data. data. as_interned_str( ) ) ) ?;
311
+ // Skip `::{{constructor}}` on tuple/unit structs.
312
+ match key. disambiguated_data . data {
313
+ DefPathData :: StructCtor => { }
314
+
315
+ _ => {
316
+ print ! ( self , write( "::{}" , key. disambiguated_data. data. as_interned_str( ) ) ) ?;
317
+ }
318
+ }
325
319
} else {
326
320
// Try to print `impl`s more like how you'd refer to their associated items.
327
321
if let DefPathData :: Impl = key. disambiguated_data . data {
@@ -352,7 +346,7 @@ impl<F: fmt::Write> PrintCx<'a, 'gcx, 'tcx, FmtPrinter<F>> {
352
346
}
353
347
} ;
354
348
355
- let start = if is_value_ns { "::<" } else { "<" } ;
349
+ let start = if ns == Namespace :: ValueNS { "::<" } else { "<" } ;
356
350
357
351
let has_own_self = generics. has_self && generics. parent_count == 0 ;
358
352
let params = & generics. params [ has_own_self as usize ..] ;
@@ -491,10 +485,15 @@ impl<F: fmt::Write> PrintCx<'a, 'gcx, 'tcx, FmtPrinter<F>> {
491
485
}
492
486
}
493
487
494
- pub fn parameterized < F : fmt:: Write > ( f : & mut F , did : DefId , substs : & Substs < ' _ > ) -> fmt:: Result {
488
+ pub fn parameterized < F : fmt:: Write > (
489
+ f : & mut F ,
490
+ did : DefId ,
491
+ substs : & Substs < ' _ > ,
492
+ ns : Namespace ,
493
+ ) -> fmt:: Result {
495
494
PrintCx :: with ( FmtPrinter { fmt : f } , |mut cx| {
496
495
let substs = cx. tcx . lift ( & substs) . expect ( "could not lift for printing" ) ;
497
- cx. parameterized ( did, substs, iter:: empty ( ) )
496
+ cx. parameterized ( did, substs, ns , iter:: empty ( ) )
498
497
} )
499
498
}
500
499
@@ -533,6 +532,7 @@ define_print! {
533
532
cx. parameterized(
534
533
principal. def_id,
535
534
principal. substs,
535
+ Namespace :: TypeNS ,
536
536
self . projection_bounds( ) ,
537
537
) ?;
538
538
}
@@ -657,7 +657,7 @@ define_print! {
657
657
let trait_ref = * ty:: Binder :: bind( * self )
658
658
. with_self_ty( cx. tcx, dummy_self)
659
659
. skip_binder( ) ;
660
- cx. parameterized( trait_ref. def_id, trait_ref. substs, iter:: empty( ) )
660
+ cx. parameterized( trait_ref. def_id, trait_ref. substs, Namespace :: TypeNS , iter:: empty( ) )
661
661
}
662
662
debug {
663
663
self . print_display( cx)
@@ -1100,12 +1100,16 @@ define_print_multi! {
1100
1100
define_print ! {
1101
1101
( ' tcx) ty:: TraitRef <' tcx>, ( self , cx) {
1102
1102
display {
1103
- cx. parameterized( self . def_id, self . substs, iter:: empty( ) )
1103
+ cx. parameterized( self . def_id, self . substs, Namespace :: TypeNS , iter:: empty( ) )
1104
1104
}
1105
1105
debug {
1106
- print!( cx, write( "<" ) , print( self . self_ty( ) ) , write( " as " ) ) ?;
1107
- cx. parameterized( self . def_id, self . substs, iter:: empty( ) ) ?;
1108
- print!( cx, write( ">" ) )
1106
+ print!( cx,
1107
+ write( "<" ) ,
1108
+ print( self . self_ty( ) ) ,
1109
+ write( " as " ) ,
1110
+ print_display( self ) ,
1111
+ write( ">" )
1112
+ )
1109
1113
}
1110
1114
}
1111
1115
}
@@ -1151,7 +1155,7 @@ define_print! {
1151
1155
FnDef ( def_id, substs) => {
1152
1156
let sig = cx. tcx. fn_sig( def_id) . subst( cx. tcx, substs) ;
1153
1157
print!( cx, print( sig) , write( " {{" ) ) ?;
1154
- cx. parameterized( def_id, substs, iter:: empty( ) ) ?;
1158
+ cx. parameterized( def_id, substs, Namespace :: ValueNS , iter:: empty( ) ) ?;
1155
1159
print!( cx, write( "}}" ) )
1156
1160
}
1157
1161
FnPtr ( ref bare_fn) => {
@@ -1173,7 +1177,9 @@ define_print! {
1173
1177
ty:: BoundTyKind :: Param ( p) => print!( cx, write( "{}" , p) ) ,
1174
1178
}
1175
1179
}
1176
- Adt ( def, substs) => cx. parameterized( def. did, substs, iter:: empty( ) ) ,
1180
+ Adt ( def, substs) => {
1181
+ cx. parameterized( def. did, substs, Namespace :: TypeNS , iter:: empty( ) )
1182
+ }
1177
1183
Dynamic ( data, r) => {
1178
1184
let print_r = r. display_outputs_anything( cx) ;
1179
1185
if print_r {
@@ -1186,7 +1192,9 @@ define_print! {
1186
1192
}
1187
1193
Ok ( ( ) )
1188
1194
}
1189
- Foreign ( def_id) => cx. parameterized( def_id, Substs :: empty( ) , iter:: empty( ) ) ,
1195
+ Foreign ( def_id) => {
1196
+ cx. parameterized( def_id, Substs :: empty( ) , Namespace :: TypeNS , iter:: empty( ) )
1197
+ }
1190
1198
Projection ( ref data) => data. print( cx) ,
1191
1199
UnnormalizedProjection ( ref data) => {
1192
1200
print!( cx, write( "Unnormalized(" ) ) ?;
@@ -1411,7 +1419,7 @@ define_print! {
1411
1419
define_print ! {
1412
1420
( ' tcx) ty:: ProjectionTy <' tcx>, ( self , cx) {
1413
1421
display {
1414
- cx. parameterized( self . item_def_id, self . substs, iter:: empty( ) )
1422
+ cx. parameterized( self . item_def_id, self . substs, Namespace :: TypeNS , iter:: empty( ) )
1415
1423
}
1416
1424
}
1417
1425
}
@@ -1448,7 +1456,7 @@ define_print! {
1448
1456
}
1449
1457
ty:: Predicate :: ConstEvaluatable ( def_id, substs) => {
1450
1458
print!( cx, write( "the constant `" ) ) ?;
1451
- cx. parameterized( def_id, substs, iter:: empty( ) ) ?;
1459
+ cx. parameterized( def_id, substs, Namespace :: ValueNS , iter:: empty( ) ) ?;
1452
1460
print!( cx, write( "` can be evaluated" ) )
1453
1461
}
1454
1462
}
0 commit comments