@@ -12,8 +12,8 @@ use stdx::format_to;
1212use syntax:: ast;
1313
1414use crate :: {
15- db:: DefDatabase , per_ns:: PerNs , visibility:: Visibility , AdtId , BuiltinType , ConstId , ImplId ,
16- LocalModuleId , MacroDefId , ModuleDefId , ModuleId , TraitId ,
15+ attr :: AttrId , db:: DefDatabase , per_ns:: PerNs , visibility:: Visibility , AdtId , BuiltinType ,
16+ ConstId , ImplId , LocalModuleId , MacroDefId , ModuleDefId , ModuleId , TraitId ,
1717} ;
1818
1919#[ derive( Copy , Clone ) ]
@@ -61,6 +61,7 @@ pub struct ItemScope {
6161 // be all resolved to the last one defined if shadowing happens.
6262 legacy_macros : FxHashMap < Name , MacroDefId > ,
6363 attr_macros : FxHashMap < AstId < ast:: Item > , MacroCallId > ,
64+ derive_macros : FxHashMap < AstId < ast:: Item > , ( AttrId , MacroCallId ) > ,
6465}
6566
6667pub ( crate ) static BUILTIN_SCOPE : Lazy < FxHashMap < Name , PerNs > > = Lazy :: new ( || {
@@ -182,6 +183,21 @@ impl ItemScope {
182183 self . attr_macros . iter ( ) . map ( |( k, v) | ( * k, * v) )
183184 }
184185
186+ pub ( crate ) fn add_derive_macro_invoc (
187+ & mut self ,
188+ item : AstId < ast:: Item > ,
189+ call : MacroCallId ,
190+ attr_id : AttrId ,
191+ ) {
192+ self . derive_macros . insert ( item, ( attr_id, call) ) ;
193+ }
194+
195+ pub ( crate ) fn derive_macro_invocs (
196+ & self ,
197+ ) -> impl Iterator < Item = ( AstId < ast:: Item > , ( AttrId , MacroCallId ) ) > + ' _ {
198+ self . derive_macros . iter ( ) . map ( |( k, v) | ( * k, * v) )
199+ }
200+
185201 pub ( crate ) fn unnamed_trait_vis ( & self , tr : TraitId ) -> Option < Visibility > {
186202 self . unnamed_trait_imports . get ( & tr) . copied ( )
187203 }
@@ -320,6 +336,7 @@ impl ItemScope {
320336 unnamed_trait_imports,
321337 legacy_macros,
322338 attr_macros,
339+ derive_macros,
323340 } = self ;
324341 types. shrink_to_fit ( ) ;
325342 values. shrink_to_fit ( ) ;
@@ -331,6 +348,7 @@ impl ItemScope {
331348 unnamed_trait_imports. shrink_to_fit ( ) ;
332349 legacy_macros. shrink_to_fit ( ) ;
333350 attr_macros. shrink_to_fit ( ) ;
351+ derive_macros. shrink_to_fit ( ) ;
334352 }
335353}
336354
0 commit comments