@@ -14,8 +14,8 @@ use rustc_middle::bug;
14
14
use rustc_middle:: ty:: layout:: IntegerExt ;
15
15
use rustc_middle:: ty:: print:: { Print , PrintError , Printer } ;
16
16
use 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 ,
19
19
} ;
20
20
use rustc_span:: kw;
21
21
@@ -227,17 +227,29 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
227
227
& mut self ,
228
228
impl_def_id : DefId ,
229
229
args : & ' tcx [ GenericArg < ' tcx > ] ,
230
- mut self_ty : Ty < ' tcx > ,
231
- mut impl_trait_ref : Option < ty:: TraitRef < ' tcx > > ,
232
230
) -> Result < ( ) , PrintError > {
233
231
let key = self . tcx . def_key ( impl_def_id) ;
234
232
let parent_def_id = DefId { index : key. parent . unwrap ( ) , ..impl_def_id } ;
235
233
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
+ } ;
241
253
242
254
match & mut impl_trait_ref {
243
255
Some ( impl_trait_ref) => {
0 commit comments