提交 25b7f10c 编写于 作者: E est31

Address review comments

上级 0d0cb279
......@@ -1195,11 +1195,9 @@ pub struct Resolver<'a> {
pub whitelisted_legacy_custom_derives: Vec<Name>,
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<DefId, bool>,
// 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<DefId>,
// Maps the `Mark` of an expansion to its containing module or block.
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
......@@ -1406,7 +1404,7 @@ pub fn new(session: &'a Session,
potentially_unused_imports: Vec::new(),
struct_constructors: DefIdMap(),
found_unresolved_macro: false,
unused_macros: FxHashMap(),
unused_macros: FxHashSet(),
}
}
......
......@@ -291,24 +291,24 @@ fn resolve_invoc(&mut self, invoc: &mut Invocation, scope: Mark, force: bool)
},
};
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<Rc<SyntaxExtension>, 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 @@ pub fn define_macro(&mut self, item: &ast::Item, legacy_scope: &mut LegacyScope<
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);
}
}
......
......@@ -252,11 +252,9 @@ pub fn compile(sess: &ParseSess, features: &RefCell<Features>, 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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册