@@ -234,9 +234,8 @@ impl Clean<Item> for doctree::Module<'_> {
234
234
items. extend ( self . fns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
235
235
items. extend ( self . foreigns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
236
236
items. extend ( self . mods . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
237
- items. extend ( self . items . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
237
+ items. extend ( self . items . iter ( ) . map ( |x| x. clean ( cx) ) . flatten ( ) ) ;
238
238
items. extend ( self . traits . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
239
- items. extend ( self . impls . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ;
240
239
items. extend ( self . macros . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
241
240
items. extend ( self . proc_macros . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
242
241
@@ -1922,8 +1921,8 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
1922
1921
}
1923
1922
}
1924
1923
1925
- impl Clean < Item > for ( & hir:: Item < ' _ > , Option < Ident > ) {
1926
- fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
1924
+ impl Clean < Vec < Item > > for ( & hir:: Item < ' _ > , Option < Ident > ) {
1925
+ fn clean ( & self , cx : & DocContext < ' _ > ) -> Vec < Item > {
1927
1926
use hir:: ItemKind ;
1928
1927
1929
1928
let ( item, renamed) = self ;
@@ -1977,10 +1976,11 @@ impl Clean<Item> for (&hir::Item<'_>, Option<Ident>) {
1977
1976
fields : variant_data. fields ( ) . clean ( cx) ,
1978
1977
fields_stripped : false ,
1979
1978
} ) ,
1979
+ ItemKind :: Impl { .. } => return clean_impl ( item, cx) ,
1980
1980
_ => unreachable ! ( "not yet converted" ) ,
1981
1981
} ;
1982
1982
1983
- Item :: from_def_id_and_parts ( def_id, Some ( name) , kind, cx)
1983
+ vec ! [ Item :: from_def_id_and_parts( def_id, Some ( name) , kind, cx) ]
1984
1984
}
1985
1985
}
1986
1986
@@ -2005,57 +2005,53 @@ impl Clean<ImplPolarity> for ty::ImplPolarity {
2005
2005
}
2006
2006
}
2007
2007
2008
- impl Clean < Vec < Item > > for doctree:: Impl < ' _ > {
2009
- fn clean ( & self , cx : & DocContext < ' _ > ) -> Vec < Item > {
2010
- let mut ret = Vec :: new ( ) ;
2011
- let trait_ = self . trait_ . clean ( cx) ;
2012
- let items = self . items . iter ( ) . map ( |ii| ii. clean ( cx) ) . collect :: < Vec < _ > > ( ) ;
2013
- let def_id = cx. tcx . hir ( ) . local_def_id ( self . id ) ;
2014
-
2015
- // If this impl block is an implementation of the Deref trait, then we
2016
- // need to try inlining the target's inherent impl blocks as well.
2017
- if trait_. def_id ( ) == cx. tcx . lang_items ( ) . deref_trait ( ) {
2018
- build_deref_target_impls ( cx, & items, & mut ret) ;
2008
+ fn clean_impl ( impl_ : & hir:: Item < ' _ > , cx : & DocContext < ' _ > ) -> Vec < Item > {
2009
+ let mut ret = Vec :: new ( ) ;
2010
+ let ( trait_, items, for_, unsafety, generics) = match & impl_. kind {
2011
+ hir:: ItemKind :: Impl { of_trait, items, self_ty, unsafety, generics, .. } => {
2012
+ ( of_trait, items, self_ty, * unsafety, generics)
2019
2013
}
2020
-
2021
- let provided: FxHashSet < String > = trait_
2022
- . def_id ( )
2023
- . map ( |did| {
2024
- cx. tcx . provided_trait_methods ( did) . map ( |meth| meth. ident . to_string ( ) ) . collect ( )
2025
- } )
2026
- . unwrap_or_default ( ) ;
2027
-
2028
- let for_ = self . for_ . clean ( cx) ;
2029
- let type_alias = for_. def_id ( ) . and_then ( |did| match cx. tcx . def_kind ( did) {
2030
- DefKind :: TyAlias => Some ( cx. tcx . type_of ( did) . clean ( cx) ) ,
2031
- _ => None ,
2014
+ _ => unreachable ! ( ) ,
2015
+ } ;
2016
+ let trait_ = trait_. clean ( cx) ;
2017
+ let items = items. iter ( ) . map ( |ii| cx. tcx . hir ( ) . impl_item ( ii. id ) . clean ( cx) ) . collect :: < Vec < _ > > ( ) ;
2018
+ let def_id = cx. tcx . hir ( ) . local_def_id ( impl_. hir_id ) ;
2019
+
2020
+ // If this impl block is an implementation of the Deref trait, then we
2021
+ // need to try inlining the target's inherent impl blocks as well.
2022
+ if trait_. def_id ( ) == cx. tcx . lang_items ( ) . deref_trait ( ) {
2023
+ build_deref_target_impls ( cx, & items, & mut ret) ;
2024
+ }
2025
+
2026
+ let provided: FxHashSet < String > = trait_
2027
+ . def_id ( )
2028
+ . map ( |did| cx. tcx . provided_trait_methods ( did) . map ( |meth| meth. ident . to_string ( ) ) . collect ( ) )
2029
+ . unwrap_or_default ( ) ;
2030
+
2031
+ let for_ = for_. clean ( cx) ;
2032
+ let type_alias = for_. def_id ( ) . and_then ( |did| match cx. tcx . def_kind ( did) {
2033
+ DefKind :: TyAlias => Some ( cx. tcx . type_of ( did) . clean ( cx) ) ,
2034
+ _ => None ,
2035
+ } ) ;
2036
+ let make_item = |trait_ : Option < Type > , for_ : Type , items : Vec < Item > | {
2037
+ let kind = ImplItem ( Impl {
2038
+ unsafety,
2039
+ generics : generics. clean ( cx) ,
2040
+ provided_trait_methods : provided. clone ( ) ,
2041
+ trait_,
2042
+ for_,
2043
+ items,
2044
+ polarity : Some ( cx. tcx . impl_polarity ( def_id) . clean ( cx) ) ,
2045
+ synthetic : false ,
2046
+ blanket_impl : None ,
2032
2047
} ) ;
2033
- let make_item = |trait_ : Option < Type > , for_ : Type , items : Vec < Item > | Item {
2034
- name : None ,
2035
- attrs : self . attrs . clean ( cx) ,
2036
- source : self . span . clean ( cx) ,
2037
- def_id : def_id. to_def_id ( ) ,
2038
- visibility : self . vis . clean ( cx) ,
2039
- stability : cx. stability ( self . id ) ,
2040
- deprecation : cx. deprecation ( self . id ) . clean ( cx) ,
2041
- kind : ImplItem ( Impl {
2042
- unsafety : self . unsafety ,
2043
- generics : self . generics . clean ( cx) ,
2044
- provided_trait_methods : provided. clone ( ) ,
2045
- trait_,
2046
- for_,
2047
- items,
2048
- polarity : Some ( cx. tcx . impl_polarity ( def_id) . clean ( cx) ) ,
2049
- synthetic : false ,
2050
- blanket_impl : None ,
2051
- } ) ,
2052
- } ;
2053
- if let Some ( type_alias) = type_alias {
2054
- ret. push ( make_item ( trait_. clone ( ) , type_alias, items. clone ( ) ) ) ;
2055
- }
2056
- ret. push ( make_item ( trait_, for_, items) ) ;
2057
- ret
2048
+ Item :: from_hir_id_and_parts ( impl_. hir_id , None , kind, cx)
2049
+ } ;
2050
+ if let Some ( type_alias) = type_alias {
2051
+ ret. push ( make_item ( trait_. clone ( ) , type_alias, items. clone ( ) ) ) ;
2058
2052
}
2053
+ ret. push ( make_item ( trait_, for_, items) ) ;
2054
+ ret
2059
2055
}
2060
2056
2061
2057
impl Clean < Vec < Item > > for doctree:: ExternCrate < ' _ > {
0 commit comments