@@ -12,7 +12,7 @@ use rustc_metadata::creader::{CStore, LoadedMacro};
1212use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
1313use rustc_middle:: ty:: { self , TyCtxt } ;
1414use rustc_span:: def_id:: LOCAL_CRATE ;
15- use rustc_span:: hygiene:: MacroKind ;
15+ use rustc_span:: hygiene:: { MacroKind , MacroKinds } ;
1616use rustc_span:: symbol:: { Symbol , sym} ;
1717use thin_vec:: { ThinVec , thin_vec} ;
1818use tracing:: { debug, trace} ;
@@ -137,13 +137,16 @@ pub(crate) fn try_inline(
137137 clean:: ConstantItem ( Box :: new ( ct) )
138138 } )
139139 }
140- Res :: Def ( DefKind :: Macro ( kind) , did) => {
141- let mac = build_macro ( cx, did, name, kind) ;
142-
143- let type_kind = match kind {
144- MacroKind :: Bang => ItemType :: Macro ,
145- MacroKind :: Attr => ItemType :: ProcAttribute ,
146- MacroKind :: Derive => ItemType :: ProcDerive ,
140+ Res :: Def ( DefKind :: Macro ( kinds) , did) => {
141+ let mac = build_macro ( cx, did, name, kinds) ;
142+
143+ // FIXME: handle attributes and derives that aren't proc macros, and macros with
144+ // multiple kinds
145+ let type_kind = match kinds {
146+ MacroKinds :: BANG => ItemType :: Macro ,
147+ MacroKinds :: ATTR => ItemType :: ProcAttribute ,
148+ MacroKinds :: DERIVE => ItemType :: ProcDerive ,
149+ _ => todo ! ( "Handle macros with multiple kinds" ) ,
147150 } ;
148151 record_extern_fqn ( cx, did, type_kind) ;
149152 mac
@@ -749,22 +752,36 @@ fn build_macro(
749752 cx : & mut DocContext < ' _ > ,
750753 def_id : DefId ,
751754 name : Symbol ,
752- macro_kind : MacroKind ,
755+ macro_kinds : MacroKinds ,
753756) -> clean:: ItemKind {
754757 match CStore :: from_tcx ( cx. tcx ) . load_macro_untracked ( def_id, cx. tcx ) {
755- LoadedMacro :: MacroDef { def, .. } => match macro_kind {
756- MacroKind :: Bang => clean:: MacroItem ( clean:: Macro {
758+ // FIXME: handle attributes and derives that aren't proc macros, and macros with multiple
759+ // kinds
760+ LoadedMacro :: MacroDef { def, .. } => match macro_kinds {
761+ MacroKinds :: BANG => clean:: MacroItem ( clean:: Macro {
757762 source : utils:: display_macro_source ( cx, name, & def) ,
758763 macro_rules : def. macro_rules ,
759764 } ) ,
760- MacroKind :: Derive | MacroKind :: Attr => {
761- clean:: ProcMacroItem ( clean:: ProcMacro { kind : macro_kind, helpers : Vec :: new ( ) } )
762- }
765+ MacroKinds :: DERIVE => clean:: ProcMacroItem ( clean:: ProcMacro {
766+ kind : MacroKind :: Derive ,
767+ helpers : Vec :: new ( ) ,
768+ } ) ,
769+ MacroKinds :: ATTR => clean:: ProcMacroItem ( clean:: ProcMacro {
770+ kind : MacroKind :: Attr ,
771+ helpers : Vec :: new ( ) ,
772+ } ) ,
773+ _ => todo ! ( "Handle macros with multiple kinds" ) ,
763774 } ,
764- LoadedMacro :: ProcMacro ( ext) => clean:: ProcMacroItem ( clean:: ProcMacro {
765- kind : ext. macro_kind ( ) ,
766- helpers : ext. helper_attrs ,
767- } ) ,
775+ LoadedMacro :: ProcMacro ( ext) => {
776+ // Proc macros can only have a single kind
777+ let kind = match ext. macro_kinds ( ) {
778+ MacroKinds :: BANG => MacroKind :: Bang ,
779+ MacroKinds :: ATTR => MacroKind :: Attr ,
780+ MacroKinds :: DERIVE => MacroKind :: Derive ,
781+ _ => unreachable ! ( ) ,
782+ } ;
783+ clean:: ProcMacroItem ( clean:: ProcMacro { kind, helpers : ext. helper_attrs } )
784+ }
768785 }
769786}
770787
0 commit comments