about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
authorMiguel Guarniz <mi9uel9@gmail.com>2022-05-12 11:34:37 -0400
committerMiguel Guarniz <mi9uel9@gmail.com>2022-05-14 11:01:33 -0400
commit959636d53126fdc33452759dcba44d12a980674b (patch)
tree518e158a31dc32464fcfa2deb38ab0aed6b954fa /compiler/rustc_passes/src
parentf1c256d1687662a8ca305976ba46e39d12199ae6 (diff)
downloadrust-959636d53126fdc33452759dcba44d12a980674b.tar.gz
rust-959636d53126fdc33452759dcba44d12a980674b.zip
avoid fetching HIR when handling Impl assoc items
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/dead.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs
index 55a67070a96..e78d9a59982 100644
--- a/compiler/rustc_passes/src/dead.rs
+++ b/compiler/rustc_passes/src/dead.rs
@@ -511,18 +511,24 @@ fn check_item<'tcx>(
             }
         }
         DefKind::Impl => {
-            let item = tcx.hir().item(id);
-            if let hir::ItemKind::Impl(hir::Impl { ref of_trait, items, .. }) = item.kind {
-                if of_trait.is_some() {
-                    worklist.push(item.def_id);
-                }
-                for impl_item_ref in *items {
-                    let impl_item = tcx.hir().impl_item(impl_item_ref.id);
-                    if of_trait.is_some()
-                        || has_allow_dead_code_or_lang_attr(tcx, impl_item.hir_id())
-                    {
-                        worklist.push(impl_item_ref.id.def_id);
-                    }
+            let of_trait = tcx.impl_trait_ref(id.def_id);
+
+            if of_trait.is_some() {
+                worklist.push(id.def_id);
+            }
+
+            // get DefIds from another query
+            let local_def_ids = tcx
+                .associated_item_def_ids(id.def_id)
+                .iter()
+                .filter_map(|def_id| def_id.as_local());
+
+            // And we access the Map here to get HirId from LocalDefId
+            for id in local_def_ids {
+                if of_trait.is_some()
+                    || has_allow_dead_code_or_lang_attr(tcx, tcx.hir().local_def_id_to_hir_id(id))
+                {
+                    worklist.push(id);
                 }
             }
         }