@@ -340,7 +340,9 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
340
340
341
341
fn record_macro_rule_usage ( & mut self , id : NodeId , rule_i : usize ) {
342
342
let did = self . local_def_id ( id) ;
343
- self . unused_macro_rules . remove ( & ( did, rule_i) ) ;
343
+ if let Some ( rules) = self . unused_macro_rules . get_mut ( & did) {
344
+ rules. remove ( & rule_i) ;
345
+ }
344
346
}
345
347
346
348
fn check_unused_macros ( & mut self ) {
@@ -352,18 +354,24 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
352
354
BuiltinLintDiag :: UnusedMacroDefinition ( ident. name ) ,
353
355
) ;
354
356
}
355
- for ( & ( def_id, arm_i) , & ( ident, rule_span) ) in self . unused_macro_rules . iter ( ) {
356
- if self . unused_macros . contains_key ( & def_id) {
357
- // We already lint the entire macro as unused
358
- continue ;
357
+
358
+ for ( & def_id, unused_arms) in self . unused_macro_rules . iter ( ) {
359
+ let mut unused_arms = unused_arms. iter ( ) . collect :: < Vec < _ > > ( ) ;
360
+ unused_arms. sort_by_key ( |& ( & arm_i, _) | arm_i) ;
361
+
362
+ for ( & arm_i, & ( ident, rule_span) ) in unused_arms {
363
+ if self . unused_macros . contains_key ( & def_id) {
364
+ // We already lint the entire macro as unused
365
+ continue ;
366
+ }
367
+ let node_id = self . def_id_to_node_id [ def_id] ;
368
+ self . lint_buffer . buffer_lint (
369
+ UNUSED_MACRO_RULES ,
370
+ node_id,
371
+ rule_span,
372
+ BuiltinLintDiag :: MacroRuleNeverUsed ( arm_i, ident. name ) ,
373
+ ) ;
359
374
}
360
- let node_id = self . def_id_to_node_id [ def_id] ;
361
- self . lint_buffer . buffer_lint (
362
- UNUSED_MACRO_RULES ,
363
- node_id,
364
- rule_span,
365
- BuiltinLintDiag :: MacroRuleNeverUsed ( arm_i, ident. name ) ,
366
- ) ;
367
375
}
368
376
}
369
377
0 commit comments