@@ -10,7 +10,9 @@ use crate::imports::{Import, ImportKind};
1010use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
1111use crate :: Namespace :: { self , MacroNS , TypeNS , ValueNS } ;
1212use crate :: { Determinacy , ExternPreludeEntry , Finalize , Module , ModuleKind , ModuleOrUniformRoot } ;
13- use crate :: { NameBinding , NameBindingKind , ParentScope , PathResult , PerNS , ResolutionError } ;
13+ use crate :: {
14+ MacroData , NameBinding , NameBindingKind , ParentScope , PathResult , PerNS , ResolutionError ,
15+ } ;
1416use crate :: { Resolver , ResolverArenas , Segment , ToNameBinding , VisResolutionError } ;
1517
1618use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
@@ -20,7 +22,6 @@ use rustc_ast_lowering::ResolverAstLowering;
2022use rustc_attr as attr;
2123use rustc_data_structures:: sync:: Lrc ;
2224use rustc_errors:: { struct_span_err, Applicability } ;
23- use rustc_expand:: base:: SyntaxExtension ;
2425use rustc_expand:: expand:: AstFragment ;
2526use rustc_hir:: def:: { self , * } ;
2627use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID } ;
@@ -180,26 +181,32 @@ impl<'a> Resolver<'a> {
180181 }
181182 }
182183
183- pub ( crate ) fn get_macro ( & mut self , res : Res ) -> Option < Lrc < SyntaxExtension > > {
184+ pub ( crate ) fn get_macro ( & mut self , res : Res ) -> Option < MacroData > {
184185 match res {
185186 Res :: Def ( DefKind :: Macro ( ..) , def_id) => Some ( self . get_macro_by_def_id ( def_id) ) ,
186- Res :: NonMacroAttr ( _) => Some ( self . non_macro_attr . clone ( ) ) ,
187+ Res :: NonMacroAttr ( _) => {
188+ Some ( MacroData { ext : self . non_macro_attr . clone ( ) , macro_rules : false } )
189+ }
187190 _ => None ,
188191 }
189192 }
190193
191- pub ( crate ) fn get_macro_by_def_id ( & mut self , def_id : DefId ) -> Lrc < SyntaxExtension > {
192- if let Some ( ext ) = self . macro_map . get ( & def_id) {
193- return ext . clone ( ) ;
194+ pub ( crate ) fn get_macro_by_def_id ( & mut self , def_id : DefId ) -> MacroData {
195+ if let Some ( macro_data ) = self . macro_map . get ( & def_id) {
196+ return macro_data . clone ( ) ;
194197 }
195198
196- let ext = Lrc :: new ( match self . cstore ( ) . load_macro_untracked ( def_id, & self . session ) {
197- LoadedMacro :: MacroDef ( item, edition) => self . compile_macro ( & item, edition) . 0 ,
198- LoadedMacro :: ProcMacro ( ext) => ext,
199- } ) ;
199+ let ( ext, macro_rules) = match self . cstore ( ) . load_macro_untracked ( def_id, & self . session ) {
200+ LoadedMacro :: MacroDef ( item, edition) => (
201+ Lrc :: new ( self . compile_macro ( & item, edition) . 0 ) ,
202+ matches ! ( item. kind, ItemKind :: MacroDef ( def) if def. macro_rules) ,
203+ ) ,
204+ LoadedMacro :: ProcMacro ( extz) => ( Lrc :: new ( extz) , false ) ,
205+ } ;
200206
201- self . macro_map . insert ( def_id, ext. clone ( ) ) ;
202- ext
207+ let macro_data = MacroData { ext, macro_rules } ;
208+ self . macro_map . insert ( def_id, macro_data. clone ( ) ) ;
209+ macro_data
203210 }
204211
205212 pub ( crate ) fn build_reduced_graph (
@@ -1251,7 +1258,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12511258 } ;
12521259
12531260 let res = Res :: Def ( DefKind :: Macro ( ext. macro_kind ( ) ) , def_id. to_def_id ( ) ) ;
1254- self . r . macro_map . insert ( def_id. to_def_id ( ) , ext) ;
1261+ self . r . macro_map . insert ( def_id. to_def_id ( ) , MacroData { ext, macro_rules } ) ;
12551262 self . r . local_macro_def_scopes . insert ( def_id, parent_scope. module ) ;
12561263
12571264 if macro_rules {
0 commit comments