resolve: Mark macros starting with an underscore as used

This commit is contained in:
Vadim Petrochenkov 2019-10-10 01:08:17 +03:00
parent 518deda77f
commit 2d3c17a609

View File

@ -1064,8 +1064,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
None None
} }
// Mark the given macro as unused unless its name starts with `_`.
// Macro uses will remove items from this set, and the remaining
// items will be reported as `unused_macros`.
fn insert_unused_macro(&mut self, ident: Ident, node_id: NodeId, span: Span) {
if !ident.as_str().starts_with("_") {
self.r.unused_macros.insert(node_id, span);
}
}
fn define_macro(&mut self, item: &ast::Item) -> LegacyScope<'a> { fn define_macro(&mut self, item: &ast::Item) -> LegacyScope<'a> {
let parent_scope = &self.parent_scope; let parent_scope = self.parent_scope;
let expansion = parent_scope.expansion; let expansion = parent_scope.expansion;
let (ext, ident, span, is_legacy) = match &item.kind { let (ext, ident, span, is_legacy) = match &item.kind {
ItemKind::MacroDef(def) => { ItemKind::MacroDef(def) => {
@ -1105,7 +1114,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
(res, vis, span, expansion, IsMacroExport)); (res, vis, span, expansion, IsMacroExport));
} else { } else {
self.r.check_reserved_macro_name(ident, res); self.r.check_reserved_macro_name(ident, res);
self.r.unused_macros.insert(item.id, span); self.insert_unused_macro(ident, item.id, span);
} }
LegacyScope::Binding(self.r.arenas.alloc_legacy_binding(LegacyBinding { LegacyScope::Binding(self.r.arenas.alloc_legacy_binding(LegacyBinding {
parent_legacy_scope: parent_scope.legacy, binding, ident parent_legacy_scope: parent_scope.legacy, binding, ident
@ -1114,7 +1123,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let module = parent_scope.module; let module = parent_scope.module;
let vis = self.resolve_visibility(&item.vis); let vis = self.resolve_visibility(&item.vis);
if vis != ty::Visibility::Public { if vis != ty::Visibility::Public {
self.r.unused_macros.insert(item.id, span); self.insert_unused_macro(ident, item.id, span);
} }
self.r.define(module, ident, MacroNS, (res, vis, span, expansion)); self.r.define(module, ident, MacroNS, (res, vis, span, expansion));
self.parent_scope.legacy self.parent_scope.legacy