mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
Avoid hitting the global node_id_to_def_id table for unused macros
This commit is contained in:
@@ -1277,7 +1277,7 @@ fn insert_unused_macro(&mut self, ident: Ident, def_id: LocalDefId, node_id: Nod
|
||||
if !ident.as_str().starts_with('_') {
|
||||
self.r.unused_macros.insert(def_id, (node_id, ident));
|
||||
let nrules = self.r.local_macro_map[&def_id].nrules;
|
||||
self.r.unused_macro_rules.insert(node_id, DenseBitSet::new_filled(nrules));
|
||||
self.r.unused_macro_rules.insert(node_id, (def_id, DenseBitSet::new_filled(nrules)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1405,8 +1405,8 @@ pub struct Resolver<'ra, 'tcx> {
|
||||
local_macro_def_scopes: FxHashMap<LocalDefId, LocalModule<'ra>> = default::fx_hash_map(),
|
||||
ast_transform_scopes: FxHashMap<LocalExpnId, LocalModule<'ra>> = default::fx_hash_map(),
|
||||
unused_macros: FxIndexMap<LocalDefId, (NodeId, Ident)>,
|
||||
/// A map from the macro to all its potentially unused arms.
|
||||
unused_macro_rules: FxIndexMap<NodeId, DenseBitSet<usize>>,
|
||||
/// A map from the macro to all its potentially unused arms and the `LocalDefId` of the macro itself.
|
||||
unused_macro_rules: FxIndexMap<NodeId, (LocalDefId, DenseBitSet<usize>)>,
|
||||
proc_macro_stubs: FxHashSet<LocalDefId> = default::fx_hash_set(),
|
||||
/// Traces collected during macro resolution and validated when it's complete.
|
||||
single_segment_macro_resolutions:
|
||||
|
||||
@@ -339,7 +339,7 @@ fn resolve_macro_invocation(
|
||||
}
|
||||
|
||||
fn record_macro_rule_usage(&mut self, id: NodeId, rule_i: usize) {
|
||||
if let Some(rules) = self.unused_macro_rules.get_mut(&id) {
|
||||
if let Some((_, rules)) = self.unused_macro_rules.get_mut(&id) {
|
||||
rules.remove(rule_i);
|
||||
}
|
||||
}
|
||||
@@ -356,11 +356,10 @@ fn check_unused_macros(&mut self) {
|
||||
self.unused_macro_rules.swap_remove(&node_id);
|
||||
}
|
||||
|
||||
for (&node_id, unused_arms) in self.unused_macro_rules.iter() {
|
||||
for (&node_id, (def_id, unused_arms)) in self.unused_macro_rules.iter() {
|
||||
if unused_arms.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let def_id = self.local_def_id(node_id);
|
||||
let m = &self.local_macro_map[&def_id];
|
||||
let SyntaxExtensionKind::MacroRules(ref m) = m.ext.kind else {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user