@@ -568,69 +568,68 @@ fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool {
568568 matches ! ( param. kind, hir:: GenericParamKind :: Lifetime { kind: hir:: LifetimeParamKind :: Elided } )
569569}
570570
571- impl < ' tcx > Clean < ' tcx , Generics > for hir :: Generics < ' tcx > {
572- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Generics {
573- let impl_trait_params = self
574- . params
575- . iter ( )
576- . filter ( |param| is_impl_trait ( param ) )
577- . map ( |param| {
578- let param = clean_generic_param ( cx , Some ( self ) , param) ;
579- match param . kind {
580- GenericParamDefKind :: Lifetime { .. } => unreachable ! ( ) ,
581- GenericParamDefKind :: Type { did , ref bounds , .. } => {
582- cx . impl_trait_bounds . insert ( did . into ( ) , bounds . clone ( ) ) ;
583- }
584- GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
571+ pub ( crate ) fn clean_generics < ' tcx > (
572+ gens : & hir :: Generics < ' tcx > ,
573+ cx : & mut DocContext < ' tcx > ,
574+ ) -> Generics {
575+ let impl_trait_params = gens
576+ . params
577+ . iter ( )
578+ . filter ( | param| is_impl_trait ( param) )
579+ . map ( |param| {
580+ let param = clean_generic_param ( cx , Some ( gens ) , param ) ;
581+ match param . kind {
582+ GenericParamDefKind :: Lifetime { .. } => unreachable ! ( ) ,
583+ GenericParamDefKind :: Type { did , ref bounds , .. } => {
584+ cx . impl_trait_bounds . insert ( did . into ( ) , bounds . clone ( ) ) ;
585585 }
586- param
587- } )
588- . collect :: < Vec < _ > > ( ) ;
586+ GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
587+ }
588+ param
589+ } )
590+ . collect :: < Vec < _ > > ( ) ;
589591
590- let mut params = Vec :: with_capacity ( self . params . len ( ) ) ;
591- for p in self . params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
592- let p = clean_generic_param ( cx, Some ( self ) , p) ;
593- params. push ( p) ;
594- }
595- params. extend ( impl_trait_params) ;
592+ let mut params = Vec :: with_capacity ( gens . params . len ( ) ) ;
593+ for p in gens . params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
594+ let p = clean_generic_param ( cx, Some ( gens ) , p) ;
595+ params. push ( p) ;
596+ }
597+ params. extend ( impl_trait_params) ;
596598
597- let mut generics = Generics {
598- params,
599- where_predicates : self
600- . predicates
601- . iter ( )
602- . filter_map ( |x| clean_where_predicate ( x, cx) )
603- . collect ( ) ,
604- } ;
599+ let mut generics = Generics {
600+ params,
601+ where_predicates : gens
602+ . predicates
603+ . iter ( )
604+ . filter_map ( |x| clean_where_predicate ( x, cx) )
605+ . collect ( ) ,
606+ } ;
605607
606- // Some duplicates are generated for ?Sized bounds between type params and where
607- // predicates. The point in here is to move the bounds definitions from type params
608- // to where predicates when such cases occur.
609- for where_pred in & mut generics. where_predicates {
610- match * where_pred {
611- WherePredicate :: BoundPredicate {
612- ty : Generic ( ref name) , ref mut bounds, ..
613- } => {
614- if bounds. is_empty ( ) {
615- for param in & mut generics. params {
616- match param. kind {
617- GenericParamDefKind :: Lifetime { .. } => { }
618- GenericParamDefKind :: Type { bounds : ref mut ty_bounds, .. } => {
619- if & param. name == name {
620- mem:: swap ( bounds, ty_bounds) ;
621- break ;
622- }
608+ // Some duplicates are generated for ?Sized bounds between type params and where
609+ // predicates. The point in here is to move the bounds definitions from type params
610+ // to where predicates when such cases occur.
611+ for where_pred in & mut generics. where_predicates {
612+ match * where_pred {
613+ WherePredicate :: BoundPredicate { ty : Generic ( ref name) , ref mut bounds, .. } => {
614+ if bounds. is_empty ( ) {
615+ for param in & mut generics. params {
616+ match param. kind {
617+ GenericParamDefKind :: Lifetime { .. } => { }
618+ GenericParamDefKind :: Type { bounds : ref mut ty_bounds, .. } => {
619+ if & param. name == name {
620+ mem:: swap ( bounds, ty_bounds) ;
621+ break ;
623622 }
624- GenericParamDefKind :: Const { .. } => { }
625623 }
624+ GenericParamDefKind :: Const { .. } => { }
626625 }
627626 }
628627 }
629- _ => continue ,
630628 }
629+ _ => continue ,
631630 }
632- generics
633631 }
632+ generics
634633}
635634
636635fn clean_ty_generics < ' tcx > (
@@ -896,7 +895,7 @@ fn clean_function<'tcx>(
896895) -> Box < Function > {
897896 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
898897 // NOTE: generics must be cleaned before args
899- let generics = generics . clean ( cx) ;
898+ let generics = clean_generics ( generics , cx) ;
900899 let args = clean_args_from_types_and_body_id ( cx, sig. decl . inputs , body_id) ;
901900 let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
902901 ( generics, decl)
@@ -1025,15 +1024,15 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10251024 hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( names) ) => {
10261025 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
10271026 // NOTE: generics must be cleaned before args
1028- let generics = trait_item. generics . clean ( cx) ;
1027+ let generics = clean_generics ( trait_item. generics , cx) ;
10291028 let args = clean_args_from_types_and_names ( cx, sig. decl . inputs , names) ;
10301029 let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
10311030 ( generics, decl)
10321031 } ) ;
10331032 TyMethodItem ( Box :: new ( Function { decl, generics } ) )
10341033 }
10351034 hir:: TraitItemKind :: Type ( bounds, Some ( default) ) => {
1036- let generics = enter_impl_trait ( cx, |cx| trait_item. generics . clean ( cx) ) ;
1035+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
10371036 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
10381037 let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , default) , cx, None ) ;
10391038 AssocTypeItem (
@@ -1046,7 +1045,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10461045 )
10471046 }
10481047 hir:: TraitItemKind :: Type ( bounds, None ) => {
1049- let generics = enter_impl_trait ( cx, |cx| trait_item. generics . clean ( cx) ) ;
1048+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
10501049 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
10511050 TyAssocTypeItem ( Box :: new ( generics) , bounds)
10521051 }
@@ -1058,45 +1057,46 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10581057 } )
10591058}
10601059
1061- impl < ' tcx > Clean < ' tcx , Item > for hir:: ImplItem < ' tcx > {
1062- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Item {
1063- let local_did = self . def_id . to_def_id ( ) ;
1064- cx. with_param_env ( local_did, |cx| {
1065- let inner = match self . kind {
1066- hir:: ImplItemKind :: Const ( ty, expr) => {
1067- let default = ConstantKind :: Local { def_id : local_did, body : expr } ;
1068- AssocConstItem ( clean_ty ( ty, cx) , default)
1069- }
1070- hir:: ImplItemKind :: Fn ( ref sig, body) => {
1071- let m = clean_function ( cx, sig, self . generics , body) ;
1072- let defaultness = cx. tcx . impl_defaultness ( self . def_id ) ;
1073- MethodItem ( m, Some ( defaultness) )
1074- }
1075- hir:: ImplItemKind :: TyAlias ( hir_ty) => {
1076- let type_ = clean_ty ( hir_ty, cx) ;
1077- let generics = self . generics . clean ( cx) ;
1078- let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
1079- AssocTypeItem (
1080- Box :: new ( Typedef { type_, generics, item_type : Some ( item_type) } ) ,
1081- Vec :: new ( ) ,
1082- )
1083- }
1084- } ;
1060+ pub ( crate ) fn clean_impl_item < ' tcx > (
1061+ impl_ : & hir:: ImplItem < ' tcx > ,
1062+ cx : & mut DocContext < ' tcx > ,
1063+ ) -> Item {
1064+ let local_did = impl_. def_id . to_def_id ( ) ;
1065+ cx. with_param_env ( local_did, |cx| {
1066+ let inner = match impl_. kind {
1067+ hir:: ImplItemKind :: Const ( ty, expr) => {
1068+ let default = ConstantKind :: Local { def_id : local_did, body : expr } ;
1069+ AssocConstItem ( clean_ty ( ty, cx) , default)
1070+ }
1071+ hir:: ImplItemKind :: Fn ( ref sig, body) => {
1072+ let m = clean_function ( cx, sig, impl_. generics , body) ;
1073+ let defaultness = cx. tcx . impl_defaultness ( impl_. def_id ) ;
1074+ MethodItem ( m, Some ( defaultness) )
1075+ }
1076+ hir:: ImplItemKind :: TyAlias ( hir_ty) => {
1077+ let type_ = clean_ty ( hir_ty, cx) ;
1078+ let generics = clean_generics ( impl_. generics , cx) ;
1079+ let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
1080+ AssocTypeItem (
1081+ Box :: new ( Typedef { type_, generics, item_type : Some ( item_type) } ) ,
1082+ Vec :: new ( ) ,
1083+ )
1084+ }
1085+ } ;
10851086
1086- let mut what_rustc_thinks =
1087- Item :: from_def_id_and_parts ( local_did, Some ( self . ident . name ) , inner, cx) ;
1087+ let mut what_rustc_thinks =
1088+ Item :: from_def_id_and_parts ( local_did, Some ( impl_ . ident . name ) , inner, cx) ;
10881089
1089- let impl_ref = cx. tcx . impl_trait_ref ( cx. tcx . local_parent ( self . def_id ) ) ;
1090+ let impl_ref = cx. tcx . impl_trait_ref ( cx. tcx . local_parent ( impl_ . def_id ) ) ;
10901091
1091- // Trait impl items always inherit the impl's visibility --
1092- // we don't want to show `pub`.
1093- if impl_ref. is_some ( ) {
1094- what_rustc_thinks. visibility = Inherited ;
1095- }
1092+ // Trait impl items always inherit the impl's visibility --
1093+ // we don't want to show `pub`.
1094+ if impl_ref. is_some ( ) {
1095+ what_rustc_thinks. visibility = Inherited ;
1096+ }
10961097
1097- what_rustc_thinks
1098- } )
1099- }
1098+ what_rustc_thinks
1099+ } )
11001100}
11011101
11021102impl < ' tcx > Clean < ' tcx , Item > for ty:: AssocItem {
@@ -1905,32 +1905,32 @@ fn clean_maybe_renamed_item<'tcx>(
19051905 } ) ,
19061906 ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
19071907 bounds : ty. bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1908- generics : ty. generics . clean ( cx) ,
1908+ generics : clean_generics ( ty. generics , cx) ,
19091909 } ) ,
19101910 ItemKind :: TyAlias ( hir_ty, generics) => {
19111911 let rustdoc_ty = clean_ty ( hir_ty, cx) ;
19121912 let ty = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
19131913 TypedefItem ( Box :: new ( Typedef {
19141914 type_ : rustdoc_ty,
1915- generics : generics . clean ( cx) ,
1915+ generics : clean_generics ( generics , cx) ,
19161916 item_type : Some ( ty) ,
19171917 } ) )
19181918 }
19191919 ItemKind :: Enum ( ref def, generics) => EnumItem ( Enum {
19201920 variants : def. variants . iter ( ) . map ( |v| v. clean ( cx) ) . collect ( ) ,
1921- generics : generics . clean ( cx) ,
1921+ generics : clean_generics ( generics , cx) ,
19221922 } ) ,
19231923 ItemKind :: TraitAlias ( generics, bounds) => TraitAliasItem ( TraitAlias {
1924- generics : generics . clean ( cx) ,
1924+ generics : clean_generics ( generics , cx) ,
19251925 bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
19261926 } ) ,
19271927 ItemKind :: Union ( ref variant_data, generics) => UnionItem ( Union {
1928- generics : generics . clean ( cx) ,
1928+ generics : clean_generics ( generics , cx) ,
19291929 fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
19301930 } ) ,
19311931 ItemKind :: Struct ( ref variant_data, generics) => StructItem ( Struct {
19321932 struct_type : CtorKind :: from_hir ( variant_data) ,
1933- generics : generics . clean ( cx) ,
1933+ generics : clean_generics ( generics , cx) ,
19341934 fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
19351935 } ) ,
19361936 ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. hir_id ( ) , cx) ,
@@ -1953,7 +1953,7 @@ fn clean_maybe_renamed_item<'tcx>(
19531953 TraitItem ( Trait {
19541954 def_id,
19551955 items,
1956- generics : generics . clean ( cx) ,
1956+ generics : clean_generics ( generics , cx) ,
19571957 bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
19581958 } )
19591959 }
@@ -1988,8 +1988,11 @@ fn clean_impl<'tcx>(
19881988 let tcx = cx. tcx ;
19891989 let mut ret = Vec :: new ( ) ;
19901990 let trait_ = impl_. of_trait . as_ref ( ) . map ( |t| clean_trait_ref ( t, cx) ) ;
1991- let items =
1992- impl_. items . iter ( ) . map ( |ii| tcx. hir ( ) . impl_item ( ii. id ) . clean ( cx) ) . collect :: < Vec < _ > > ( ) ;
1991+ let items = impl_
1992+ . items
1993+ . iter ( )
1994+ . map ( |ii| clean_impl_item ( tcx. hir ( ) . impl_item ( ii. id ) , cx) )
1995+ . collect :: < Vec < _ > > ( ) ;
19931996 let def_id = tcx. hir ( ) . local_def_id ( hir_id) ;
19941997
19951998 // If this impl block is an implementation of the Deref trait, then we
@@ -2006,7 +2009,7 @@ fn clean_impl<'tcx>(
20062009 let mut make_item = |trait_ : Option < Path > , for_ : Type , items : Vec < Item > | {
20072010 let kind = ImplItem ( Box :: new ( Impl {
20082011 unsafety : impl_. unsafety ,
2009- generics : impl_. generics . clean ( cx) ,
2012+ generics : clean_generics ( impl_. generics , cx) ,
20102013 trait_,
20112014 for_,
20122015 items,
@@ -2203,7 +2206,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
22032206 hir:: ForeignItemKind :: Fn ( decl, names, generics) => {
22042207 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
22052208 // NOTE: generics must be cleaned before args
2206- let generics = generics . clean ( cx) ;
2209+ let generics = clean_generics ( generics , cx) ;
22072210 let args = clean_args_from_types_and_names ( cx, decl. inputs , names) ;
22082211 let decl = clean_fn_decl_with_args ( cx, decl, args) ;
22092212 ( generics, decl)
0 commit comments