@@ -163,25 +163,15 @@ impl<'a> Resolver<'a> {
163163 Some ( ext)
164164 }
165165
166- // FIXME: `extra_placeholders` should be included into the `fragment` as regular placeholders.
167166 crate fn build_reduced_graph (
168167 & mut self ,
169168 fragment : & AstFragment ,
170- extra_placeholders : & [ NodeId ] ,
171169 parent_scope : ParentScope < ' a > ,
172170 ) -> LegacyScope < ' a > {
173171 let mut def_collector = DefCollector :: new ( & mut self . definitions , parent_scope. expansion ) ;
174172 fragment. visit_with ( & mut def_collector) ;
175- for placeholder in extra_placeholders {
176- def_collector. visit_macro_invoc ( * placeholder) ;
177- }
178-
179173 let mut visitor = BuildReducedGraphVisitor { r : self , parent_scope } ;
180174 fragment. visit_with ( & mut visitor) ;
181- for placeholder in extra_placeholders {
182- visitor. parent_scope . legacy = visitor. visit_invoc ( * placeholder) ;
183- }
184-
185175 visitor. parent_scope . legacy
186176 }
187177
@@ -1064,8 +1054,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
10641054 None
10651055 }
10661056
1057+ // Mark the given macro as unused unless its name starts with `_`.
1058+ // Macro uses will remove items from this set, and the remaining
1059+ // items will be reported as `unused_macros`.
1060+ fn insert_unused_macro ( & mut self , ident : Ident , node_id : NodeId , span : Span ) {
1061+ if !ident. as_str ( ) . starts_with ( "_" ) {
1062+ self . r . unused_macros . insert ( node_id, span) ;
1063+ }
1064+ }
1065+
10671066 fn define_macro ( & mut self , item : & ast:: Item ) -> LegacyScope < ' a > {
1068- let parent_scope = & self . parent_scope ;
1067+ let parent_scope = self . parent_scope ;
10691068 let expansion = parent_scope. expansion ;
10701069 let ( ext, ident, span, is_legacy) = match & item. kind {
10711070 ItemKind :: MacroDef ( def) => {
@@ -1105,7 +1104,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11051104 ( res, vis, span, expansion, IsMacroExport ) ) ;
11061105 } else {
11071106 self . r . check_reserved_macro_name ( ident, res) ;
1108- self . r . unused_macros . insert ( item. id , span) ;
1107+ self . insert_unused_macro ( ident , item. id , span) ;
11091108 }
11101109 LegacyScope :: Binding ( self . r . arenas . alloc_legacy_binding ( LegacyBinding {
11111110 parent_legacy_scope : parent_scope. legacy , binding, ident
@@ -1114,7 +1113,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11141113 let module = parent_scope. module ;
11151114 let vis = self . resolve_visibility ( & item. vis ) ;
11161115 if vis != ty:: Visibility :: Public {
1117- self . r . unused_macros . insert ( item. id , span) ;
1116+ self . insert_unused_macro ( ident , item. id , span) ;
11181117 }
11191118 self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
11201119 self . parent_scope . legacy
0 commit comments