@@ -231,13 +231,11 @@ impl Clean<Item> for doctree::Module<'_> {
231231 let mut items: Vec < Item > = vec ! [ ] ;
232232 items. extend ( self . extern_crates . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ;
233233 items. extend ( self . imports . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ;
234- items. extend ( self . fns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
235234 items. extend ( self . foreigns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
236235 items. extend ( self . mods . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
237236 items. extend ( self . items . iter ( ) . map ( |x| x. clean ( cx) ) . flatten ( ) ) ;
238237 items. extend ( self . traits . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
239238 items. extend ( self . macros . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
240- items. extend ( self . proc_macros . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
241239
242240 // determine if we should display the inner contents or
243241 // the outer `mod` item for the source code.
@@ -871,6 +869,66 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
871869 }
872870}
873871
872+ fn clean_fn_or_proc_macro (
873+ item : & hir:: Item < ' _ > ,
874+ sig : & ' a hir:: FnSig < ' a > ,
875+ generics : & ' a hir:: Generics < ' a > ,
876+ body_id : hir:: BodyId ,
877+ name : & mut Symbol ,
878+ cx : & DocContext < ' _ > ,
879+ ) -> ItemKind {
880+ let macro_kind = item. attrs . iter ( ) . find_map ( |a| {
881+ if a. has_name ( sym:: proc_macro) {
882+ Some ( MacroKind :: Bang )
883+ } else if a. has_name ( sym:: proc_macro_derive) {
884+ Some ( MacroKind :: Derive )
885+ } else if a. has_name ( sym:: proc_macro_attribute) {
886+ Some ( MacroKind :: Attr )
887+ } else {
888+ None
889+ }
890+ } ) ;
891+ match macro_kind {
892+ Some ( kind) => {
893+ if kind == MacroKind :: Derive {
894+ * name = item
895+ . attrs
896+ . lists ( sym:: proc_macro_derive)
897+ . find_map ( |mi| mi. ident ( ) )
898+ . expect ( "proc-macro derives require a name" )
899+ . name ;
900+ }
901+
902+ let mut helpers = Vec :: new ( ) ;
903+ for mi in item. attrs . lists ( sym:: proc_macro_derive) {
904+ if !mi. has_name ( sym:: attributes) {
905+ continue ;
906+ }
907+
908+ if let Some ( list) = mi. meta_item_list ( ) {
909+ for inner_mi in list {
910+ if let Some ( ident) = inner_mi. ident ( ) {
911+ helpers. push ( ident. name ) ;
912+ }
913+ }
914+ }
915+ }
916+ ProcMacroItem ( ProcMacro { kind, helpers : helpers. clean ( cx) } )
917+ }
918+ None => {
919+ let mut func = ( sig, generics, body_id) . clean ( cx) ;
920+ let def_id = cx. tcx . hir ( ) . local_def_id ( item. hir_id ) . to_def_id ( ) ;
921+ func. header . constness =
922+ if is_const_fn ( cx. tcx , def_id) && is_unstable_const_fn ( cx. tcx , def_id) . is_none ( ) {
923+ hir:: Constness :: Const
924+ } else {
925+ hir:: Constness :: NotConst
926+ } ;
927+ FunctionItem ( func)
928+ }
929+ }
930+ }
931+
874932impl < ' a > Clean < Function > for ( & ' a hir:: FnSig < ' a > , & ' a hir:: Generics < ' a > , hir:: BodyId ) {
875933 fn clean ( & self , cx : & DocContext < ' _ > ) -> Function {
876934 let ( generics, decl) =
@@ -880,34 +938,6 @@ impl<'a> Clean<Function> for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::Bo
880938 }
881939}
882940
883- impl Clean < Item > for doctree:: Function < ' _ > {
884- fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
885- let ( generics, decl) =
886- enter_impl_trait ( cx, || ( self . generics . clean ( cx) , ( self . decl , self . body ) . clean ( cx) ) ) ;
887-
888- let did = cx. tcx . hir ( ) . local_def_id ( self . id ) . to_def_id ( ) ;
889- let constness = if is_const_fn ( cx. tcx , did) && !is_unstable_const_fn ( cx. tcx , did) . is_some ( )
890- {
891- hir:: Constness :: Const
892- } else {
893- hir:: Constness :: NotConst
894- } ;
895- let ( all_types, ret_types) = get_all_types ( & generics, & decl, cx) ;
896- Item :: from_def_id_and_parts (
897- did,
898- Some ( self . name ) ,
899- FunctionItem ( Function {
900- decl,
901- generics,
902- header : hir:: FnHeader { constness, ..self . header } ,
903- all_types,
904- ret_types,
905- } ) ,
906- cx,
907- )
908- }
909- }
910-
911941impl < ' a > Clean < Arguments > for ( & ' a [ hir:: Ty < ' a > ] , & ' a [ Ident ] ) {
912942 fn clean ( & self , cx : & DocContext < ' _ > ) -> Arguments {
913943 Arguments {
@@ -1927,7 +1957,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
19271957
19281958 let ( item, renamed) = self ;
19291959 let def_id = cx. tcx . hir ( ) . local_def_id ( item. hir_id ) . to_def_id ( ) ;
1930- let name = match renamed {
1960+ let mut name = match renamed {
19311961 Some ( ident) => ident. name ,
19321962 None => cx. tcx . hir ( ) . name ( item. hir_id ) ,
19331963 } ;
@@ -1977,6 +2007,10 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
19772007 fields_stripped : false ,
19782008 } ) ,
19792009 ItemKind :: Impl { .. } => return clean_impl ( item, cx) ,
2010+ // proc macros can have a name set by attributes
2011+ ItemKind :: Fn ( ref sig, ref generics, body_id) => {
2012+ clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
2013+ }
19802014 _ => unreachable ! ( "not yet converted" ) ,
19812015 } ;
19822016
@@ -2239,17 +2273,6 @@ impl Clean<Item> for doctree::Macro {
22392273 }
22402274}
22412275
2242- impl Clean < Item > for doctree:: ProcMacro {
2243- fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
2244- Item :: from_hir_id_and_parts (
2245- self . id ,
2246- Some ( self . name ) ,
2247- ProcMacroItem ( ProcMacro { kind : self . kind , helpers : self . helpers . clean ( cx) } ) ,
2248- cx,
2249- )
2250- }
2251- }
2252-
22532276impl Clean < Deprecation > for attr:: Deprecation {
22542277 fn clean ( & self , _: & DocContext < ' _ > ) -> Deprecation {
22552278 Deprecation {
0 commit comments