@@ -568,69 +568,68 @@ fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool {
568
568
matches ! ( param. kind, hir:: GenericParamKind :: Lifetime { kind: hir:: LifetimeParamKind :: Elided } )
569
569
}
570
570
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 ( ) ) ;
585
585
}
586
- param
587
- } )
588
- . collect :: < Vec < _ > > ( ) ;
586
+ GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
587
+ }
588
+ param
589
+ } )
590
+ . collect :: < Vec < _ > > ( ) ;
589
591
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) ;
596
598
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
+ } ;
605
607
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 ;
623
622
}
624
- GenericParamDefKind :: Const { .. } => { }
625
623
}
624
+ GenericParamDefKind :: Const { .. } => { }
626
625
}
627
626
}
628
627
}
629
- _ => continue ,
630
628
}
629
+ _ => continue ,
631
630
}
632
- generics
633
631
}
632
+ generics
634
633
}
635
634
636
635
fn clean_ty_generics < ' tcx > (
@@ -896,7 +895,7 @@ fn clean_function<'tcx>(
896
895
) -> Box < Function > {
897
896
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
898
897
// NOTE: generics must be cleaned before args
899
- let generics = generics . clean ( cx) ;
898
+ let generics = clean_generics ( generics , cx) ;
900
899
let args = clean_args_from_types_and_body_id ( cx, sig. decl . inputs , body_id) ;
901
900
let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
902
901
( generics, decl)
@@ -1025,15 +1024,15 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1025
1024
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( names) ) => {
1026
1025
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
1027
1026
// NOTE: generics must be cleaned before args
1028
- let generics = trait_item. generics . clean ( cx) ;
1027
+ let generics = clean_generics ( trait_item. generics , cx) ;
1029
1028
let args = clean_args_from_types_and_names ( cx, sig. decl . inputs , names) ;
1030
1029
let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
1031
1030
( generics, decl)
1032
1031
} ) ;
1033
1032
TyMethodItem ( Box :: new ( Function { decl, generics } ) )
1034
1033
}
1035
1034
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) ) ;
1037
1036
let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1038
1037
let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , default) , cx, None ) ;
1039
1038
AssocTypeItem (
@@ -1046,7 +1045,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1046
1045
)
1047
1046
}
1048
1047
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) ) ;
1050
1049
let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1051
1050
TyAssocTypeItem ( Box :: new ( generics) , bounds)
1052
1051
}
@@ -1058,45 +1057,46 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1058
1057
} )
1059
1058
}
1060
1059
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
+ } ;
1085
1086
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) ;
1088
1089
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 ) ) ;
1090
1091
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
+ }
1096
1097
1097
- what_rustc_thinks
1098
- } )
1099
- }
1098
+ what_rustc_thinks
1099
+ } )
1100
1100
}
1101
1101
1102
1102
impl < ' tcx > Clean < ' tcx , Item > for ty:: AssocItem {
@@ -1905,32 +1905,32 @@ fn clean_maybe_renamed_item<'tcx>(
1905
1905
} ) ,
1906
1906
ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
1907
1907
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) ,
1909
1909
} ) ,
1910
1910
ItemKind :: TyAlias ( hir_ty, generics) => {
1911
1911
let rustdoc_ty = clean_ty ( hir_ty, cx) ;
1912
1912
let ty = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
1913
1913
TypedefItem ( Box :: new ( Typedef {
1914
1914
type_ : rustdoc_ty,
1915
- generics : generics . clean ( cx) ,
1915
+ generics : clean_generics ( generics , cx) ,
1916
1916
item_type : Some ( ty) ,
1917
1917
} ) )
1918
1918
}
1919
1919
ItemKind :: Enum ( ref def, generics) => EnumItem ( Enum {
1920
1920
variants : def. variants . iter ( ) . map ( |v| v. clean ( cx) ) . collect ( ) ,
1921
- generics : generics . clean ( cx) ,
1921
+ generics : clean_generics ( generics , cx) ,
1922
1922
} ) ,
1923
1923
ItemKind :: TraitAlias ( generics, bounds) => TraitAliasItem ( TraitAlias {
1924
- generics : generics . clean ( cx) ,
1924
+ generics : clean_generics ( generics , cx) ,
1925
1925
bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1926
1926
} ) ,
1927
1927
ItemKind :: Union ( ref variant_data, generics) => UnionItem ( Union {
1928
- generics : generics . clean ( cx) ,
1928
+ generics : clean_generics ( generics , cx) ,
1929
1929
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
1930
1930
} ) ,
1931
1931
ItemKind :: Struct ( ref variant_data, generics) => StructItem ( Struct {
1932
1932
struct_type : CtorKind :: from_hir ( variant_data) ,
1933
- generics : generics . clean ( cx) ,
1933
+ generics : clean_generics ( generics , cx) ,
1934
1934
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
1935
1935
} ) ,
1936
1936
ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. hir_id ( ) , cx) ,
@@ -1953,7 +1953,7 @@ fn clean_maybe_renamed_item<'tcx>(
1953
1953
TraitItem ( Trait {
1954
1954
def_id,
1955
1955
items,
1956
- generics : generics . clean ( cx) ,
1956
+ generics : clean_generics ( generics , cx) ,
1957
1957
bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1958
1958
} )
1959
1959
}
@@ -1988,8 +1988,11 @@ fn clean_impl<'tcx>(
1988
1988
let tcx = cx. tcx ;
1989
1989
let mut ret = Vec :: new ( ) ;
1990
1990
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 < _ > > ( ) ;
1993
1996
let def_id = tcx. hir ( ) . local_def_id ( hir_id) ;
1994
1997
1995
1998
// If this impl block is an implementation of the Deref trait, then we
@@ -2006,7 +2009,7 @@ fn clean_impl<'tcx>(
2006
2009
let mut make_item = |trait_ : Option < Path > , for_ : Type , items : Vec < Item > | {
2007
2010
let kind = ImplItem ( Box :: new ( Impl {
2008
2011
unsafety : impl_. unsafety ,
2009
- generics : impl_. generics . clean ( cx) ,
2012
+ generics : clean_generics ( impl_. generics , cx) ,
2010
2013
trait_,
2011
2014
for_,
2012
2015
items,
@@ -2203,7 +2206,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
2203
2206
hir:: ForeignItemKind :: Fn ( decl, names, generics) => {
2204
2207
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
2205
2208
// NOTE: generics must be cleaned before args
2206
- let generics = generics . clean ( cx) ;
2209
+ let generics = clean_generics ( generics , cx) ;
2207
2210
let args = clean_args_from_types_and_names ( cx, decl. inputs , names) ;
2208
2211
let decl = clean_fn_decl_with_args ( cx, decl, args) ;
2209
2212
( generics, decl)
0 commit comments