@@ -194,7 +194,7 @@ impl<'a> Resolver<'a> {
194
194
}
195
195
196
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) ,
197
+ LoadedMacro :: MacroDef ( item, edition) => self . compile_macro ( & item, edition) . 0 ,
198
198
LoadedMacro :: ProcMacro ( ext) => ext,
199
199
} ) ;
200
200
@@ -1218,25 +1218,35 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1218
1218
// Mark the given macro as unused unless its name starts with `_`.
1219
1219
// Macro uses will remove items from this set, and the remaining
1220
1220
// 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
+ ) {
1222
1228
if !ident. as_str ( ) . starts_with ( '_' ) {
1223
1229
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
+ }
1224
1233
}
1225
1234
}
1226
1235
1227
1236
fn define_macro ( & mut self , item : & ast:: Item ) -> MacroRulesScopeRef < ' a > {
1228
1237
let parent_scope = self . parent_scope ;
1229
1238
let expansion = parent_scope. expansion ;
1230
1239
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 {
1232
1241
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)
1235
1245
}
1236
1246
ItemKind :: Fn ( ..) => match self . proc_macro_stub ( item) {
1237
1247
Some ( ( macro_kind, ident, span) ) => {
1238
1248
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 ( ) )
1240
1250
}
1241
1251
None => return parent_scope. macro_rules ,
1242
1252
} ,
@@ -1264,7 +1274,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1264
1274
self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion, IsMacroExport ) ) ;
1265
1275
} else {
1266
1276
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 ) ;
1268
1278
}
1269
1279
self . r . visibilities . insert ( def_id, vis) ;
1270
1280
let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Binding (
@@ -1287,7 +1297,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1287
1297
_ => self . resolve_visibility ( & item. vis ) ,
1288
1298
} ;
1289
1299
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 ) ;
1291
1301
}
1292
1302
self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
1293
1303
self . r . visibilities . insert ( def_id, vis) ;
0 commit comments