@@ -14,8 +14,8 @@ use rustc_middle::bug;
1414use rustc_middle:: ty:: layout:: IntegerExt ;
1515use rustc_middle:: ty:: print:: { Print , PrintError , Printer } ;
1616use rustc_middle:: ty:: {
17- self , EarlyBinder , FloatTy , GenericArg , GenericArgKind , Instance , IntTy , ReifyReason , Ty ,
18- TyCtxt , TypeVisitable , TypeVisitableExt , UintTy ,
17+ self , FloatTy , GenericArg , GenericArgKind , Instance , IntTy , ReifyReason , Ty , TyCtxt ,
18+ TypeVisitable , TypeVisitableExt , UintTy ,
1919} ;
2020use rustc_span:: kw;
2121
@@ -227,17 +227,29 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
227227 & mut self ,
228228 impl_def_id : DefId ,
229229 args : & ' tcx [ GenericArg < ' tcx > ] ,
230- mut self_ty : Ty < ' tcx > ,
231- mut impl_trait_ref : Option < ty:: TraitRef < ' tcx > > ,
232230 ) -> Result < ( ) , PrintError > {
233231 let key = self . tcx . def_key ( impl_def_id) ;
234232 let parent_def_id = DefId { index : key. parent . unwrap ( ) , ..impl_def_id } ;
235233
236- let mut typing_env = ty:: TypingEnv :: post_analysis ( self . tcx , impl_def_id) ;
237- if !args. is_empty ( ) {
238- typing_env. param_env =
239- EarlyBinder :: bind ( typing_env. param_env ) . instantiate ( self . tcx , args) ;
240- }
234+ let self_ty = self . tcx . type_of ( impl_def_id) ;
235+ let impl_trait_ref = self . tcx . impl_trait_ref ( impl_def_id) ;
236+ let ( typing_env, mut self_ty, mut impl_trait_ref) =
237+ if self . tcx . generics_of ( impl_def_id) . count ( ) <= args. len ( ) {
238+ (
239+ ty:: TypingEnv :: fully_monomorphized ( ) ,
240+ self_ty. instantiate ( self . tcx , args) ,
241+ impl_trait_ref. map ( |impl_trait_ref| impl_trait_ref. instantiate ( self . tcx , args) ) ,
242+ )
243+ } else {
244+ // We are probably printing a nested item inside of an impl.
245+ // Use the identity substitutions for the impl. We also need
246+ // a well-formed param-env, so let's use post-analysis.
247+ (
248+ ty:: TypingEnv :: post_analysis ( self . tcx , impl_def_id) ,
249+ self_ty. instantiate_identity ( ) ,
250+ impl_trait_ref. map ( |impl_trait_ref| impl_trait_ref. instantiate_identity ( ) ) ,
251+ )
252+ } ;
241253
242254 match & mut impl_trait_ref {
243255 Some ( impl_trait_ref) => {
0 commit comments