44use std:: collections:: hash_map:: Entry ;
55
66use base_db:: CrateId ;
7- use hir_expand:: name:: Name ;
8- use hir_expand:: MacroDefKind ;
7+ use hir_expand:: { name:: Name , AstId , MacroCallId , MacroDefKind } ;
98use once_cell:: sync:: Lazy ;
109use rustc_hash:: { FxHashMap , FxHashSet } ;
1110use stdx:: format_to;
11+ use syntax:: ast;
1212
1313use crate :: {
1414 db:: DefDatabase , per_ns:: PerNs , visibility:: Visibility , AdtId , BuiltinType , ConstId , ImplId ,
@@ -53,6 +53,7 @@ pub struct ItemScope {
5353 // FIXME: Macro shadowing in one module is not properly handled. Non-item place macros will
5454 // be all resolved to the last one defined if shadowing happens.
5555 legacy_macros : FxHashMap < Name , MacroDefId > ,
56+ attr_macros : FxHashMap < AstId < ast:: Item > , MacroCallId > ,
5657}
5758
5859pub ( crate ) static BUILTIN_SCOPE : Lazy < FxHashMap < Name , PerNs > > = Lazy :: new ( || {
@@ -169,6 +170,16 @@ impl ItemScope {
169170 self . legacy_macros . insert ( name, mac) ;
170171 }
171172
173+ pub ( crate ) fn add_attr_macro_invoc ( & mut self , item : AstId < ast:: Item > , call : MacroCallId ) {
174+ self . attr_macros . insert ( item, call) ;
175+ }
176+
177+ pub ( crate ) fn attr_macro_invocs (
178+ & self ,
179+ ) -> impl Iterator < Item = ( AstId < ast:: Item > , MacroCallId ) > + ' _ {
180+ self . attr_macros . iter ( ) . map ( |( k, v) | ( * k, * v) )
181+ }
182+
172183 pub ( crate ) fn unnamed_trait_vis ( & self , tr : TraitId ) -> Option < Visibility > {
173184 self . unnamed_trait_imports . get ( & tr) . copied ( )
174185 }
@@ -307,6 +318,7 @@ impl ItemScope {
307318 unnamed_consts,
308319 unnamed_trait_imports,
309320 legacy_macros,
321+ attr_macros,
310322 } = self ;
311323 types. shrink_to_fit ( ) ;
312324 values. shrink_to_fit ( ) ;
@@ -317,6 +329,7 @@ impl ItemScope {
317329 unnamed_consts. shrink_to_fit ( ) ;
318330 unnamed_trait_imports. shrink_to_fit ( ) ;
319331 legacy_macros. shrink_to_fit ( ) ;
332+ attr_macros. shrink_to_fit ( ) ;
320333 }
321334}
322335
0 commit comments