Skip to content

Commit 959636d

Browse files
committed
avoid fetching HIR when handling Impl assoc items
Signed-off-by: Miguel Guarniz <[email protected]>
1 parent f1c256d commit 959636d

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

compiler/rustc_passes/src/dead.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,24 @@ fn check_item<'tcx>(
511511
}
512512
}
513513
DefKind::Impl => {
514-
let item = tcx.hir().item(id);
515-
if let hir::ItemKind::Impl(hir::Impl { ref of_trait, items, .. }) = item.kind {
516-
if of_trait.is_some() {
517-
worklist.push(item.def_id);
518-
}
519-
for impl_item_ref in *items {
520-
let impl_item = tcx.hir().impl_item(impl_item_ref.id);
521-
if of_trait.is_some()
522-
|| has_allow_dead_code_or_lang_attr(tcx, impl_item.hir_id())
523-
{
524-
worklist.push(impl_item_ref.id.def_id);
525-
}
514+
let of_trait = tcx.impl_trait_ref(id.def_id);
515+
516+
if of_trait.is_some() {
517+
worklist.push(id.def_id);
518+
}
519+
520+
// get DefIds from another query
521+
let local_def_ids = tcx
522+
.associated_item_def_ids(id.def_id)
523+
.iter()
524+
.filter_map(|def_id| def_id.as_local());
525+
526+
// And we access the Map here to get HirId from LocalDefId
527+
for id in local_def_ids {
528+
if of_trait.is_some()
529+
|| has_allow_dead_code_or_lang_attr(tcx, tcx.hir().local_def_id_to_hir_id(id))
530+
{
531+
worklist.push(id);
526532
}
527533
}
528534
}

0 commit comments

Comments
 (0)