@@ -1064,8 +1064,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
10641064 None
10651065 }
10661066
1067+ // Mark the given macro as unused unless its name starts with `_`.
1068+ // Macro uses will remove items from this set, and the remaining
1069+ // items will be reported as `unused_macros`.
1070+ fn insert_unused_macro ( & mut self , ident : Ident , node_id : NodeId , span : Span ) {
1071+ if !ident. as_str ( ) . starts_with ( "_" ) {
1072+ self . r . unused_macros . insert ( node_id, span) ;
1073+ }
1074+ }
1075+
10671076 fn define_macro ( & mut self , item : & ast:: Item ) -> LegacyScope < ' a > {
1068- let parent_scope = & self . parent_scope ;
1077+ let parent_scope = self . parent_scope ;
10691078 let expansion = parent_scope. expansion ;
10701079 let ( ext, ident, span, is_legacy) = match & item. kind {
10711080 ItemKind :: MacroDef ( def) => {
@@ -1105,7 +1114,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11051114 ( res, vis, span, expansion, IsMacroExport ) ) ;
11061115 } else {
11071116 self . r . check_reserved_macro_name ( ident, res) ;
1108- self . r . unused_macros . insert ( item. id , span) ;
1117+ self . insert_unused_macro ( ident , item. id , span) ;
11091118 }
11101119 LegacyScope :: Binding ( self . r . arenas . alloc_legacy_binding ( LegacyBinding {
11111120 parent_legacy_scope : parent_scope. legacy , binding, ident
@@ -1114,7 +1123,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11141123 let module = parent_scope. module ;
11151124 let vis = self . resolve_visibility ( & item. vis ) ;
11161125 if vis != ty:: Visibility :: Public {
1117- self . r . unused_macros . insert ( item. id , span) ;
1126+ self . insert_unused_macro ( ident , item. id , span) ;
11181127 }
11191128 self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
11201129 self . parent_scope . legacy
0 commit comments