@@ -575,69 +575,68 @@ fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool {
575
575
matches ! ( param. kind, hir:: GenericParamKind :: Lifetime { kind: hir:: LifetimeParamKind :: Elided } )
576
576
}
577
577
578
- impl < ' tcx > Clean < ' tcx , Generics > for hir :: Generics < ' tcx > {
579
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Generics {
580
- let impl_trait_params = self
581
- . params
582
- . iter ( )
583
- . filter ( |param| is_impl_trait ( param ) )
584
- . map ( |param| {
585
- let param = clean_generic_param ( cx , Some ( self ) , param) ;
586
- match param . kind {
587
- GenericParamDefKind :: Lifetime { .. } => unreachable ! ( ) ,
588
- GenericParamDefKind :: Type { did , ref bounds , .. } => {
589
- cx . impl_trait_bounds . insert ( did . into ( ) , bounds . clone ( ) ) ;
590
- }
591
- GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
578
+ pub ( crate ) fn clean_generics < ' tcx > (
579
+ gens : & hir :: Generics < ' tcx > ,
580
+ cx : & mut DocContext < ' tcx > ,
581
+ ) -> Generics {
582
+ let impl_trait_params = gens
583
+ . params
584
+ . iter ( )
585
+ . filter ( | param| is_impl_trait ( param) )
586
+ . map ( |param| {
587
+ let param = clean_generic_param ( cx , Some ( gens ) , param ) ;
588
+ match param . kind {
589
+ GenericParamDefKind :: Lifetime { .. } => unreachable ! ( ) ,
590
+ GenericParamDefKind :: Type { did , ref bounds , .. } => {
591
+ cx . impl_trait_bounds . insert ( did . into ( ) , bounds . clone ( ) ) ;
592
592
}
593
- param
594
- } )
595
- . collect :: < Vec < _ > > ( ) ;
593
+ GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
594
+ }
595
+ param
596
+ } )
597
+ . collect :: < Vec < _ > > ( ) ;
596
598
597
- let mut params = Vec :: with_capacity ( self . params . len ( ) ) ;
598
- for p in self . params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
599
- let p = clean_generic_param ( cx, Some ( self ) , p) ;
600
- params. push ( p) ;
601
- }
602
- params. extend ( impl_trait_params) ;
599
+ let mut params = Vec :: with_capacity ( gens . params . len ( ) ) ;
600
+ for p in gens . params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
601
+ let p = clean_generic_param ( cx, Some ( gens ) , p) ;
602
+ params. push ( p) ;
603
+ }
604
+ params. extend ( impl_trait_params) ;
603
605
604
- let mut generics = Generics {
605
- params,
606
- where_predicates : self
607
- . predicates
608
- . iter ( )
609
- . filter_map ( |x| clean_where_predicate ( x, cx) )
610
- . collect ( ) ,
611
- } ;
606
+ let mut generics = Generics {
607
+ params,
608
+ where_predicates : gens
609
+ . predicates
610
+ . iter ( )
611
+ . filter_map ( |x| clean_where_predicate ( x, cx) )
612
+ . collect ( ) ,
613
+ } ;
612
614
613
- // Some duplicates are generated for ?Sized bounds between type params and where
614
- // predicates. The point in here is to move the bounds definitions from type params
615
- // to where predicates when such cases occur.
616
- for where_pred in & mut generics. where_predicates {
617
- match * where_pred {
618
- WherePredicate :: BoundPredicate {
619
- ty : Generic ( ref name) , ref mut bounds, ..
620
- } => {
621
- if bounds. is_empty ( ) {
622
- for param in & mut generics. params {
623
- match param. kind {
624
- GenericParamDefKind :: Lifetime { .. } => { }
625
- GenericParamDefKind :: Type { bounds : ref mut ty_bounds, .. } => {
626
- if & param. name == name {
627
- mem:: swap ( bounds, ty_bounds) ;
628
- break ;
629
- }
615
+ // Some duplicates are generated for ?Sized bounds between type params and where
616
+ // predicates. The point in here is to move the bounds definitions from type params
617
+ // to where predicates when such cases occur.
618
+ for where_pred in & mut generics. where_predicates {
619
+ match * where_pred {
620
+ WherePredicate :: BoundPredicate { ty : Generic ( ref name) , ref mut bounds, .. } => {
621
+ if bounds. is_empty ( ) {
622
+ for param in & mut generics. params {
623
+ match param. kind {
624
+ GenericParamDefKind :: Lifetime { .. } => { }
625
+ GenericParamDefKind :: Type { bounds : ref mut ty_bounds, .. } => {
626
+ if & param. name == name {
627
+ mem:: swap ( bounds, ty_bounds) ;
628
+ break ;
630
629
}
631
- GenericParamDefKind :: Const { .. } => { }
632
630
}
631
+ GenericParamDefKind :: Const { .. } => { }
633
632
}
634
633
}
635
634
}
636
- _ => continue ,
637
635
}
636
+ _ => continue ,
638
637
}
639
- generics
640
638
}
639
+ generics
641
640
}
642
641
643
642
fn clean_ty_generics < ' tcx > (
@@ -903,7 +902,7 @@ fn clean_function<'tcx>(
903
902
) -> Box < Function > {
904
903
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
905
904
// NOTE: generics must be cleaned before args
906
- let generics = generics . clean ( cx) ;
905
+ let generics = clean_generics ( generics , cx) ;
907
906
let args = clean_args_from_types_and_body_id ( cx, sig. decl . inputs , body_id) ;
908
907
let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
909
908
( generics, decl)
@@ -1032,15 +1031,15 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1032
1031
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( names) ) => {
1033
1032
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
1034
1033
// NOTE: generics must be cleaned before args
1035
- let generics = trait_item. generics . clean ( cx) ;
1034
+ let generics = clean_generics ( trait_item. generics , cx) ;
1036
1035
let args = clean_args_from_types_and_names ( cx, sig. decl . inputs , names) ;
1037
1036
let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
1038
1037
( generics, decl)
1039
1038
} ) ;
1040
1039
TyMethodItem ( Box :: new ( Function { decl, generics } ) )
1041
1040
}
1042
1041
hir:: TraitItemKind :: Type ( bounds, Some ( default) ) => {
1043
- let generics = enter_impl_trait ( cx, |cx| trait_item. generics . clean ( cx) ) ;
1042
+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
1044
1043
let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1045
1044
let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , default) , cx, None ) ;
1046
1045
AssocTypeItem (
@@ -1053,7 +1052,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1053
1052
)
1054
1053
}
1055
1054
hir:: TraitItemKind :: Type ( bounds, None ) => {
1056
- let generics = enter_impl_trait ( cx, |cx| trait_item. generics . clean ( cx) ) ;
1055
+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
1057
1056
let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1058
1057
TyAssocTypeItem ( Box :: new ( generics) , bounds)
1059
1058
}
@@ -1083,7 +1082,7 @@ pub(crate) fn clean_impl_item<'tcx>(
1083
1082
}
1084
1083
hir:: ImplItemKind :: TyAlias ( hir_ty) => {
1085
1084
let type_ = clean_ty ( hir_ty, cx) ;
1086
- let generics = impl_. generics . clean ( cx) ;
1085
+ let generics = clean_generics ( impl_. generics , cx) ;
1087
1086
let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
1088
1087
AssocTypeItem (
1089
1088
Box :: new ( Typedef { type_, generics, item_type : Some ( item_type) } ) ,
@@ -1913,32 +1912,32 @@ fn clean_maybe_renamed_item<'tcx>(
1913
1912
} ) ,
1914
1913
ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
1915
1914
bounds : ty. bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1916
- generics : ty. generics . clean ( cx) ,
1915
+ generics : clean_generics ( ty. generics , cx) ,
1917
1916
} ) ,
1918
1917
ItemKind :: TyAlias ( hir_ty, generics) => {
1919
1918
let rustdoc_ty = clean_ty ( hir_ty, cx) ;
1920
1919
let ty = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
1921
1920
TypedefItem ( Box :: new ( Typedef {
1922
1921
type_ : rustdoc_ty,
1923
- generics : generics . clean ( cx) ,
1922
+ generics : clean_generics ( generics , cx) ,
1924
1923
item_type : Some ( ty) ,
1925
1924
} ) )
1926
1925
}
1927
1926
ItemKind :: Enum ( ref def, generics) => EnumItem ( Enum {
1928
1927
variants : def. variants . iter ( ) . map ( |v| v. clean ( cx) ) . collect ( ) ,
1929
- generics : generics . clean ( cx) ,
1928
+ generics : clean_generics ( generics , cx) ,
1930
1929
} ) ,
1931
1930
ItemKind :: TraitAlias ( generics, bounds) => TraitAliasItem ( TraitAlias {
1932
- generics : generics . clean ( cx) ,
1931
+ generics : clean_generics ( generics , cx) ,
1933
1932
bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1934
1933
} ) ,
1935
1934
ItemKind :: Union ( ref variant_data, generics) => UnionItem ( Union {
1936
- generics : generics . clean ( cx) ,
1935
+ generics : clean_generics ( generics , cx) ,
1937
1936
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
1938
1937
} ) ,
1939
1938
ItemKind :: Struct ( ref variant_data, generics) => StructItem ( Struct {
1940
1939
struct_type : CtorKind :: from_hir ( variant_data) ,
1941
- generics : generics . clean ( cx) ,
1940
+ generics : clean_generics ( generics , cx) ,
1942
1941
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
1943
1942
} ) ,
1944
1943
ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. hir_id ( ) , cx) ,
@@ -1961,7 +1960,7 @@ fn clean_maybe_renamed_item<'tcx>(
1961
1960
TraitItem ( Trait {
1962
1961
def_id,
1963
1962
items,
1964
- generics : generics . clean ( cx) ,
1963
+ generics : clean_generics ( generics , cx) ,
1965
1964
bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1966
1965
} )
1967
1966
}
@@ -2017,7 +2016,7 @@ fn clean_impl<'tcx>(
2017
2016
let mut make_item = |trait_ : Option < Path > , for_ : Type , items : Vec < Item > | {
2018
2017
let kind = ImplItem ( Box :: new ( Impl {
2019
2018
unsafety : impl_. unsafety ,
2020
- generics : impl_. generics . clean ( cx) ,
2019
+ generics : clean_generics ( impl_. generics , cx) ,
2021
2020
trait_,
2022
2021
for_,
2023
2022
items,
@@ -2212,7 +2211,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
2212
2211
hir:: ForeignItemKind :: Fn ( decl, names, generics) => {
2213
2212
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
2214
2213
// NOTE: generics must be cleaned before args
2215
- let generics = generics . clean ( cx) ;
2214
+ let generics = clean_generics ( generics , cx) ;
2216
2215
let args = clean_args_from_types_and_names ( cx, decl. inputs , names) ;
2217
2216
let decl = clean_fn_decl_with_args ( cx, decl, args) ;
2218
2217
( generics, decl)
0 commit comments