Skip to content

Commit 33a6820

Browse files
committed
Avoid storing the LocalDefId twice
1 parent f5c60f6 commit 33a6820

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
12091209
.unused_macro_rules
12101210
.entry(node_id)
12111211
.or_default()
1212-
.insert(*rule_i, (ident, *rule_span, def_id));
1212+
.insert(*rule_i, (ident, *rule_span));
12131213
}
12141214
}
12151215
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ pub struct Resolver<'ra, 'tcx> {
11401140
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'ra>>,
11411141
unused_macros: FxIndexMap<LocalDefId, (NodeId, Ident)>,
11421142
/// A map from the macro to all its potentially unused arms.
1143-
unused_macro_rules: FxIndexMap<NodeId, UnordMap<usize, (Ident, Span, LocalDefId)>>,
1143+
unused_macro_rules: FxIndexMap<NodeId, UnordMap<usize, (Ident, Span)>>,
11441144
proc_macro_stubs: FxHashSet<LocalDefId>,
11451145
/// Traces collected during macro resolution and validated when it's complete.
11461146
single_segment_macro_resolutions:

compiler/rustc_resolve/src/macros.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,12 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
336336
ident.span,
337337
BuiltinLintDiag::UnusedMacroDefinition(ident.name),
338338
);
339+
// Do not report unused individual rules if the entire macro is unused
340+
self.unused_macro_rules.swap_remove(&node_id);
339341
}
340342

341343
for (&node_id, unused_arms) in self.unused_macro_rules.iter() {
342-
for (&arm_i, &(ident, rule_span, def_id)) in unused_arms.to_sorted_stable_ord() {
343-
if self.unused_macros.contains_key(&def_id) {
344-
// We already lint the entire macro as unused
345-
continue;
346-
}
344+
for (&arm_i, &(ident, rule_span)) in unused_arms.to_sorted_stable_ord() {
347345
self.lint_buffer.buffer_lint(
348346
UNUSED_MACRO_RULES,
349347
node_id,

0 commit comments

Comments
 (0)