@@ -395,8 +395,8 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
395
395
}
396
396
ty_enum( did, substs) | ty_struct( did, substs) => {
397
397
let base = ty:: item_path_str ( cx, did) ;
398
- let generics = ty :: lookup_item_type ( cx, did) . generics ;
399
- parameterized ( cx , & base , substs , & generics , did , & [ ] )
398
+ parameterized ( cx, & base , substs , did, & [ ] ,
399
+ || ty :: lookup_item_type ( cx , did ) . generics )
400
400
}
401
401
ty_trait( ref data) => {
402
402
data. user_string ( cx)
@@ -444,23 +444,40 @@ pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory)
444
444
}
445
445
}
446
446
447
- pub fn parameterized < ' tcx > ( cx : & ctxt < ' tcx > ,
448
- base : & str ,
449
- substs : & subst:: Substs < ' tcx > ,
450
- generics : & ty:: Generics < ' tcx > ,
451
- did : ast:: DefId ,
452
- projections : & [ ty:: ProjectionPredicate < ' tcx > ] )
453
- -> String
447
+ pub fn parameterized < ' tcx , GG > ( cx : & ctxt < ' tcx > ,
448
+ base : & str ,
449
+ substs : & subst:: Substs < ' tcx > ,
450
+ did : ast:: DefId ,
451
+ projections : & [ ty:: ProjectionPredicate < ' tcx > ] ,
452
+ get_generics : GG )
453
+ -> String
454
+ where GG : FnOnce ( ) -> ty:: Generics < ' tcx >
454
455
{
455
456
if cx. sess . verbose ( ) {
456
- if substs. is_noop ( ) {
457
- return format ! ( "{}" , base) ;
458
- } else {
459
- return format ! ( "{}<{},{}>" ,
460
- base,
461
- substs. regions. repr( cx) ,
462
- substs. types. repr( cx) ) ;
457
+ let mut strings = vec ! [ ] ;
458
+ match substs. regions {
459
+ subst:: ErasedRegions => {
460
+ strings. push ( format ! ( ".." ) ) ;
461
+ }
462
+ subst:: NonerasedRegions ( ref regions) => {
463
+ for region in regions. iter ( ) {
464
+ strings. push ( region. repr ( cx) ) ;
465
+ }
466
+ }
463
467
}
468
+ for ty in substs. types . iter ( ) {
469
+ strings. push ( ty. repr ( cx) ) ;
470
+ }
471
+ for projection in projections. iter ( ) {
472
+ strings. push ( format ! ( "{}={}" ,
473
+ projection. projection_ty. item_name. user_string( cx) ,
474
+ projection. ty. user_string( cx) ) ) ;
475
+ }
476
+ return if strings. is_empty ( ) {
477
+ format ! ( "{}" , base)
478
+ } else {
479
+ format ! ( "{}<{}>" , base, strings. connect( "," ) )
480
+ } ;
464
481
}
465
482
466
483
let mut strs = Vec :: new ( ) ;
@@ -484,6 +501,13 @@ pub fn parameterized<'tcx>(cx: &ctxt<'tcx>,
484
501
}
485
502
}
486
503
504
+ // It is important to execute this conditionally, only if -Z
505
+ // verbose is false. Otherwise, debug logs can sometimes cause
506
+ // ICEs trying to fetch the generics early in the pipeline. This
507
+ // is kind of a hacky workaround in that -Z verbose is required to
508
+ // avoid those ICEs.
509
+ let generics = get_generics ( ) ;
510
+
487
511
let tps = substs. types . get_slice ( subst:: TypeSpace ) ;
488
512
let ty_params = generics. types . get_slice ( subst:: TypeSpace ) ;
489
513
let has_defaults = ty_params. last ( ) . map_or ( false , |def| def. default . is_some ( ) ) ;
@@ -645,13 +669,12 @@ impl<'tcx> UserString<'tcx> for TraitAndProjections<'tcx> {
645
669
fn user_string ( & self , tcx : & ctxt < ' tcx > ) -> String {
646
670
let & ( ref trait_ref, ref projection_bounds) = self ;
647
671
let base = ty:: item_path_str ( tcx, trait_ref. def_id ) ;
648
- let trait_def = ty:: lookup_trait_def ( tcx, trait_ref. def_id ) ;
649
672
parameterized ( tcx,
650
673
& base,
651
674
trait_ref. substs ,
652
- & trait_def. generics ,
653
675
trait_ref. def_id ,
654
- & projection_bounds[ ] )
676
+ & projection_bounds[ ] ,
677
+ || ty:: lookup_trait_def ( tcx, trait_ref. def_id ) . generics . clone ( ) )
655
678
}
656
679
}
657
680
@@ -687,10 +710,9 @@ impl<'tcx> UserString<'tcx> for ty::TyTrait<'tcx> {
687
710
}
688
711
689
712
impl < ' tcx > Repr < ' tcx > for ty:: TypeParameterDef < ' tcx > {
690
- fn repr ( & self , tcx : & ctxt < ' tcx > ) -> String {
691
- format ! ( "TypeParameterDef({:?}, {}, { :?}/{})" ,
713
+ fn repr ( & self , _tcx : & ctxt < ' tcx > ) -> String {
714
+ format ! ( "TypeParameterDef({:?}, {:?}/{})" ,
692
715
self . def_id,
693
- self . bounds. repr( tcx) ,
694
716
self . space,
695
717
self . index)
696
718
}
@@ -781,11 +803,8 @@ impl<'tcx> Repr<'tcx> for ty::TraitRef<'tcx> {
781
803
// to enumerate the `for<...>` etc because the debruijn index
782
804
// tells you everything you need to know.
783
805
let base = ty:: item_path_str ( tcx, self . def_id ) ;
784
- let trait_def = ty:: lookup_trait_def ( tcx, self . def_id ) ;
785
- format ! ( "TraitRef({}, {})" ,
786
- self . substs. self_ty( ) . repr( tcx) ,
787
- parameterized( tcx, & base, self . substs,
788
- & trait_def. generics, self . def_id, & [ ] ) )
806
+ parameterized ( tcx, & base, self . substs , self . def_id , & [ ] ,
807
+ || ty:: lookup_trait_def ( tcx, self . def_id ) . generics . clone ( ) )
789
808
}
790
809
}
791
810
@@ -987,16 +1006,22 @@ impl<'tcx> Repr<'tcx> for ty::TypeScheme<'tcx> {
987
1006
988
1007
impl < ' tcx > Repr < ' tcx > for ty:: Generics < ' tcx > {
989
1008
fn repr ( & self , tcx : & ctxt < ' tcx > ) -> String {
990
- format ! ( "Generics(types: {}, regions: {}, predicates: {} )" ,
1009
+ format ! ( "Generics(types: {}, regions: {})" ,
991
1010
self . types. repr( tcx) ,
992
- self . regions. repr( tcx) ,
1011
+ self . regions. repr( tcx) )
1012
+ }
1013
+ }
1014
+
1015
+ impl < ' tcx > Repr < ' tcx > for ty:: GenericPredicates < ' tcx > {
1016
+ fn repr ( & self , tcx : & ctxt < ' tcx > ) -> String {
1017
+ format ! ( "GenericPredicates(predicates: {})" ,
993
1018
self . predicates. repr( tcx) )
994
1019
}
995
1020
}
996
1021
997
- impl < ' tcx > Repr < ' tcx > for ty:: GenericBounds < ' tcx > {
1022
+ impl < ' tcx > Repr < ' tcx > for ty:: InstantiatedPredicates < ' tcx > {
998
1023
fn repr ( & self , tcx : & ctxt < ' tcx > ) -> String {
999
- format ! ( "GenericBounds ({})" ,
1024
+ format ! ( "InstantiatedPredicates ({})" ,
1000
1025
self . predicates. repr( tcx) )
1001
1026
}
1002
1027
}
@@ -1249,9 +1274,8 @@ impl<'tcx, T> UserString<'tcx> for ty::Binder<T>
1249
1274
impl < ' tcx > UserString < ' tcx > for ty:: TraitRef < ' tcx > {
1250
1275
fn user_string ( & self , tcx : & ctxt < ' tcx > ) -> String {
1251
1276
let path_str = ty:: item_path_str ( tcx, self . def_id ) ;
1252
- let trait_def = ty:: lookup_trait_def ( tcx, self . def_id ) ;
1253
- parameterized ( tcx, & path_str, self . substs ,
1254
- & trait_def. generics , self . def_id , & [ ] )
1277
+ parameterized ( tcx, & path_str, self . substs , self . def_id , & [ ] ,
1278
+ || ty:: lookup_trait_def ( tcx, self . def_id ) . generics . clone ( ) )
1255
1279
}
1256
1280
}
1257
1281
0 commit comments