@@ -69,15 +69,12 @@ pub enum Ns {
69
69
Value
70
70
}
71
71
72
- fn number_of_supplied_defaults < ' a , ' gcx , ' tcx , GG > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
73
- substs : & subst:: Substs ,
74
- space : subst:: ParamSpace ,
75
- get_generics : GG )
76
- -> usize
77
- where GG : FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> ty:: Generics < ' tcx >
72
+ fn number_of_supplied_defaults < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
73
+ substs : & subst:: Substs ,
74
+ space : subst:: ParamSpace ,
75
+ generics : ty:: Generics < ' tcx > )
76
+ -> usize
78
77
{
79
- let generics = get_generics ( tcx) ;
80
-
81
78
let has_self = substs. self_ty ( ) . is_some ( ) ;
82
79
let ty_params = generics. types . get_slice ( space) ;
83
80
let tps = substs. types . get_slice ( space) ;
@@ -115,7 +112,8 @@ pub fn parameterized<GG>(f: &mut fmt::Formatter,
115
112
projections : & [ ty:: ProjectionPredicate ] ,
116
113
get_generics : GG )
117
114
-> fmt:: Result
118
- where GG : for <' a , ' gcx , ' tcx > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> ty:: Generics < ' tcx >
115
+ where GG : for <' a , ' gcx , ' tcx > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > )
116
+ -> Option < ty:: Generics < ' tcx > >
119
117
{
120
118
if let ( Ns :: Value , Some ( self_ty) ) = ( ns, substs. self_ty ( ) ) {
121
119
write ! ( f, "<{} as " , self_ty) ?;
@@ -176,13 +174,12 @@ pub fn parameterized<GG>(f: &mut fmt::Formatter,
176
174
let num_supplied_defaults = if verbose {
177
175
0
178
176
} else {
179
- // It is important to execute this conditionally, only if -Z
180
- // verbose is false. Otherwise, debug logs can sometimes cause
181
- // ICEs trying to fetch the generics early in the pipeline. This
182
- // is kind of a hacky workaround in that -Z verbose is required to
183
- // avoid those ICEs.
184
177
ty:: tls:: with ( |tcx| {
185
- number_of_supplied_defaults ( tcx, substs, subst:: TypeSpace , get_generics)
178
+ if let Some ( generics) = get_generics ( tcx) {
179
+ number_of_supplied_defaults ( tcx, substs, subst:: TypeSpace , generics)
180
+ } else {
181
+ 0
182
+ }
186
183
} )
187
184
} ;
188
185
@@ -310,7 +307,7 @@ impl<'tcx> fmt::Display for TraitAndProjections<'tcx> {
310
307
trait_ref. def_id ,
311
308
Ns :: Type ,
312
309
projection_bounds,
313
- |tcx| tcx. lookup_trait_def ( trait_ref. def_id ) . generics . clone ( ) )
310
+ |tcx| Some ( tcx. lookup_trait_def ( trait_ref. def_id ) . generics . clone ( ) ) )
314
311
}
315
312
}
316
313
@@ -811,7 +808,7 @@ impl fmt::Display for ty::Binder<ty::OutlivesPredicate<ty::Region, ty::Region>>
811
808
impl < ' tcx > fmt:: Display for ty:: TraitRef < ' tcx > {
812
809
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
813
810
parameterized ( f, self . substs , self . def_id , Ns :: Type , & [ ] ,
814
- |tcx| tcx. lookup_trait_def ( self . def_id ) . generics . clone ( ) )
811
+ |tcx| Some ( tcx. lookup_trait_def ( self . def_id ) . generics . clone ( ) ) )
815
812
}
816
813
}
817
814
@@ -863,8 +860,9 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
863
860
}
864
861
865
862
write ! ( f, "{} {{" , bare_fn. sig. 0 ) ?;
866
- parameterized ( f, substs, def_id, Ns :: Value , & [ ] ,
867
- |tcx| tcx. lookup_item_type ( def_id) . generics ) ?;
863
+ parameterized (
864
+ f, substs, def_id, Ns :: Value , & [ ] ,
865
+ |tcx| tcx. opt_lookup_item_type ( def_id) . map ( |t| t. generics ) ) ?;
868
866
write ! ( f, "}}" )
869
867
}
870
868
TyFnPtr ( ref bare_fn) => {
@@ -887,8 +885,12 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
887
885
!tcx. tcache . borrow ( ) . contains_key ( & def. did ) {
888
886
write ! ( f, "{}<..>" , tcx. item_path_str( def. did) )
889
887
} else {
890
- parameterized ( f, substs, def. did , Ns :: Type , & [ ] ,
891
- |tcx| tcx. lookup_item_type ( def. did ) . generics )
888
+ parameterized (
889
+ f, substs, def. did , Ns :: Type , & [ ] ,
890
+ |tcx| {
891
+ tcx. opt_lookup_item_type ( def. did ) .
892
+ map ( |t| t. generics )
893
+ } )
892
894
}
893
895
} )
894
896
}
0 commit comments