@@ -10,7 +10,9 @@ use crate::imports::{Import, ImportKind};
10
10
use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
11
11
use crate :: Namespace :: { self , MacroNS , TypeNS , ValueNS } ;
12
12
use 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
+ } ;
14
16
use crate :: { Resolver , ResolverArenas , Segment , ToNameBinding , VisResolutionError } ;
15
17
16
18
use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
@@ -20,7 +22,6 @@ use rustc_ast_lowering::ResolverAstLowering;
20
22
use rustc_attr as attr;
21
23
use rustc_data_structures:: sync:: Lrc ;
22
24
use rustc_errors:: { struct_span_err, Applicability } ;
23
- use rustc_expand:: base:: SyntaxExtension ;
24
25
use rustc_expand:: expand:: AstFragment ;
25
26
use rustc_hir:: def:: { self , * } ;
26
27
use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID } ;
@@ -180,26 +181,32 @@ impl<'a> Resolver<'a> {
180
181
}
181
182
}
182
183
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 > {
184
185
match res {
185
186
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
+ }
187
190
_ => None ,
188
191
}
189
192
}
190
193
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 ( ) ;
194
197
}
195
198
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
+ } ;
200
206
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
203
210
}
204
211
205
212
pub ( crate ) fn build_reduced_graph (
@@ -1251,7 +1258,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1251
1258
} ;
1252
1259
1253
1260
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 } ) ;
1255
1262
self . r . local_macro_def_scopes . insert ( def_id, parent_scope. module ) ;
1256
1263
1257
1264
if macro_rules {
0 commit comments