@@ -55,13 +55,15 @@ use rustc_hir::def_id::{DefId, DefIdSet};
55
55
use rustc_hir:: Mutability ;
56
56
use rustc_middle:: middle:: stability;
57
57
use rustc_middle:: ty:: { self , TyCtxt } ;
58
+ use rustc_middle:: ty:: fast_reject:: { DeepRejectCtxt , TreatParams } ;
58
59
use rustc_span:: {
59
60
symbol:: { sym, Symbol } ,
60
61
BytePos , FileName , RealFileName ,
61
62
} ;
62
63
use serde:: ser:: { SerializeMap , SerializeSeq } ;
63
64
use serde:: { Serialize , Serializer } ;
64
65
66
+ use crate :: clean:: types:: TypeAliasItem ;
65
67
use crate :: clean:: { self , ItemId , RenderedLink , SelfTy } ;
66
68
use crate :: error:: Error ;
67
69
use crate :: formats:: cache:: Cache ;
@@ -1132,13 +1134,13 @@ pub(crate) fn render_all_impls(
1132
1134
fn render_assoc_items < ' a , ' cx : ' a > (
1133
1135
cx : & ' a mut Context < ' cx > ,
1134
1136
containing_item : & ' a clean:: Item ,
1135
- did : DefId ,
1137
+ it : DefId ,
1136
1138
what : AssocItemRender < ' a > ,
1137
1139
) -> impl fmt:: Display + ' a + Captures < ' cx > {
1138
1140
let mut derefs = DefIdSet :: default ( ) ;
1139
- derefs. insert ( did ) ;
1141
+ derefs. insert ( it ) ;
1140
1142
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) ;
1142
1144
Ok ( ( ) )
1143
1145
} )
1144
1146
}
@@ -1147,16 +1149,46 @@ fn render_assoc_items_inner(
1147
1149
mut w : & mut dyn fmt:: Write ,
1148
1150
cx : & mut Context < ' _ > ,
1149
1151
containing_item : & clean:: Item ,
1150
- did : DefId ,
1152
+ it : DefId ,
1151
1153
what : AssocItemRender < ' _ > ,
1152
1154
derefs : & mut DefIdSet ,
1153
1155
) {
1154
1156
info ! ( "Documenting associated items of {:?}" , containing_item. name) ;
1155
1157
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 ( ) ) ;
1160
1192
let mut saw_impls = FxHashSet :: default ( ) ;
1161
1193
if !non_trait. is_empty ( ) {
1162
1194
let mut tmp_buf = Buffer :: html ( ) ;
0 commit comments