@@ -69,15 +69,12 @@ pub enum Ns {
6969 Value
7070}
7171
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
7877{
79- let generics = get_generics ( tcx) ;
80-
8178 let has_self = substs. self_ty ( ) . is_some ( ) ;
8279 let ty_params = generics. types . get_slice ( space) ;
8380 let tps = substs. types . get_slice ( space) ;
@@ -115,7 +112,8 @@ pub fn parameterized<GG>(f: &mut fmt::Formatter,
115112 projections : & [ ty:: ProjectionPredicate ] ,
116113 get_generics : GG )
117114 -> 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 > >
119117{
120118 if let ( Ns :: Value , Some ( self_ty) ) = ( ns, substs. self_ty ( ) ) {
121119 write ! ( f, "<{} as " , self_ty) ?;
@@ -176,13 +174,12 @@ pub fn parameterized<GG>(f: &mut fmt::Formatter,
176174 let num_supplied_defaults = if verbose {
177175 0
178176 } 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.
184177 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+ }
186183 } )
187184 } ;
188185
@@ -310,7 +307,7 @@ impl<'tcx> fmt::Display for TraitAndProjections<'tcx> {
310307 trait_ref. def_id ,
311308 Ns :: Type ,
312309 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 ( ) ) )
314311 }
315312}
316313
@@ -811,7 +808,7 @@ impl fmt::Display for ty::Binder<ty::OutlivesPredicate<ty::Region, ty::Region>>
811808impl < ' tcx > fmt:: Display for ty:: TraitRef < ' tcx > {
812809 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
813810 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 ( ) ) )
815812 }
816813}
817814
@@ -863,8 +860,9 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
863860 }
864861
865862 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 ) ) ?;
868866 write ! ( f, "}}" )
869867 }
870868 TyFnPtr ( ref bare_fn) => {
@@ -887,8 +885,12 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
887885 !tcx. tcache . borrow ( ) . contains_key ( & def. did ) {
888886 write ! ( f, "{}<..>" , tcx. item_path_str( def. did) )
889887 } 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+ } )
892894 }
893895 } )
894896 }
0 commit comments