@@ -575,69 +575,68 @@ fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool {
575575 matches ! ( param. kind, hir:: GenericParamKind :: Lifetime { kind: hir:: LifetimeParamKind :: Elided } )
576576}
577577
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 ( ) ) ;
592592 }
593- param
594- } )
595- . collect :: < Vec < _ > > ( ) ;
593+ GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
594+ }
595+ param
596+ } )
597+ . collect :: < Vec < _ > > ( ) ;
596598
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) ;
603605
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+ } ;
612614
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 ;
630629 }
631- GenericParamDefKind :: Const { .. } => { }
632630 }
631+ GenericParamDefKind :: Const { .. } => { }
633632 }
634633 }
635634 }
636- _ => continue ,
637635 }
636+ _ => continue ,
638637 }
639- generics
640638 }
639+ generics
641640}
642641
643642fn clean_ty_generics < ' tcx > (
@@ -903,7 +902,7 @@ fn clean_function<'tcx>(
903902) -> Box < Function > {
904903 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
905904 // NOTE: generics must be cleaned before args
906- let generics = generics . clean ( cx) ;
905+ let generics = clean_generics ( generics , cx) ;
907906 let args = clean_args_from_types_and_body_id ( cx, sig. decl . inputs , body_id) ;
908907 let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
909908 ( generics, decl)
@@ -1032,15 +1031,15 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10321031 hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( names) ) => {
10331032 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
10341033 // NOTE: generics must be cleaned before args
1035- let generics = trait_item. generics . clean ( cx) ;
1034+ let generics = clean_generics ( trait_item. generics , cx) ;
10361035 let args = clean_args_from_types_and_names ( cx, sig. decl . inputs , names) ;
10371036 let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
10381037 ( generics, decl)
10391038 } ) ;
10401039 TyMethodItem ( Box :: new ( Function { decl, generics } ) )
10411040 }
10421041 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) ) ;
10441043 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
10451044 let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , default) , cx, None ) ;
10461045 AssocTypeItem (
@@ -1053,7 +1052,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10531052 )
10541053 }
10551054 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) ) ;
10571056 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
10581057 TyAssocTypeItem ( Box :: new ( generics) , bounds)
10591058 }
@@ -1083,7 +1082,7 @@ pub(crate) fn clean_impl_item<'tcx>(
10831082 }
10841083 hir:: ImplItemKind :: TyAlias ( hir_ty) => {
10851084 let type_ = clean_ty ( hir_ty, cx) ;
1086- let generics = impl_. generics . clean ( cx) ;
1085+ let generics = clean_generics ( impl_. generics , cx) ;
10871086 let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
10881087 AssocTypeItem (
10891088 Box :: new ( Typedef { type_, generics, item_type : Some ( item_type) } ) ,
@@ -1913,32 +1912,32 @@ fn clean_maybe_renamed_item<'tcx>(
19131912 } ) ,
19141913 ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
19151914 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) ,
19171916 } ) ,
19181917 ItemKind :: TyAlias ( hir_ty, generics) => {
19191918 let rustdoc_ty = clean_ty ( hir_ty, cx) ;
19201919 let ty = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
19211920 TypedefItem ( Box :: new ( Typedef {
19221921 type_ : rustdoc_ty,
1923- generics : generics . clean ( cx) ,
1922+ generics : clean_generics ( generics , cx) ,
19241923 item_type : Some ( ty) ,
19251924 } ) )
19261925 }
19271926 ItemKind :: Enum ( ref def, generics) => EnumItem ( Enum {
19281927 variants : def. variants . iter ( ) . map ( |v| v. clean ( cx) ) . collect ( ) ,
1929- generics : generics . clean ( cx) ,
1928+ generics : clean_generics ( generics , cx) ,
19301929 } ) ,
19311930 ItemKind :: TraitAlias ( generics, bounds) => TraitAliasItem ( TraitAlias {
1932- generics : generics . clean ( cx) ,
1931+ generics : clean_generics ( generics , cx) ,
19331932 bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
19341933 } ) ,
19351934 ItemKind :: Union ( ref variant_data, generics) => UnionItem ( Union {
1936- generics : generics . clean ( cx) ,
1935+ generics : clean_generics ( generics , cx) ,
19371936 fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
19381937 } ) ,
19391938 ItemKind :: Struct ( ref variant_data, generics) => StructItem ( Struct {
19401939 struct_type : CtorKind :: from_hir ( variant_data) ,
1941- generics : generics . clean ( cx) ,
1940+ generics : clean_generics ( generics , cx) ,
19421941 fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
19431942 } ) ,
19441943 ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. hir_id ( ) , cx) ,
@@ -1961,7 +1960,7 @@ fn clean_maybe_renamed_item<'tcx>(
19611960 TraitItem ( Trait {
19621961 def_id,
19631962 items,
1964- generics : generics . clean ( cx) ,
1963+ generics : clean_generics ( generics , cx) ,
19651964 bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
19661965 } )
19671966 }
@@ -2017,7 +2016,7 @@ fn clean_impl<'tcx>(
20172016 let mut make_item = |trait_ : Option < Path > , for_ : Type , items : Vec < Item > | {
20182017 let kind = ImplItem ( Box :: new ( Impl {
20192018 unsafety : impl_. unsafety ,
2020- generics : impl_. generics . clean ( cx) ,
2019+ generics : clean_generics ( impl_. generics , cx) ,
20212020 trait_,
20222021 for_,
20232022 items,
@@ -2212,7 +2211,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
22122211 hir:: ForeignItemKind :: Fn ( decl, names, generics) => {
22132212 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
22142213 // NOTE: generics must be cleaned before args
2215- let generics = generics . clean ( cx) ;
2214+ let generics = clean_generics ( generics , cx) ;
22162215 let args = clean_args_from_types_and_names ( cx, decl. inputs , names) ;
22172216 let decl = clean_fn_decl_with_args ( cx, decl, args) ;
22182217 ( generics, decl)
0 commit comments