@@ -388,14 +388,35 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
388388 let trait_ = lifted. trait_ref ( cx. tcx ) . clean ( cx) ;
389389 let self_type = self . self_ty ( ) . clean ( cx) ;
390390 Type :: QPath {
391- name : cx . tcx . associated_item ( self . item_def_id ) . name ,
391+ assoc : Box :: new ( projection_to_path_segment ( * self , cx ) ) ,
392392 self_def_id : self_type. def_id ( & cx. cache ) ,
393393 self_type : box self_type,
394394 trait_,
395395 }
396396 }
397397}
398398
399+ fn projection_to_path_segment ( ty : ty:: ProjectionTy < ' _ > , cx : & mut DocContext < ' _ > ) -> PathSegment {
400+ let item = cx. tcx . associated_item ( ty. item_def_id ) ;
401+ let generics = cx. tcx . generics_of ( ty. item_def_id ) ;
402+ PathSegment {
403+ name : item. name ,
404+ args : GenericArgs :: AngleBracketed {
405+ args : ty. substs [ generics. parent_count ..]
406+ . iter ( )
407+ . map ( |ty| match ty. unpack ( ) {
408+ ty:: subst:: GenericArgKind :: Lifetime ( lt) => {
409+ GenericArg :: Lifetime ( lt. clean ( cx) . unwrap ( ) )
410+ }
411+ ty:: subst:: GenericArgKind :: Type ( ty) => GenericArg :: Type ( ty. clean ( cx) ) ,
412+ ty:: subst:: GenericArgKind :: Const ( c) => GenericArg :: Const ( Box :: new ( c. clean ( cx) ) ) ,
413+ } )
414+ . collect ( ) ,
415+ bindings : Default :: default ( ) ,
416+ } ,
417+ }
418+ }
419+
399420impl Clean < GenericParamDef > for ty:: GenericParamDef {
400421 fn clean ( & self , cx : & mut DocContext < ' _ > ) -> GenericParamDef {
401422 let ( name, kind) = match self . kind {
@@ -601,8 +622,8 @@ fn clean_ty_generics(
601622 } )
602623 . collect :: < Vec < GenericParamDef > > ( ) ;
603624
604- // param index -> [(DefId of trait, associated type name, type)]
605- let mut impl_trait_proj = FxHashMap :: < u32 , Vec < ( DefId , Symbol , Ty < ' _ > ) > > :: default ( ) ;
625+ // param index -> [(DefId of trait, associated type name and generics , type)]
626+ let mut impl_trait_proj = FxHashMap :: < u32 , Vec < ( DefId , PathSegment , Ty < ' _ > ) > > :: default ( ) ;
606627
607628 let where_predicates = preds
608629 . predicates
@@ -648,8 +669,9 @@ fn clean_ty_generics(
648669
649670 let proj = projection
650671 . map ( |p| ( p. skip_binder ( ) . projection_ty . clean ( cx) , p. skip_binder ( ) . term ) ) ;
651- if let Some ( ( ( _, trait_did, name) , rhs) ) =
652- proj. as_ref ( ) . and_then ( |( lhs, rhs) | Some ( ( lhs. projection ( ) ?, rhs) ) )
672+ if let Some ( ( ( _, trait_did, name) , rhs) ) = proj
673+ . as_ref ( )
674+ . and_then ( |( lhs, rhs) : & ( Type , _ ) | Some ( ( lhs. projection ( ) ?, rhs) ) )
653675 {
654676 // FIXME(...): Remove this unwrap()
655677 impl_trait_proj. entry ( param_idx) . or_default ( ) . push ( (
@@ -985,7 +1007,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
9851007 TyMethodItem ( t)
9861008 }
9871009 hir:: TraitItemKind :: Type ( bounds, ref default) => {
988- let generics = self . generics . clean ( cx) ;
1010+ let generics = enter_impl_trait ( cx , |cx| self . generics . clean ( cx) ) ;
9891011 let bounds = bounds. iter ( ) . filter_map ( |x| x. clean ( cx) ) . collect ( ) ;
9901012 let default = default. map ( |t| t. clean ( cx) ) ;
9911013 AssocTypeItem ( Box :: new ( generics) , bounds, default)
@@ -1136,6 +1158,27 @@ impl Clean<Item> for ty::AssocItem {
11361158 ty:: AssocKind :: Type => {
11371159 let my_name = self . name ;
11381160
1161+ fn param_eq_arg ( param : & GenericParamDef , arg : & GenericArg ) -> bool {
1162+ match ( & param. kind , arg) {
1163+ ( GenericParamDefKind :: Type { .. } , GenericArg :: Type ( Type :: Generic ( ty) ) )
1164+ if * ty == param. name =>
1165+ {
1166+ true
1167+ }
1168+ (
1169+ GenericParamDefKind :: Lifetime { .. } ,
1170+ GenericArg :: Lifetime ( Lifetime ( lt) ) ,
1171+ ) if * lt == param. name => true ,
1172+ ( GenericParamDefKind :: Const { .. } , GenericArg :: Const ( c) ) => {
1173+ match & c. kind {
1174+ ConstantKind :: TyConst { expr } => expr == param. name . as_str ( ) ,
1175+ _ => false ,
1176+ }
1177+ }
1178+ _ => false ,
1179+ }
1180+ }
1181+
11391182 if let ty:: TraitContainer ( _) = self . container {
11401183 let bounds = tcx. explicit_item_bounds ( self . def_id ) ;
11411184 let predicates = ty:: GenericPredicates { parent : None , predicates : bounds } ;
@@ -1147,10 +1190,10 @@ impl Clean<Item> for ty::AssocItem {
11471190 . where_predicates
11481191 . drain_filter ( |pred| match * pred {
11491192 WherePredicate :: BoundPredicate {
1150- ty : QPath { name , ref self_type, ref trait_, .. } ,
1193+ ty : QPath { ref assoc , ref self_type, ref trait_, .. } ,
11511194 ..
11521195 } => {
1153- if name != my_name {
1196+ if assoc . name != my_name {
11541197 return false ;
11551198 }
11561199 if trait_. def_id ( ) != self . container . id ( ) {
@@ -1267,7 +1310,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
12671310 } ;
12681311 register_res ( cx, trait_. res ) ;
12691312 Type :: QPath {
1270- name : p. segments . last ( ) . expect ( "segments were empty" ) . ident . name ,
1313+ assoc : Box :: new ( p. segments . last ( ) . expect ( "segments were empty" ) . clean ( cx ) ) ,
12711314 self_def_id : Some ( DefId :: local ( qself. hir_id . owner . local_def_index ) ) ,
12721315 self_type : box qself. clean ( cx) ,
12731316 trait_,
@@ -1284,7 +1327,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
12841327 let trait_ = hir:: Path { span, res, segments : & [ ] } . clean ( cx) ;
12851328 register_res ( cx, trait_. res ) ;
12861329 Type :: QPath {
1287- name : segment. ident . name ,
1330+ assoc : Box :: new ( segment. clean ( cx ) ) ,
12881331 self_def_id : res. opt_def_id ( ) ,
12891332 self_type : box qself. clean ( cx) ,
12901333 trait_,
@@ -1557,7 +1600,16 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
15571600 let mut bindings = vec ! [ ] ;
15581601 for pb in obj. projection_bounds ( ) {
15591602 bindings. push ( TypeBinding {
1560- name : cx. tcx . associated_item ( pb. item_def_id ( ) ) . name ,
1603+ assoc : projection_to_path_segment (
1604+ pb. skip_binder ( )
1605+ . lift_to_tcx ( cx. tcx )
1606+ . unwrap ( )
1607+ // HACK(compiler-errors): Doesn't actually matter what self
1608+ // type we put here, because we're only using the GAT's substs.
1609+ . with_self_ty ( cx. tcx , cx. tcx . types . self_param )
1610+ . projection_ty ,
1611+ cx,
1612+ ) ,
15611613 kind : TypeBindingKind :: Equality { term : pb. skip_binder ( ) . term . clean ( cx) } ,
15621614 } ) ;
15631615 }
@@ -1623,10 +1675,10 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
16231675 == trait_ref. skip_binder ( )
16241676 {
16251677 Some ( TypeBinding {
1626- name : cx
1627- . tcx
1628- . associated_item ( proj . projection_ty . item_def_id )
1629- . name ,
1678+ assoc : projection_to_path_segment (
1679+ proj . projection_ty ,
1680+ cx ,
1681+ ) ,
16301682 kind : TypeBindingKind :: Equality {
16311683 term : proj. term . clean ( cx) ,
16321684 } ,
@@ -2169,7 +2221,10 @@ fn clean_maybe_renamed_foreign_item(
21692221
21702222impl Clean < TypeBinding > for hir:: TypeBinding < ' _ > {
21712223 fn clean ( & self , cx : & mut DocContext < ' _ > ) -> TypeBinding {
2172- TypeBinding { name : self . ident . name , kind : self . kind . clean ( cx) }
2224+ TypeBinding {
2225+ assoc : PathSegment { name : self . ident . name , args : self . gen_args . clean ( cx) } ,
2226+ kind : self . kind . clean ( cx) ,
2227+ }
21732228 }
21742229}
21752230
0 commit comments