From 25b7f10c781fae5682523c59a73c4c6b49c97091 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 15 May 2017 07:35:19 +0200 Subject: [PATCH] Address review comments --- src/librustc_resolve/lib.rs | 10 ++++------ src/librustc_resolve/macros.rs | 14 +++++++------- src/libsyntax/ext/tt/macro_rules.rs | 6 ++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index f78dd4890e2ce..827d902de02d1 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1195,11 +1195,9 @@ pub struct Resolver<'a> { pub whitelisted_legacy_custom_derives: Vec, pub found_unresolved_macro: bool, - // List of macros that we need to warn about as being unused. - // The bool is true if the macro is unused, and false if its used. - // Setting a bool to false should be much faster than removing a single - // element from a FxHashSet. - unused_macros: FxHashMap, + // List of crate local macros that we need to warn about as being unused. + // Right now this only includes macro_rules! macros. + unused_macros: FxHashSet, // Maps the `Mark` of an expansion to its containing module or block. invocations: FxHashMap>, @@ -1406,7 +1404,7 @@ impl<'a> Resolver<'a> { potentially_unused_imports: Vec::new(), struct_constructors: DefIdMap(), found_unresolved_macro: false, - unused_macros: FxHashMap(), + unused_macros: FxHashSet(), } } diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index f6155c6cafdea..231d30cd2a22d 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -291,24 +291,24 @@ impl<'a> base::Resolver for Resolver<'a> { }, }; self.macro_defs.insert(invoc.expansion_data.mark, def.def_id()); - self.unused_macros.get_mut(&def.def_id()).map(|m| *m = false); + self.unused_macros.remove(&def.def_id()); Ok(Some(self.get_macro(def))) } fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, kind: MacroKind, force: bool) -> Result, Determinacy> { self.resolve_macro_to_def(scope, path, kind, force).map(|def| { - self.unused_macros.get_mut(&def.def_id()).map(|m| *m = false); + self.unused_macros.remove(&def.def_id()); self.get_macro(def) }) } fn check_unused_macros(&self) { - for (did, _) in self.unused_macros.iter().filter(|&(_, b)| *b) { + for did in self.unused_macros.iter() { let id_span = match *self.macro_map[did] { - SyntaxExtension::NormalTT(_, isp, _) => isp, - _ => None - }; + SyntaxExtension::NormalTT(_, isp, _) => isp, + _ => None, + }; if let Some((id, span)) = id_span { let lint = lint::builtin::UNUSED_MACROS; let msg = "unused macro definition".to_string(); @@ -708,7 +708,7 @@ impl<'a> Resolver<'a> { let def = Def::Macro(def_id, MacroKind::Bang); self.macro_exports.push(Export { name: ident.name, def: def, span: item.span }); } else { - self.unused_macros.insert(def_id, true); + self.unused_macros.insert(def_id); } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 0c787dcbecb9a..39a60e5c08010 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -252,11 +252,9 @@ pub fn compile(sess: &ParseSess, features: &RefCell, def: &ast::Item) valid: valid, }); - NormalTT( - exp, + NormalTT(exp, Some((def.id, def.span)), - attr::contains_name(&def.attrs, "allow_internal_unstable") - ) + attr::contains_name(&def.attrs, "allow_internal_unstable")) } fn check_lhs_nt_follows(sess: &ParseSess,