@@ -14,7 +14,7 @@ use rustc_ast::{
1414 TyAlias ,
1515} ;
1616use rustc_attr_parsing:: AttributeParser ;
17- use rustc_expand:: base:: ResolverExpand ;
17+ use rustc_expand:: base:: { ResolverExpand , SyntaxExtension , SyntaxExtensionKind } ;
1818use rustc_hir:: Attribute ;
1919use rustc_hir:: attrs:: { AttributeKind , MacroUseArgs } ;
2020use rustc_hir:: def:: { self , * } ;
@@ -37,9 +37,8 @@ use crate::macros::{MacroRulesDecl, MacroRulesScope, MacroRulesScopeRef};
3737use crate :: ref_mut:: CmCell ;
3838use crate :: {
3939 BindingKey , Decl , DeclData , DeclKind , DelayedVisResolutionError , ExternModule ,
40- ExternPreludeEntry , Finalize , IdentKey , LocalModule , MacroData , Module , ModuleKind ,
41- ModuleOrUniformRoot , ParentScope , PathResult , Res , Resolver , Segment , SyntaxExtension , Used ,
42- VisResolutionError , errors,
40+ ExternPreludeEntry , Finalize , IdentKey , LocalModule , Module , ModuleKind , ModuleOrUniformRoot ,
41+ ParentScope , PathResult , Res , Resolver , Segment , Used , VisResolutionError , errors,
4342} ;
4443
4544impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
@@ -208,28 +207,28 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
208207 }
209208
210209 /// Gets the `SyntaxExtension` corresponding to `res`.
211- pub ( crate ) fn get_macro ( & self , res : Res ) -> Option < & Arc < SyntaxExtension > > {
210+ pub ( crate ) fn get_macro ( & self , res : Res ) -> Option < & ' ra Arc < SyntaxExtension > > {
212211 match res {
213- Res :: Def ( DefKind :: Macro ( ..) , def_id) => Some ( & self . get_macro_by_def_id ( def_id) . ext ) ,
214- Res :: NonMacroAttr ( _) => Some ( & self . non_macro_attr ) ,
212+ Res :: Def ( DefKind :: Macro ( ..) , def_id) => Some ( self . get_macro_by_def_id ( def_id) ) ,
213+ Res :: NonMacroAttr ( _) => Some ( self . non_macro_attr ) ,
215214 _ => None ,
216215 }
217216 }
218217
219- pub ( crate ) fn get_macro_by_def_id ( & self , def_id : DefId ) -> & ' ra MacroData {
218+ pub ( crate ) fn get_macro_by_def_id ( & self , def_id : DefId ) -> & ' ra Arc < SyntaxExtension > {
220219 // Local macros are always compiled.
221220 match def_id. as_local ( ) {
222221 Some ( local_def_id) => self . local_macro_map [ & local_def_id] ,
223- None => * self . extern_macro_map . borrow_mut ( ) . entry ( def_id) . or_insert_with ( || {
222+ None => self . extern_macro_map . borrow_mut ( ) . entry ( def_id) . or_insert_with ( || {
224223 let loaded_macro = self . cstore ( ) . load_macro_untracked ( self . tcx , def_id) ;
225- let macro_data = match loaded_macro {
224+ let ext = match loaded_macro {
226225 LoadedMacro :: MacroDef { def, ident, attrs, span, edition } => {
227226 self . compile_macro ( & def, ident, & attrs, span, ast:: DUMMY_NODE_ID , edition)
228227 }
229- LoadedMacro :: ProcMacro ( ext) => MacroData :: new ( Arc :: new ( ext) ) ,
228+ LoadedMacro :: ProcMacro ( ext) => ext,
230229 } ;
231230
232- self . arenas . alloc_macro ( macro_data )
231+ self . arenas . alloc_macro ( ext )
233232 } ) ,
234233 }
235234 }
@@ -1277,8 +1276,10 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
12771276 fn insert_unused_macro ( & mut self , ident : Ident , def_id : LocalDefId , node_id : NodeId ) {
12781277 if !ident. as_str ( ) . starts_with ( '_' ) {
12791278 self . r . unused_macros . insert ( def_id, ( node_id, ident) ) ;
1280- let nrules = self . r . local_macro_map [ & def_id] . nrules ;
1281- self . r . unused_macro_rules . insert ( node_id, ( def_id, DenseBitSet :: new_filled ( nrules) ) ) ;
1279+ if let SyntaxExtensionKind :: MacroRules ( mr) = & self . r . local_macro_map [ & def_id] . kind {
1280+ let value = ( def_id, DenseBitSet :: new_filled ( mr. nrules ( ) ) ) ;
1281+ self . r . unused_macro_rules . insert ( node_id, value) ;
1282+ }
12821283 }
12831284 }
12841285
@@ -1299,8 +1300,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
12991300 Some ( ( macro_kind, ident, span) ) => {
13001301 let macro_kinds = macro_kind. into ( ) ;
13011302 let res = Res :: Def ( DefKind :: Macro ( macro_kinds) , def_id. to_def_id ( ) ) ;
1302- let macro_data = MacroData :: new ( self . r . dummy_ext ( macro_kind) ) ;
1303- self . r . new_local_macro ( def_id, macro_data) ;
1303+ self . r . local_macro_map . insert ( def_id, self . r . dummy_ext ( macro_kind) ) ;
13041304 self . r . proc_macro_stubs . insert ( def_id) ;
13051305 ( res, ident, span, false )
13061306 }
0 commit comments