@@ -561,69 +561,68 @@ fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool {
561
561
matches ! ( param. kind, hir:: GenericParamKind :: Lifetime { kind: hir:: LifetimeParamKind :: Elided } )
562
562
}
563
563
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 ( ) ) ;
578
578
}
579
- param
580
- } )
581
- . collect :: < Vec < _ > > ( ) ;
579
+ GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
580
+ }
581
+ param
582
+ } )
583
+ . collect :: < Vec < _ > > ( ) ;
582
584
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) ;
589
591
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
+ } ;
598
600
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 ;
616
615
}
617
- GenericParamDefKind :: Const { .. } => { }
618
616
}
617
+ GenericParamDefKind :: Const { .. } => { }
619
618
}
620
619
}
621
620
}
622
- _ => continue ,
623
621
}
622
+ _ => continue ,
624
623
}
625
- generics
626
624
}
625
+ generics
627
626
}
628
627
629
628
fn clean_ty_generics < ' tcx > (
@@ -889,7 +888,7 @@ fn clean_function<'tcx>(
889
888
) -> Box < Function > {
890
889
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
891
890
// NOTE: generics must be cleaned before args
892
- let generics = generics . clean ( cx) ;
891
+ let generics = clean_generics ( generics , cx) ;
893
892
let args = clean_args_from_types_and_body_id ( cx, sig. decl . inputs , body_id) ;
894
893
let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
895
894
( generics, decl)
@@ -1018,15 +1017,15 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1018
1017
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( names) ) => {
1019
1018
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
1020
1019
// NOTE: generics must be cleaned before args
1021
- let generics = trait_item. generics . clean ( cx) ;
1020
+ let generics = clean_generics ( trait_item. generics , cx) ;
1022
1021
let args = clean_args_from_types_and_names ( cx, sig. decl . inputs , names) ;
1023
1022
let decl = clean_fn_decl_with_args ( cx, sig. decl , args) ;
1024
1023
( generics, decl)
1025
1024
} ) ;
1026
1025
TyMethodItem ( Box :: new ( Function { decl, generics } ) )
1027
1026
}
1028
1027
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) ) ;
1030
1029
let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1031
1030
let item_type = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , default) , cx, None ) ;
1032
1031
AssocTypeItem (
@@ -1039,7 +1038,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1039
1038
)
1040
1039
}
1041
1040
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) ) ;
1043
1042
let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1044
1043
TyAssocTypeItem ( Box :: new ( generics) , bounds)
1045
1044
}
@@ -1051,45 +1050,46 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1051
1050
} )
1052
1051
}
1053
1052
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
+ } ;
1078
1079
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) ;
1081
1082
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 ) ) ;
1083
1084
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
+ }
1089
1090
1090
- what_rustc_thinks
1091
- } )
1092
- }
1091
+ what_rustc_thinks
1092
+ } )
1093
1093
}
1094
1094
1095
1095
impl < ' tcx > Clean < ' tcx , Item > for ty:: AssocItem {
@@ -1898,32 +1898,32 @@ fn clean_maybe_renamed_item<'tcx>(
1898
1898
} ) ,
1899
1899
ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
1900
1900
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) ,
1902
1902
} ) ,
1903
1903
ItemKind :: TyAlias ( hir_ty, generics) => {
1904
1904
let rustdoc_ty = clean_ty ( hir_ty, cx) ;
1905
1905
let ty = clean_middle_ty ( hir_ty_to_ty ( cx. tcx , hir_ty) , cx, None ) ;
1906
1906
TypedefItem ( Box :: new ( Typedef {
1907
1907
type_ : rustdoc_ty,
1908
- generics : generics . clean ( cx) ,
1908
+ generics : clean_generics ( generics , cx) ,
1909
1909
item_type : Some ( ty) ,
1910
1910
} ) )
1911
1911
}
1912
1912
ItemKind :: Enum ( ref def, generics) => EnumItem ( Enum {
1913
1913
variants : def. variants . iter ( ) . map ( |v| v. clean ( cx) ) . collect ( ) ,
1914
- generics : generics . clean ( cx) ,
1914
+ generics : clean_generics ( generics , cx) ,
1915
1915
} ) ,
1916
1916
ItemKind :: TraitAlias ( generics, bounds) => TraitAliasItem ( TraitAlias {
1917
- generics : generics . clean ( cx) ,
1917
+ generics : clean_generics ( generics , cx) ,
1918
1918
bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1919
1919
} ) ,
1920
1920
ItemKind :: Union ( ref variant_data, generics) => UnionItem ( Union {
1921
- generics : generics . clean ( cx) ,
1921
+ generics : clean_generics ( generics , cx) ,
1922
1922
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
1923
1923
} ) ,
1924
1924
ItemKind :: Struct ( ref variant_data, generics) => StructItem ( Struct {
1925
1925
struct_type : CtorKind :: from_hir ( variant_data) ,
1926
- generics : generics . clean ( cx) ,
1926
+ generics : clean_generics ( generics , cx) ,
1927
1927
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
1928
1928
} ) ,
1929
1929
ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. hir_id ( ) , cx) ,
@@ -1946,7 +1946,7 @@ fn clean_maybe_renamed_item<'tcx>(
1946
1946
TraitItem ( Trait {
1947
1947
def_id,
1948
1948
items,
1949
- generics : generics . clean ( cx) ,
1949
+ generics : clean_generics ( generics , cx) ,
1950
1950
bounds : bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
1951
1951
} )
1952
1952
}
@@ -1981,8 +1981,11 @@ fn clean_impl<'tcx>(
1981
1981
let tcx = cx. tcx ;
1982
1982
let mut ret = Vec :: new ( ) ;
1983
1983
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 < _ > > ( ) ;
1986
1989
let def_id = tcx. hir ( ) . local_def_id ( hir_id) ;
1987
1990
1988
1991
// If this impl block is an implementation of the Deref trait, then we
@@ -1999,7 +2002,7 @@ fn clean_impl<'tcx>(
1999
2002
let mut make_item = |trait_ : Option < Path > , for_ : Type , items : Vec < Item > | {
2000
2003
let kind = ImplItem ( Box :: new ( Impl {
2001
2004
unsafety : impl_. unsafety ,
2002
- generics : impl_. generics . clean ( cx) ,
2005
+ generics : clean_generics ( impl_. generics , cx) ,
2003
2006
trait_,
2004
2007
for_,
2005
2008
items,
@@ -2196,7 +2199,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
2196
2199
hir:: ForeignItemKind :: Fn ( decl, names, generics) => {
2197
2200
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
2198
2201
// NOTE: generics must be cleaned before args
2199
- let generics = generics . clean ( cx) ;
2202
+ let generics = clean_generics ( generics , cx) ;
2200
2203
let args = clean_args_from_types_and_names ( cx, decl. inputs , names) ;
2201
2204
let decl = clean_fn_decl_with_args ( cx, decl, args) ;
2202
2205
( generics, decl)
0 commit comments