@@ -77,7 +77,7 @@ use tt::TextRange;
7777
7878use crate :: {
7979 AstId , BlockId , BlockLoc , CrateRootModuleId , ExternCrateId , FunctionId , FxIndexMap ,
80- LocalModuleId , Lookup , MacroExpander , MacroId , ModuleId , ProcMacroId , UseId ,
80+ LocalModuleId , Lookup , MacroCallStyles , MacroExpander , MacroId , ModuleId , ProcMacroId , UseId ,
8181 db:: DefDatabase ,
8282 item_scope:: { BuiltinShadowMode , ItemScope } ,
8383 item_tree:: TreeId ,
@@ -813,26 +813,25 @@ pub enum MacroSubNs {
813813 Attr ,
814814}
815815
816- impl MacroSubNs {
817- pub ( crate ) fn from_id ( db : & dyn DefDatabase , macro_id : MacroId ) -> Self {
818- let expander = match macro_id {
819- MacroId :: Macro2Id ( it) => it. lookup ( db) . expander ,
820- MacroId :: MacroRulesId ( it) => it . lookup ( db ) . expander ,
821- MacroId :: ProcMacroId ( it ) => {
822- return match it . lookup ( db ) . kind {
823- ProcMacroKind :: CustomDerive | ProcMacroKind :: Attr => Self :: Attr ,
824- ProcMacroKind :: Bang => Self :: Bang ,
825- } ;
826- }
827- } ;
816+ pub ( crate ) fn macro_styles_from_id ( db : & dyn DefDatabase , macro_id : MacroId ) -> MacroCallStyles {
817+ let expander = match macro_id {
818+ MacroId :: Macro2Id ( it ) => it . lookup ( db ) . expander ,
819+ MacroId :: MacroRulesId ( it) => it. lookup ( db) . expander ,
820+ MacroId :: ProcMacroId ( it) => {
821+ return match it . lookup ( db ) . kind {
822+ ProcMacroKind :: CustomDerive => MacroCallStyles :: DERIVE ,
823+ ProcMacroKind :: Bang => MacroCallStyles :: FN_LIKE ,
824+ ProcMacroKind :: Attr => MacroCallStyles :: ATTR ,
825+ } ;
826+ }
827+ } ;
828828
829+ match expander {
830+ MacroExpander :: Declarative { styles } => styles,
829831 // Eager macros aren't *guaranteed* to be bang macros, but they *are* all bang macros currently.
830- match expander {
831- MacroExpander :: Declarative
832- | MacroExpander :: BuiltIn ( _)
833- | MacroExpander :: BuiltInEager ( _) => Self :: Bang ,
834- MacroExpander :: BuiltInAttr ( _) | MacroExpander :: BuiltInDerive ( _) => Self :: Attr ,
835- }
832+ MacroExpander :: BuiltIn ( _) | MacroExpander :: BuiltInEager ( _) => MacroCallStyles :: FN_LIKE ,
833+ MacroExpander :: BuiltInAttr ( _) => MacroCallStyles :: ATTR ,
834+ MacroExpander :: BuiltInDerive ( _) => MacroCallStyles :: DERIVE ,
836835 }
837836}
838837
@@ -847,9 +846,14 @@ fn sub_namespace_match(
847846 macro_id : MacroId ,
848847 expected : Option < MacroSubNs > ,
849848) -> bool {
850- let candidate = MacroSubNs :: from_id ( db, macro_id) ;
849+ let candidate = macro_styles_from_id ( db, macro_id) ;
851850 match expected {
852- Some ( expected) => candidate == expected,
851+ Some ( MacroSubNs :: Bang ) => candidate. contains ( MacroCallStyles :: FN_LIKE ) ,
852+ Some ( MacroSubNs :: Attr ) => {
853+ candidate. contains ( MacroCallStyles :: ATTR ) || candidate. contains ( MacroCallStyles :: DERIVE )
854+ }
855+ // If we aren't expecting a specific sub-namespace
856+ // (e.g. in `use` declarations), match any macro.
853857 None => true ,
854858 }
855859}
0 commit comments