@@ -36,6 +36,7 @@ use std::mem;
3636
3737use rustc_ast:: token:: { Token , TokenKind } ;
3838use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
39+ use rustc_attr_data_structures:: { AttributeKind , find_attr} ;
3940use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap , FxIndexSet , IndexEntry } ;
4041use rustc_errors:: codes:: * ;
4142use rustc_errors:: { FatalError , struct_span_code_err} ;
@@ -987,28 +988,17 @@ fn clean_proc_macro<'tcx>(
987988 kind : MacroKind ,
988989 cx : & mut DocContext < ' tcx > ,
989990) -> ItemKind {
990- let attrs = cx. tcx . hir_attrs ( item. hir_id ( ) ) ;
991- if kind == MacroKind :: Derive
992- && let Some ( derive_name) =
993- hir_attr_lists ( attrs, sym:: proc_macro_derive) . find_map ( |mi| mi. ident ( ) )
994- {
995- * name = derive_name. name ;
991+ if kind != MacroKind :: Derive {
992+ return ProcMacroItem ( ProcMacro { kind, helpers : vec ! [ ] } ) ;
996993 }
994+ let attrs = cx. tcx . hir_attrs ( item. hir_id ( ) ) ;
995+ let Some ( ( trait_name, helper_attrs) ) = find_attr ! ( attrs, AttributeKind :: ProcMacroDerive { trait_name, helper_attrs, ..} => ( * trait_name, helper_attrs) )
996+ else {
997+ return ProcMacroItem ( ProcMacro { kind, helpers : vec ! [ ] } ) ;
998+ } ;
999+ * name = trait_name;
1000+ let helpers = helper_attrs. iter ( ) . copied ( ) . collect ( ) ;
9971001
998- let mut helpers = Vec :: new ( ) ;
999- for mi in hir_attr_lists ( attrs, sym:: proc_macro_derive) {
1000- if !mi. has_name ( sym:: attributes) {
1001- continue ;
1002- }
1003-
1004- if let Some ( list) = mi. meta_item_list ( ) {
1005- for inner_mi in list {
1006- if let Some ( ident) = inner_mi. ident ( ) {
1007- helpers. push ( ident. name ) ;
1008- }
1009- }
1010- }
1011- }
10121002 ProcMacroItem ( ProcMacro { kind, helpers } )
10131003}
10141004
@@ -1021,17 +1011,16 @@ fn clean_fn_or_proc_macro<'tcx>(
10211011 cx : & mut DocContext < ' tcx > ,
10221012) -> ItemKind {
10231013 let attrs = cx. tcx . hir_attrs ( item. hir_id ( ) ) ;
1024- let macro_kind = attrs. iter ( ) . find_map ( |a| {
1025- if a. has_name ( sym:: proc_macro) {
1026- Some ( MacroKind :: Bang )
1027- } else if a. has_name ( sym:: proc_macro_derive) {
1028- Some ( MacroKind :: Derive )
1029- } else if a. has_name ( sym:: proc_macro_attribute) {
1030- Some ( MacroKind :: Attr )
1031- } else {
1032- None
1033- }
1034- } ) ;
1014+ let macro_kind = if find_attr ! ( attrs, AttributeKind :: ProcMacro ( ..) ) {
1015+ Some ( MacroKind :: Bang )
1016+ } else if find_attr ! ( attrs, AttributeKind :: ProcMacroDerive { .. } ) {
1017+ Some ( MacroKind :: Derive )
1018+ } else if find_attr ! ( attrs, AttributeKind :: ProcMacroAttribute ( ..) ) {
1019+ Some ( MacroKind :: Attr )
1020+ } else {
1021+ None
1022+ } ;
1023+
10351024 match macro_kind {
10361025 Some ( kind) => clean_proc_macro ( item, name, kind, cx) ,
10371026 None => {
0 commit comments