@@ -234,9 +234,8 @@ impl Clean<Item> for doctree::Module<'_> {
234234 items. extend ( self . fns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
235235 items. extend ( self . foreigns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
236236 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 ( ) ) ;
238238 items. extend ( self . traits . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
239- items. extend ( self . impls . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ;
240239 items. extend ( self . macros . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
241240 items. extend ( self . proc_macros . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
242241
@@ -1922,8 +1921,8 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
19221921 }
19231922}
19241923
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 > {
19271926 use hir:: ItemKind ;
19281927
19291928 let ( item, renamed) = self ;
@@ -1977,10 +1976,11 @@ impl Clean<Item> for (&hir::Item<'_>, Option<Ident>) {
19771976 fields : variant_data. fields ( ) . clean ( cx) ,
19781977 fields_stripped : false ,
19791978 } ) ,
1979+ ItemKind :: Impl { .. } => return clean_impl ( item, cx) ,
19801980 _ => unreachable ! ( "not yet converted" ) ,
19811981 } ;
19821982
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) ]
19841984 }
19851985}
19861986
@@ -2005,57 +2005,53 @@ impl Clean<ImplPolarity> for ty::ImplPolarity {
20052005 }
20062006}
20072007
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)
20192013 }
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 ,
20322047 } ) ;
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 ( ) ) ) ;
20582052 }
2053+ ret. push ( make_item ( trait_, for_, items) ) ;
2054+ ret
20592055}
20602056
20612057impl Clean < Vec < Item > > for doctree:: ExternCrate < ' _ > {
0 commit comments