Avoid storing the LocalDefId twice

This commit is contained in:
Oli Scherer 2025-04-11 09:52:47 +00:00
parent f5c60f616f
commit 33a6820c2f
3 changed files with 5 additions and 7 deletions

View File

@ -1209,7 +1209,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
.unused_macro_rules
.entry(node_id)
.or_default()
.insert(*rule_i, (ident, *rule_span, def_id));
.insert(*rule_i, (ident, *rule_span));
}
}
}

View File

@ -1140,7 +1140,7 @@ pub struct Resolver<'ra, 'tcx> {
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'ra>>,
unused_macros: FxIndexMap<LocalDefId, (NodeId, Ident)>,
/// A map from the macro to all its potentially unused arms.
unused_macro_rules: FxIndexMap<NodeId, UnordMap<usize, (Ident, Span, LocalDefId)>>,
unused_macro_rules: FxIndexMap<NodeId, UnordMap<usize, (Ident, Span)>>,
proc_macro_stubs: FxHashSet<LocalDefId>,
/// Traces collected during macro resolution and validated when it's complete.
single_segment_macro_resolutions:

View File

@ -336,14 +336,12 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
ident.span,
BuiltinLintDiag::UnusedMacroDefinition(ident.name),
);
// Do not report unused individual rules if the entire macro is unused
self.unused_macro_rules.swap_remove(&node_id);
}
for (&node_id, unused_arms) in self.unused_macro_rules.iter() {
for (&arm_i, &(ident, rule_span, def_id)) in unused_arms.to_sorted_stable_ord() {
if self.unused_macros.contains_key(&def_id) {
// We already lint the entire macro as unused
continue;
}
for (&arm_i, &(ident, rule_span)) in unused_arms.to_sorted_stable_ord() {
self.lint_buffer.buffer_lint(
UNUSED_MACRO_RULES,
node_id,