@@ -909,6 +909,38 @@ fn clean_ty_generics<'tcx>(
909
909
}
910
910
}
911
911
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
+
912
944
fn clean_fn_or_proc_macro < ' tcx > (
913
945
item : & hir:: Item < ' tcx > ,
914
946
sig : & hir:: FnSig < ' tcx > ,
@@ -930,31 +962,7 @@ fn clean_fn_or_proc_macro<'tcx>(
930
962
}
931
963
} ) ;
932
964
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) ,
958
966
None => {
959
967
let mut func = clean_function ( cx, sig, generics, FunctionArgs :: Body ( body_id) ) ;
960
968
clean_fn_decl_legacy_const_generics ( & mut func, attrs) ;
@@ -2247,16 +2255,17 @@ fn clean_maybe_renamed_item<'tcx>(
2247
2255
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
2248
2256
} ) ,
2249
2257
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 ) => {
2255
2259
let ty_vis = cx. tcx . visibility ( def_id) ;
2256
2260
MacroItem ( Macro {
2257
2261
source : display_macro_source ( cx, name, macro_def, def_id, ty_vis) ,
2258
2262
} )
2259
2263
}
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
+ }
2260
2269
ItemKind :: Trait ( _, _, generics, bounds, item_ids) => {
2261
2270
let items = item_ids
2262
2271
. iter ( )
0 commit comments