@@ -561,69 +561,68 @@ fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool {
561561 matches ! ( param. kind, hir:: GenericParamKind :: Lifetime { kind: hir:: LifetimeParamKind :: Elided } )
562562}
563563
564- impl < ' tcx > Clean < ' tcx , Generics > for hir :: Generics < ' tcx > {
565- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Generics {
566- let impl_trait_params = self
567- . params
568- . iter ( )
569- . filter ( |param| is_impl_trait ( param ) )
570- . map ( |param| {
571- let param = clean_generic_param ( cx , Some ( self ) , param) ;
572- match param . kind {
573- GenericParamDefKind :: Lifetime { .. } => unreachable ! ( ) ,
574- GenericParamDefKind :: Type { did , ref bounds , .. } => {
575- cx . impl_trait_bounds . insert ( did . into ( ) , bounds . clone ( ) ) ;
576- }
577- GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
564+ pub ( crate ) fn clean_generics < ' tcx > (
565+ gens : & hir :: Generics < ' tcx > ,
566+ cx : & mut DocContext < ' tcx > ,
567+ ) -> Generics {
568+ let impl_trait_params = gens
569+ . params
570+ . iter ( )
571+ . filter ( | param| is_impl_trait ( param) )
572+ . map ( |param| {
573+ let param = clean_generic_param ( cx , Some ( gens ) , param ) ;
574+ match param . kind {
575+ GenericParamDefKind :: Lifetime { .. } => unreachable ! ( ) ,
576+ GenericParamDefKind :: Type { did , ref bounds , .. } => {
577+ cx . impl_trait_bounds . insert ( did . into ( ) , bounds . clone ( ) ) ;
578578 }
579- param
580- } )
581- . collect :: < Vec < _ > > ( ) ;
579+ GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
580+ }
581+ param
582+ } )
583+ . collect :: < Vec < _ > > ( ) ;
582584
583- let mut params = Vec :: with_capacity ( self . params . len ( ) ) ;
584- for p in self . params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
585- let p = clean_generic_param ( cx, Some ( self ) , p) ;
586- params. push ( p) ;
587- }
588- params. extend ( impl_trait_params) ;
585+ let mut params = Vec :: with_capacity ( gens . params . len ( ) ) ;
586+ for p in gens . params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
587+ let p = clean_generic_param ( cx, Some ( gens ) , p) ;
588+ params. push ( p) ;
589+ }
590+ params. extend ( impl_trait_params) ;
589591
590- let mut generics = Generics {
591- params,
592- where_predicates : self
593- . predicates
594- . iter ( )
595- . filter_map ( |x| clean_where_predicate ( x, cx) )
596- . collect ( ) ,
597- } ;
592+ let mut generics = Generics {
593+ params,
594+ where_predicates : gens
595+ . predicates
596+ . iter ( )
597+ . filter_map ( |x| clean_where_predicate ( x, cx) )
598+ . collect ( ) ,
599+ } ;
598600
599- // Some duplicates are generated for ?Sized bounds between type params and where
600- // predicates. The point in here is to move the bounds definitions from type params
601- // to where predicates when such cases occur.
602- for where_pred in & mut generics. where_predicates {
603- match * where_pred {
604- WherePredicate :: BoundPredicate {
605- ty : Generic ( ref name) , ref mut bounds, ..
606- } => {
607- if bounds. is_empty ( ) {
608- for param in & mut generics. params {
609- match param. kind {
610- GenericParamDefKind :: Lifetime { .. } => { }
611- GenericParamDefKind :: Type { bounds : ref mut ty_bounds, .. } => {
612- if & param. name == name {
613- mem:: swap ( bounds, ty_bounds) ;
614- break ;
615- }
601+ // Some duplicates are generated for ?Sized bounds between type params and where
602+ // predicates. The point in here is to move the bounds definitions from type params
603+ // to where predicates when such cases occur.
604+ for where_pred in & mut generics. where_predicates {
605+ match * where_pred {
606+ WherePredicate :: BoundPredicate { ty : Generic ( ref name) , ref mut bounds, .. } => {
607+ if bounds. is_empty ( ) {
608+ for param in & mut generics. params {
609+ match param. kind {
610+ GenericParamDefKind :: Lifetime { .. } => { }
611+ GenericParamDefKind :: Type { bounds : ref mut ty_bounds, .. } => {
612+ if & param. name == name {
613+ mem:: swap ( bounds, ty_bounds) ;
614+ break ;
616615 }
617- GenericParamDefKind :: Const { .. } => { }
618616 }
617+ GenericParamDefKind :: Const { .. } => { }
619618 }
620619 }
621620 }
622- _ => continue ,
623621 }
622+ _ => continue ,
624623 }
625- generics
626624 }
625+ generics
627626}
628627
629628fn clean_ty_generics < ' tcx > (
@@ -889,7 +888,7 @@ fn clean_function<'tcx>(
889888) -> Box < Function > {
890889 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
891890 // NOTE: generics must be cleaned before args
892- let generics = generics . clean ( cx) ;
891+ let generics = clean_generics ( generics , cx) ;
893892 let args = clean_args_from_types_and_body_id ( cx, sig. decl . inputs , body_id) ;
894893 let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
895894 ( generics, decl)
@@ -1018,15 +1017,15 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10181017 hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( names) ) => {
10191018 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
10201019 // NOTE: generics must be cleaned before args
1021- let generics = trait_item. generics . clean ( cx) ;
1020+ let generics = clean_generics ( trait_item. generics , cx) ;
10221021 let args = clean_args_from_types_and_names ( cx, sig. decl . inputs , names) ;
10231022 let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
10241023 ( generics, decl)
10251024 } ) ;
10261025 TyMethodItem ( Box :: new ( Function { decl, generics } ) )
10271026 }
10281027 hir:: TraitItemKind :: Type ( bounds, Some ( default) ) => {
1029- let generics = enter_impl_trait ( cx, |cx| trait_item. generics . clean ( cx) ) ;
1028+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
10301029 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
10311030 let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , default) , cx, None ) ;
10321031 AssocTypeItem (
@@ -1039,7 +1038,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10391038 )
10401039 }
10411040 hir:: TraitItemKind :: Type ( bounds, None ) => {
1042- let generics = enter_impl_trait ( cx, |cx| trait_item. generics . clean ( cx) ) ;
1041+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
10431042 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
10441043 TyAssocTypeItem ( Box :: new ( generics) , bounds)
10451044 }
@@ -1051,45 +1050,46 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10511050 } )
10521051}
10531052
1054- impl < ' tcx > Clean < ' tcx , Item > for hir:: ImplItem < ' tcx > {
1055- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Item {
1056- let local_did = self . def_id . to_def_id ( ) ;
1057- cx. with_param_env ( local_did, |cx| {
1058- let inner = match self . kind {
1059- hir:: ImplItemKind :: Const ( ty, expr) => {
1060- let default = ConstantKind :: Local { def_id : local_did, body : expr } ;
1061- AssocConstItem ( clean_ty ( ty, cx) , default)
1062- }
1063- hir:: ImplItemKind :: Fn ( ref sig, body) => {
1064- let m = clean_function ( cx, sig, self . generics , body) ;
1065- let defaultness = cx. tcx . impl_defaultness ( self . def_id ) ;
1066- MethodItem ( m, Some ( defaultness) )
1067- }
1068- hir:: ImplItemKind :: TyAlias ( hir_ty) => {
1069- let type_ = clean_ty ( hir_ty, cx) ;
1070- let generics = self . generics . clean ( cx) ;
1071- let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
1072- AssocTypeItem (
1073- Box :: new ( Typedef { type_, generics, item_type : Some ( item_type) } ) ,
1074- Vec :: new ( ) ,
1075- )
1076- }
1077- } ;
1053+ pub ( crate ) fn clean_impl_item < ' tcx > (
1054+ impl_ : & hir:: ImplItem < ' tcx > ,
1055+ cx : & mut DocContext < ' tcx > ,
1056+ ) -> Item {
1057+ let local_did = impl_. def_id . to_def_id ( ) ;
1058+ cx. with_param_env ( local_did, |cx| {
1059+ let inner = match impl_. kind {
1060+ hir:: ImplItemKind :: Const ( ty, expr) => {
1061+ let default = ConstantKind :: Local { def_id : local_did, body : expr } ;
1062+ AssocConstItem ( clean_ty ( ty, cx) , default)
1063+ }
1064+ hir:: ImplItemKind :: Fn ( ref sig, body) => {
1065+ let m = clean_function ( cx, sig, impl_. generics , body) ;
1066+ let defaultness = cx. tcx . impl_defaultness ( impl_. def_id ) ;
1067+ MethodItem ( m, Some ( defaultness) )
1068+ }
1069+ hir:: ImplItemKind :: TyAlias ( hir_ty) => {
1070+ let type_ = clean_ty ( hir_ty, cx) ;
1071+ let generics = clean_generics ( impl_. generics , cx) ;
1072+ let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
1073+ AssocTypeItem (
1074+ Box :: new ( Typedef { type_, generics, item_type : Some ( item_type) } ) ,
1075+ Vec :: new ( ) ,
1076+ )
1077+ }
1078+ } ;
10781079
1079- let mut what_rustc_thinks =
1080- Item :: from_def_id_and_parts ( local_did, Some ( self . ident . name ) , inner, cx) ;
1080+ let mut what_rustc_thinks =
1081+ Item :: from_def_id_and_parts ( local_did, Some ( impl_ . ident . name ) , inner, cx) ;
10811082
1082- let impl_ref = cx. tcx . impl_trait_ref ( cx. tcx . local_parent ( self . def_id ) ) ;
1083+ let impl_ref = cx. tcx . impl_trait_ref ( cx. tcx . local_parent ( impl_ . def_id ) ) ;
10831084
1084- // Trait impl items always inherit the impl's visibility --
1085- // we don't want to show `pub`.
1086- if impl_ref. is_some ( ) {
1087- what_rustc_thinks. visibility = Inherited ;
1088- }
1085+ // Trait impl items always inherit the impl's visibility --
1086+ // we don't want to show `pub`.
1087+ if impl_ref. is_some ( ) {
1088+ what_rustc_thinks. visibility = Inherited ;
1089+ }
10891090
1090- what_rustc_thinks
1091- } )
1092- }
1091+ what_rustc_thinks
1092+ } )
10931093}
10941094
10951095impl < ' tcx > Clean < ' tcx , Item > for ty:: AssocItem {
@@ -1898,32 +1898,32 @@ fn clean_maybe_renamed_item<'tcx>(
18981898 } ) ,
18991899 ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
19001900 bounds : ty. bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1901- generics : ty. generics . clean ( cx) ,
1901+ generics : clean_generics ( ty. generics , cx) ,
19021902 } ) ,
19031903 ItemKind :: TyAlias ( hir_ty, generics) => {
19041904 let rustdoc_ty = clean_ty ( hir_ty, cx) ;
19051905 let ty = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
19061906 TypedefItem ( Box :: new ( Typedef {
19071907 type_ : rustdoc_ty,
1908- generics : generics . clean ( cx) ,
1908+ generics : clean_generics ( generics , cx) ,
19091909 item_type : Some ( ty) ,
19101910 } ) )
19111911 }
19121912 ItemKind :: Enum ( ref def, generics) => EnumItem ( Enum {
19131913 variants : def. variants . iter ( ) . map ( |v| v. clean ( cx) ) . collect ( ) ,
1914- generics : generics . clean ( cx) ,
1914+ generics : clean_generics ( generics , cx) ,
19151915 } ) ,
19161916 ItemKind :: TraitAlias ( generics, bounds) => TraitAliasItem ( TraitAlias {
1917- generics : generics . clean ( cx) ,
1917+ generics : clean_generics ( generics , cx) ,
19181918 bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
19191919 } ) ,
19201920 ItemKind :: Union ( ref variant_data, generics) => UnionItem ( Union {
1921- generics : generics . clean ( cx) ,
1921+ generics : clean_generics ( generics , cx) ,
19221922 fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
19231923 } ) ,
19241924 ItemKind :: Struct ( ref variant_data, generics) => StructItem ( Struct {
19251925 struct_type : CtorKind :: from_hir ( variant_data) ,
1926- generics : generics . clean ( cx) ,
1926+ generics : clean_generics ( generics , cx) ,
19271927 fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
19281928 } ) ,
19291929 ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. hir_id ( ) , cx) ,
@@ -1946,7 +1946,7 @@ fn clean_maybe_renamed_item<'tcx>(
19461946 TraitItem ( Trait {
19471947 def_id,
19481948 items,
1949- generics : generics . clean ( cx) ,
1949+ generics : clean_generics ( generics , cx) ,
19501950 bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
19511951 } )
19521952 }
@@ -1981,8 +1981,11 @@ fn clean_impl<'tcx>(
19811981 let tcx = cx. tcx ;
19821982 let mut ret = Vec :: new ( ) ;
19831983 let trait_ = impl_. of_trait . as_ref ( ) . map ( |t| clean_trait_ref ( t, cx) ) ;
1984- let items =
1985- impl_. items . iter ( ) . map ( |ii| tcx. hir ( ) . impl_item ( ii. id ) . clean ( cx) ) . collect :: < Vec < _ > > ( ) ;
1984+ let items = impl_
1985+ . items
1986+ . iter ( )
1987+ . map ( |ii| clean_impl_item ( tcx. hir ( ) . impl_item ( ii. id ) , cx) )
1988+ . collect :: < Vec < _ > > ( ) ;
19861989 let def_id = tcx. hir ( ) . local_def_id ( hir_id) ;
19871990
19881991 // If this impl block is an implementation of the Deref trait, then we
@@ -1999,7 +2002,7 @@ fn clean_impl<'tcx>(
19992002 let mut make_item = |trait_ : Option < Path > , for_ : Type , items : Vec < Item > | {
20002003 let kind = ImplItem ( Box :: new ( Impl {
20012004 unsafety : impl_. unsafety ,
2002- generics : impl_. generics . clean ( cx) ,
2005+ generics : clean_generics ( impl_. generics , cx) ,
20032006 trait_,
20042007 for_,
20052008 items,
@@ -2196,7 +2199,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
21962199 hir:: ForeignItemKind :: Fn ( decl, names, generics) => {
21972200 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
21982201 // NOTE: generics must be cleaned before args
2199- let generics = generics . clean ( cx) ;
2202+ let generics = clean_generics ( generics , cx) ;
22002203 let args = clean_args_from_types_and_names ( cx, decl. inputs , names) ;
22012204 let decl = clean_fn_decl_with_args ( cx, decl, args) ;
22022205 ( generics, decl)
0 commit comments