@@ -194,7 +194,7 @@ impl<'a> Resolver<'a> {
194194 }
195195
196196 let ext = Lrc :: new ( match self . cstore ( ) . load_macro_untracked ( def_id, & self . session ) {
197- LoadedMacro :: MacroDef ( item, edition) => self . compile_macro ( & item, edition) ,
197+ LoadedMacro :: MacroDef ( item, edition) => self . compile_macro ( & item, edition) . 0 ,
198198 LoadedMacro :: ProcMacro ( ext) => ext,
199199 } ) ;
200200
@@ -1218,25 +1218,35 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12181218 // Mark the given macro as unused unless its name starts with `_`.
12191219 // Macro uses will remove items from this set, and the remaining
12201220 // items will be reported as `unused_macros`.
1221- fn insert_unused_macro ( & mut self , ident : Ident , def_id : LocalDefId , node_id : NodeId ) {
1221+ fn insert_unused_macro (
1222+ & mut self ,
1223+ ident : Ident ,
1224+ def_id : LocalDefId ,
1225+ node_id : NodeId ,
1226+ rule_spans : & [ Span ] ,
1227+ ) {
12221228 if !ident. as_str ( ) . starts_with ( '_' ) {
12231229 self . r . unused_macros . insert ( def_id, ( node_id, ident) ) ;
1230+ for ( rule_i, rule_span) in rule_spans. iter ( ) . enumerate ( ) {
1231+ self . r . unused_macro_rules . insert ( ( def_id, rule_i) , ( ident, * rule_span) ) ;
1232+ }
12241233 }
12251234 }
12261235
12271236 fn define_macro ( & mut self , item : & ast:: Item ) -> MacroRulesScopeRef < ' a > {
12281237 let parent_scope = self . parent_scope ;
12291238 let expansion = parent_scope. expansion ;
12301239 let def_id = self . r . local_def_id ( item. id ) ;
1231- let ( ext, ident, span, macro_rules) = match & item. kind {
1240+ let ( ext, ident, span, macro_rules, rule_spans ) = match & item. kind {
12321241 ItemKind :: MacroDef ( def) => {
1233- let ext = Lrc :: new ( self . r . compile_macro ( item, self . r . session . edition ( ) ) ) ;
1234- ( ext, item. ident , item. span , def. macro_rules )
1242+ let ( ext, rule_spans) = self . r . compile_macro ( item, self . r . session . edition ( ) ) ;
1243+ let ext = Lrc :: new ( ext) ;
1244+ ( ext, item. ident , item. span , def. macro_rules , rule_spans)
12351245 }
12361246 ItemKind :: Fn ( ..) => match self . proc_macro_stub ( item) {
12371247 Some ( ( macro_kind, ident, span) ) => {
12381248 self . r . proc_macro_stubs . insert ( def_id) ;
1239- ( self . r . dummy_ext ( macro_kind) , ident, span, false )
1249+ ( self . r . dummy_ext ( macro_kind) , ident, span, false , Vec :: new ( ) )
12401250 }
12411251 None => return parent_scope. macro_rules ,
12421252 } ,
@@ -1264,7 +1274,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12641274 self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion, IsMacroExport ) ) ;
12651275 } else {
12661276 self . r . check_reserved_macro_name ( ident, res) ;
1267- self . insert_unused_macro ( ident, def_id, item. id ) ;
1277+ self . insert_unused_macro ( ident, def_id, item. id , & rule_spans ) ;
12681278 }
12691279 self . r . visibilities . insert ( def_id, vis) ;
12701280 let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Binding (
@@ -1287,7 +1297,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12871297 _ => self . resolve_visibility ( & item. vis ) ,
12881298 } ;
12891299 if vis != ty:: Visibility :: Public {
1290- self . insert_unused_macro ( ident, def_id, item. id ) ;
1300+ self . insert_unused_macro ( ident, def_id, item. id , & rule_spans ) ;
12911301 }
12921302 self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
12931303 self . r . visibilities . insert ( def_id, vis) ;
0 commit comments