@@ -55,13 +55,15 @@ use rustc_hir::def_id::{DefId, DefIdSet};
5555use rustc_hir:: Mutability ;
5656use rustc_middle:: middle:: stability;
5757use rustc_middle:: ty:: { self , TyCtxt } ;
58+ use rustc_middle:: ty:: fast_reject:: { DeepRejectCtxt , TreatParams } ;
5859use rustc_span:: {
5960 symbol:: { sym, Symbol } ,
6061 BytePos , FileName , RealFileName ,
6162} ;
6263use serde:: ser:: { SerializeMap , SerializeSeq } ;
6364use serde:: { Serialize , Serializer } ;
6465
66+ use crate :: clean:: types:: TypeAliasItem ;
6567use crate :: clean:: { self , ItemId , RenderedLink , SelfTy } ;
6668use crate :: error:: Error ;
6769use crate :: formats:: cache:: Cache ;
@@ -1132,13 +1134,13 @@ pub(crate) fn render_all_impls(
11321134fn render_assoc_items < ' a , ' cx : ' a > (
11331135 cx : & ' a mut Context < ' cx > ,
11341136 containing_item : & ' a clean:: Item ,
1135- did : DefId ,
1137+ it : DefId ,
11361138 what : AssocItemRender < ' a > ,
11371139) -> impl fmt:: Display + ' a + Captures < ' cx > {
11381140 let mut derefs = DefIdSet :: default ( ) ;
1139- derefs. insert ( did ) ;
1141+ derefs. insert ( it ) ;
11401142 display_fn ( move |f| {
1141- render_assoc_items_inner ( f, cx, containing_item, did , what, & mut derefs) ;
1143+ render_assoc_items_inner ( f, cx, containing_item, it , what, & mut derefs) ;
11421144 Ok ( ( ) )
11431145 } )
11441146}
@@ -1147,16 +1149,46 @@ fn render_assoc_items_inner(
11471149 mut w : & mut dyn fmt:: Write ,
11481150 cx : & mut Context < ' _ > ,
11491151 containing_item : & clean:: Item ,
1150- did : DefId ,
1152+ it : DefId ,
11511153 what : AssocItemRender < ' _ > ,
11521154 derefs : & mut DefIdSet ,
11531155) {
11541156 info ! ( "Documenting associated items of {:?}" , containing_item. name) ;
11551157 let shared = Rc :: clone ( & cx. shared ) ;
1156- let v = shared. all_impls_for_item ( containing_item, did) ;
1157- let v = v. as_slice ( ) ;
1158- let ( non_trait, traits) : ( Vec < & Impl > , _ ) =
1159- v. iter ( ) . partition ( |i| i. inner_impl ( ) . trait_ . is_none ( ) ) ;
1158+ let cache = & shared. cache ;
1159+ let tcx = cx. tcx ( ) ;
1160+ let av = if let TypeAliasItem ( ait) = & * containing_item. kind &&
1161+ let aliased_clean_type = ait. item_type . as_ref ( ) . unwrap_or ( & ait. type_ ) &&
1162+ let Some ( aliased_type_defid) = aliased_clean_type. def_id ( cache) &&
1163+ let Some ( mut av) = cache. impls . get ( & aliased_type_defid) . cloned ( ) &&
1164+ let Some ( alias_def_id) = containing_item. item_id . as_def_id ( )
1165+ {
1166+ // This branch of the compiler compares types structually, but does
1167+ // not check trait bounds. That's probably fine, since type aliases
1168+ // don't normally constrain on them anyway.
1169+ // https://github.com/rust-lang/rust/issues/21903
1170+ //
1171+ // FIXME(lazy_type_alias): Once the feature is complete or stable, rewrite this to use type unification.
1172+ // Be aware of `tests/rustdoc/issue-112515-impl-ty-alias.rs` which might regress.
1173+ let aliased_ty = tcx. type_of ( alias_def_id) . skip_binder ( ) ;
1174+ let reject_cx = DeepRejectCtxt {
1175+ treat_obligation_params : TreatParams :: AsCandidateKey ,
1176+ } ;
1177+ av. retain ( |impl_| {
1178+ if let Some ( impl_def_id) = impl_. impl_item . item_id . as_def_id ( ) {
1179+ reject_cx. types_may_unify ( aliased_ty, tcx. type_of ( impl_def_id) . skip_binder ( ) )
1180+ } else {
1181+ false
1182+ }
1183+ } ) ;
1184+ av
1185+ } else {
1186+ Vec :: new ( )
1187+ } ;
1188+ let blank = Vec :: new ( ) ;
1189+ let v = cache. impls . get ( & it) . unwrap_or ( & blank) ;
1190+ let ( non_trait, traits) : ( Vec < _ > , _ ) =
1191+ v. iter ( ) . chain ( & av[ ..] ) . partition ( |i| i. inner_impl ( ) . trait_ . is_none ( ) ) ;
11601192 let mut saw_impls = FxHashSet :: default ( ) ;
11611193 if !non_trait. is_empty ( ) {
11621194 let mut tmp_buf = Buffer :: html ( ) ;
0 commit comments