@@ -909,6 +909,38 @@ fn clean_ty_generics<'tcx>(
909909 }
910910}
911911
912+ fn clean_proc_macro < ' tcx > (
913+ item : & hir:: Item < ' tcx > ,
914+ name : & mut Symbol ,
915+ kind : MacroKind ,
916+ cx : & mut DocContext < ' tcx > ,
917+ ) -> ItemKind {
918+ let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
919+ if kind == MacroKind :: Derive &&
920+ let Some ( derive_name) = attrs
921+ . lists ( sym:: proc_macro_derive)
922+ . find_map ( |mi| mi. ident ( ) )
923+ {
924+ * name = derive_name. name ;
925+ }
926+
927+ let mut helpers = Vec :: new ( ) ;
928+ for mi in attrs. lists ( sym:: proc_macro_derive) {
929+ if !mi. has_name ( sym:: attributes) {
930+ continue ;
931+ }
932+
933+ if let Some ( list) = mi. meta_item_list ( ) {
934+ for inner_mi in list {
935+ if let Some ( ident) = inner_mi. ident ( ) {
936+ helpers. push ( ident. name ) ;
937+ }
938+ }
939+ }
940+ }
941+ ProcMacroItem ( ProcMacro { kind, helpers } )
942+ }
943+
912944fn clean_fn_or_proc_macro < ' tcx > (
913945 item : & hir:: Item < ' tcx > ,
914946 sig : & hir:: FnSig < ' tcx > ,
@@ -930,31 +962,7 @@ fn clean_fn_or_proc_macro<'tcx>(
930962 }
931963 } ) ;
932964 match macro_kind {
933- Some ( kind) => {
934- if kind == MacroKind :: Derive {
935- * name = attrs
936- . lists ( sym:: proc_macro_derive)
937- . find_map ( |mi| mi. ident ( ) )
938- . expect ( "proc-macro derives require a name" )
939- . name ;
940- }
941-
942- let mut helpers = Vec :: new ( ) ;
943- for mi in attrs. lists ( sym:: proc_macro_derive) {
944- if !mi. has_name ( sym:: attributes) {
945- continue ;
946- }
947-
948- if let Some ( list) = mi. meta_item_list ( ) {
949- for inner_mi in list {
950- if let Some ( ident) = inner_mi. ident ( ) {
951- helpers. push ( ident. name ) ;
952- }
953- }
954- }
955- }
956- ProcMacroItem ( ProcMacro { kind, helpers } )
957- }
965+ Some ( kind) => clean_proc_macro ( item, name, kind, cx) ,
958966 None => {
959967 let mut func = clean_function ( cx, sig, generics, FunctionArgs :: Body ( body_id) ) ;
960968 clean_fn_decl_legacy_const_generics ( & mut func, attrs) ;
@@ -2247,16 +2255,17 @@ fn clean_maybe_renamed_item<'tcx>(
22472255 fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
22482256 } ) ,
22492257 ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. owner_id . def_id , cx) ,
2250- // proc macros can have a name set by attributes
2251- ItemKind :: Fn ( ref sig, generics, body_id) => {
2252- clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
2253- }
2254- ItemKind :: Macro ( ref macro_def, _) => {
2258+ ItemKind :: Macro ( ref macro_def, MacroKind :: Bang ) => {
22552259 let ty_vis = cx. tcx . visibility ( def_id) ;
22562260 MacroItem ( Macro {
22572261 source : display_macro_source ( cx, name, macro_def, def_id, ty_vis) ,
22582262 } )
22592263 }
2264+ ItemKind :: Macro ( _, macro_kind) => clean_proc_macro ( item, & mut name, macro_kind, cx) ,
2265+ // proc macros can have a name set by attributes
2266+ ItemKind :: Fn ( ref sig, generics, body_id) => {
2267+ clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
2268+ }
22602269 ItemKind :: Trait ( _, _, generics, bounds, item_ids) => {
22612270 let items = item_ids
22622271 . iter ( )
0 commit comments