@@ -67,9 +67,13 @@ pub(crate) fn try_inline(
67
67
record_extern_fqn ( cx, did, ItemType :: Trait ) ;
68
68
cx. with_param_env ( did, |cx| {
69
69
build_impls ( cx, did, attrs_without_docs, & mut ret) ;
70
- clean:: TraitItem ( Box :: new ( build_external_trait ( cx, did) ) )
70
+ clean:: TraitItem ( Box :: new ( build_trait ( cx, did) ) )
71
71
} )
72
72
}
73
+ Res :: Def ( DefKind :: TraitAlias , did) => {
74
+ record_extern_fqn ( cx, did, ItemType :: TraitAlias ) ;
75
+ cx. with_param_env ( did, |cx| clean:: TraitAliasItem ( build_trait_alias ( cx, did) ) )
76
+ }
73
77
Res :: Def ( DefKind :: Fn , did) => {
74
78
record_extern_fqn ( cx, did, ItemType :: Function ) ;
75
79
cx. with_param_env ( did, |cx| {
@@ -251,7 +255,7 @@ pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemT
251
255
}
252
256
}
253
257
254
- pub ( crate ) fn build_external_trait ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Trait {
258
+ pub ( crate ) fn build_trait ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Trait {
255
259
let trait_items = cx
256
260
. tcx
257
261
. associated_items ( did)
@@ -263,11 +267,18 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
263
267
let predicates = cx. tcx . predicates_of ( did) ;
264
268
let generics = clean_ty_generics ( cx, cx. tcx . generics_of ( did) , predicates) ;
265
269
let generics = filter_non_trait_generics ( did, generics) ;
266
- let ( generics, supertrait_bounds) = separate_supertrait_bounds ( generics) ;
270
+ let ( generics, supertrait_bounds) = separate_self_bounds ( generics) ;
267
271
clean:: Trait { def_id : did, generics, items : trait_items, bounds : supertrait_bounds }
268
272
}
269
273
270
- pub ( crate ) fn build_function ( cx : & mut DocContext < ' _ > , def_id : DefId ) -> Box < clean:: Function > {
274
+ fn build_trait_alias ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: TraitAlias {
275
+ let predicates = cx. tcx . predicates_of ( did) ;
276
+ let generics = clean_ty_generics ( cx, cx. tcx . generics_of ( did) , predicates) ;
277
+ let ( generics, bounds) = separate_self_bounds ( generics) ;
278
+ clean:: TraitAlias { generics, bounds }
279
+ }
280
+
281
+ pub ( super ) fn build_function ( cx : & mut DocContext < ' _ > , def_id : DefId ) -> Box < clean:: Function > {
271
282
let sig = cx. tcx . fn_sig ( def_id) . instantiate_identity ( ) ;
272
283
// The generics need to be cleaned before the signature.
273
284
let mut generics =
@@ -788,12 +799,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean:
788
799
g
789
800
}
790
801
791
- /// Supertrait bounds for a trait are also listed in the generics coming from
792
- /// the metadata for a crate, so we want to separate those out and create a new
793
- /// list of explicit supertrait bounds to render nicely.
794
- fn separate_supertrait_bounds (
795
- mut g : clean:: Generics ,
796
- ) -> ( clean:: Generics , Vec < clean:: GenericBound > ) {
802
+ fn separate_self_bounds ( mut g : clean:: Generics ) -> ( clean:: Generics , Vec < clean:: GenericBound > ) {
797
803
let mut ty_bounds = Vec :: new ( ) ;
798
804
g. where_predicates . retain ( |pred| match * pred {
799
805
clean:: WherePredicate :: BoundPredicate { ty : clean:: SelfTy , ref bounds, .. } => {
@@ -806,22 +812,17 @@ fn separate_supertrait_bounds(
806
812
}
807
813
808
814
pub ( crate ) fn record_extern_trait ( cx : & mut DocContext < ' _ > , did : DefId ) {
809
- if did. is_local ( ) {
810
- return ;
811
- }
812
-
815
+ if did. is_local ( )
816
+ || cx. external_traits . contains_key ( & did)
817
+ || cx. active_extern_traits . contains ( & did)
813
818
{
814
- if cx. external_traits . contains_key ( & did) || cx. active_extern_traits . contains ( & did) {
815
- return ;
816
- }
819
+ return ;
817
820
}
818
821
819
- {
820
- cx. active_extern_traits . insert ( did) ;
821
- }
822
+ cx. active_extern_traits . insert ( did) ;
822
823
823
824
debug ! ( "record_extern_trait: {did:?}" ) ;
824
- let trait_ = build_external_trait ( cx, did) ;
825
+ let trait_ = build_trait ( cx, did) ;
825
826
826
827
cx. external_traits . insert ( did, trait_) ;
827
828
cx. active_extern_traits . remove ( & did) ;
0 commit comments