Skip to content

Commit bc17705

Browse files
committed
Do not record derived impl def-id for dead code.
1 parent 6d091b2 commit bc17705

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,11 +1178,10 @@ rustc_queries! {
11781178

11791179
/// Return the live symbols in the crate for dead code check.
11801180
///
1181-
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
1182-
/// their respective impl (i.e., part of the derive macro)
1181+
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone).
11831182
query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx (
11841183
LocalDefIdSet,
1185-
LocalDefIdMap<FxIndexSet<(DefId, DefId)>>
1184+
LocalDefIdMap<FxIndexSet<DefId>>,
11861185
) {
11871186
arena_cache
11881187
desc { "finding live symbols in crate" }

compiler/rustc_passes/src/dead.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct MarkSymbolVisitor<'tcx> {
8484
// maps from ADTs to ignored derived traits (e.g. Debug and Clone)
8585
// and the span of their respective impl (i.e., part of the derive
8686
// macro)
87-
ignored_derived_traits: LocalDefIdMap<FxIndexSet<(DefId, DefId)>>,
87+
ignored_derived_traits: LocalDefIdMap<FxIndexSet<DefId>>,
8888
}
8989

9090
impl<'tcx> MarkSymbolVisitor<'tcx> {
@@ -380,10 +380,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
380380
if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind()
381381
&& let Some(adt_def_id) = adt_def.did().as_local()
382382
{
383-
self.ignored_derived_traits
384-
.entry(adt_def_id)
385-
.or_default()
386-
.insert((trait_of, impl_of));
383+
self.ignored_derived_traits.entry(adt_def_id).or_default().insert(trait_of);
387384
}
388385
return true;
389386
}
@@ -881,7 +878,7 @@ fn create_and_seed_worklist(
881878
fn live_symbols_and_ignored_derived_traits(
882879
tcx: TyCtxt<'_>,
883880
(): (),
884-
) -> (LocalDefIdSet, LocalDefIdMap<FxIndexSet<(DefId, DefId)>>) {
881+
) -> (LocalDefIdSet, LocalDefIdMap<FxIndexSet<DefId>>) {
885882
let (worklist, struct_constructors, mut unsolved_items) = create_and_seed_worklist(tcx);
886883
let mut symbol_visitor = MarkSymbolVisitor {
887884
worklist,
@@ -925,7 +922,7 @@ struct DeadItem {
925922
struct DeadVisitor<'tcx> {
926923
tcx: TyCtxt<'tcx>,
927924
live_symbols: &'tcx LocalDefIdSet,
928-
ignored_derived_traits: &'tcx LocalDefIdMap<FxIndexSet<(DefId, DefId)>>,
925+
ignored_derived_traits: &'tcx LocalDefIdMap<FxIndexSet<DefId>>,
929926
}
930927

931928
enum ShouldWarnAboutField {
@@ -1047,20 +1044,18 @@ impl<'tcx> DeadVisitor<'tcx> {
10471044
let encl_def_id = get_parent_if_enum_variant(tcx, encl_def_id);
10481045

10491046
let ignored_derived_impls =
1050-
if let Some(ign_traits) = self.ignored_derived_traits.get(&encl_def_id) {
1047+
self.ignored_derived_traits.get(&encl_def_id).map(|ign_traits| {
10511048
let trait_list = ign_traits
10521049
.iter()
1053-
.map(|(trait_id, _)| self.tcx.item_name(*trait_id))
1050+
.map(|trait_id| self.tcx.item_name(*trait_id))
10541051
.collect::<Vec<_>>();
10551052
let trait_list_len = trait_list.len();
1056-
Some(IgnoredDerivedImpls {
1053+
IgnoredDerivedImpls {
10571054
name: self.tcx.item_name(encl_def_id.to_def_id()),
10581055
trait_list: trait_list.into(),
10591056
trait_list_len,
1060-
})
1061-
} else {
1062-
None
1063-
};
1057+
}
1058+
});
10641059

10651060
let enum_variants_with_same_name = dead_codes
10661061
.iter()

0 commit comments

Comments
 (0)