@@ -36,6 +36,7 @@ use std::mem;
36
36
37
37
use rustc_ast:: token:: { Token , TokenKind } ;
38
38
use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
39
+ use rustc_attr_data_structures:: { AttributeKind , find_attr} ;
39
40
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap , FxIndexSet , IndexEntry } ;
40
41
use rustc_errors:: codes:: * ;
41
42
use rustc_errors:: { FatalError , struct_span_code_err} ;
@@ -987,28 +988,17 @@ fn clean_proc_macro<'tcx>(
987
988
kind : MacroKind ,
988
989
cx : & mut DocContext < ' tcx > ,
989
990
) -> 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 ! [ ] } ) ;
996
993
}
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 ( ) ;
997
1001
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
- }
1012
1002
ProcMacroItem ( ProcMacro { kind, helpers } )
1013
1003
}
1014
1004
@@ -1021,17 +1011,16 @@ fn clean_fn_or_proc_macro<'tcx>(
1021
1011
cx : & mut DocContext < ' tcx > ,
1022
1012
) -> ItemKind {
1023
1013
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
+
1035
1024
match macro_kind {
1036
1025
Some ( kind) => clean_proc_macro ( item, name, kind, cx) ,
1037
1026
None => {
0 commit comments