@@ -1061,8 +1061,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
10611061 None
10621062 }
10631063
1064+ // Mark the given macro as unused unless its name starts with `_`.
1065+ // Macro uses will remove items from this set, and the remaining
1066+ // items will be reported as `unused_macros`.
1067+ fn insert_unused_macro ( & mut self , ident : Ident , node_id : NodeId , span : Span ) {
1068+ if !ident. as_str ( ) . starts_with ( "_" ) {
1069+ self . r . unused_macros . insert ( node_id, span) ;
1070+ }
1071+ }
1072+
10641073 fn define_macro ( & mut self , item : & ast:: Item ) -> LegacyScope < ' a > {
1065- let parent_scope = & self . parent_scope ;
1074+ let parent_scope = self . parent_scope ;
10661075 let expansion = parent_scope. expansion ;
10671076 let ( ext, ident, span, is_legacy) = match & item. kind {
10681077 ItemKind :: MacroDef ( def) => {
@@ -1102,7 +1111,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11021111 ( res, vis, span, expansion, IsMacroExport ) ) ;
11031112 } else {
11041113 self . r . check_reserved_macro_name ( ident, res) ;
1105- self . r . unused_macros . insert ( item. id , span) ;
1114+ self . insert_unused_macro ( ident , item. id , span) ;
11061115 }
11071116 LegacyScope :: Binding ( self . r . arenas . alloc_legacy_binding ( LegacyBinding {
11081117 parent_legacy_scope : parent_scope. legacy , binding, ident
@@ -1111,7 +1120,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11111120 let module = parent_scope. module ;
11121121 let vis = self . resolve_visibility ( & item. vis ) ;
11131122 if vis != ty:: Visibility :: Public {
1114- self . r . unused_macros . insert ( item. id , span) ;
1123+ self . insert_unused_macro ( ident , item. id , span) ;
11151124 }
11161125 self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
11171126 self . parent_scope . legacy
0 commit comments