@@ -5,7 +5,7 @@ use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
55use  rustc_hir:: definitions:: DefPathData ; 
66use  rustc_hir:: intravisit:: { self ,  Visitor } ; 
77use  rustc_middle:: ty:: { self ,  ImplTraitInTraitData ,  InternalSubsts ,  TyCtxt } ; 
8- use  rustc_span:: symbol :: kw ; 
8+ use  rustc_span:: Symbol ; 
99
1010pub  fn  provide ( providers :  & mut  ty:: query:: Providers )  { 
1111    * providers = ty:: query:: Providers  { 
@@ -266,7 +266,8 @@ fn associated_type_for_impl_trait_in_trait(
266266    assert_eq ! ( tcx. def_kind( trait_def_id) ,  DefKind :: Trait ) ; 
267267
268268    let  span = tcx. def_span ( opaque_ty_def_id) ; 
269-     let  trait_assoc_ty = tcx. at ( span) . create_def ( trait_def_id,  DefPathData :: ImplTraitAssocTy ) ; 
269+     let  name = name_for_impl_trait_in_trait ( tcx,  opaque_ty_def_id,  trait_def_id) ; 
270+     let  trait_assoc_ty = tcx. at ( span) . create_def ( trait_def_id,  DefPathData :: ImplTraitAssocTy ( name) ) ; 
270271
271272    let  local_def_id = trait_assoc_ty. def_id ( ) ; 
272273    let  def_id = local_def_id. to_def_id ( ) ; 
@@ -281,7 +282,7 @@ fn associated_type_for_impl_trait_in_trait(
281282    trait_assoc_ty. def_ident_span ( Some ( span) ) ; 
282283
283284    trait_assoc_ty. associated_item ( ty:: AssocItem  { 
284-         name :  kw :: Empty , 
285+         name, 
285286        kind :  ty:: AssocKind :: Type , 
286287        def_id, 
287288        trait_item_def_id :  None , 
@@ -351,6 +352,24 @@ fn associated_type_for_impl_trait_in_trait(
351352    local_def_id
352353} 
353354
355+ /// Create a stable path name for an associated type for an impl trait in trait 
356+ /// by appending the opaque type's path segments starting from the function name. 
357+ fn  name_for_impl_trait_in_trait ( 
358+     tcx :  TyCtxt < ' _ > , 
359+     opaque_ty_def_id :  LocalDefId , 
360+     trait_def_id :  LocalDefId , 
361+ )  -> Symbol  { 
362+     let  mut  name = vec ! [ ] ; 
363+     let  mut  def_id = opaque_ty_def_id; 
364+     while  def_id != trait_def_id { 
365+         name. push ( tcx. def_key ( def_id. to_def_id ( ) ) . disambiguated_data . to_string ( ) ) ; 
366+         def_id = tcx. local_parent ( def_id) ; 
367+     } 
368+     name. reverse ( ) ; 
369+     let  name = Symbol :: intern ( & name. join ( "::" ) ) ; 
370+     name
371+ } 
372+ 
354373/// Given an `trait_assoc_def_id` corresponding to an associated item synthesized 
355374/// from an `impl Trait` in an associated function from a trait, and an 
356375/// `impl_fn_def_id` that represents an implementation of the associated function 
@@ -364,9 +383,11 @@ fn associated_type_for_impl_trait_in_impl(
364383    let  impl_local_def_id = tcx. local_parent ( impl_fn_def_id) ; 
365384    let  impl_def_id = impl_local_def_id. to_def_id ( ) ; 
366385
386+     let  name = tcx. item_name ( trait_assoc_def_id) ; 
367387    // FIXME fix the span, we probably want the def_id of the return type of the function 
368388    let  span = tcx. def_span ( impl_fn_def_id) ; 
369-     let  impl_assoc_ty = tcx. at ( span) . create_def ( impl_local_def_id,  DefPathData :: ImplTraitAssocTy ) ; 
389+     let  impl_assoc_ty =
390+         tcx. at ( span) . create_def ( impl_local_def_id,  DefPathData :: ImplTraitAssocTy ( name) ) ; 
370391
371392    let  local_def_id = impl_assoc_ty. def_id ( ) ; 
372393    let  def_id = local_def_id. to_def_id ( ) ; 
@@ -381,7 +402,7 @@ fn associated_type_for_impl_trait_in_impl(
381402    impl_assoc_ty. def_ident_span ( Some ( span) ) ; 
382403
383404    impl_assoc_ty. associated_item ( ty:: AssocItem  { 
384-         name :  kw :: Empty , 
405+         name, 
385406        kind :  ty:: AssocKind :: Type , 
386407        def_id, 
387408        trait_item_def_id :  Some ( trait_assoc_def_id) , 
0 commit comments