about summary refs log tree commit diff
path: root/compiler/rustc_passes
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-02-12 18:35:31 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-02-14 20:26:01 +0000
commite9e12266ced4c43f07c53017f5ed094e93157a18 (patch)
treeb6493d127ed10bcd1f70a7e0bd47836ea90dedf1 /compiler/rustc_passes
parent2a51e73ac9a1616300e3db93e094baa4b86b895f (diff)
downloadrust-e9e12266ced4c43f07c53017f5ed094e93157a18.tar.gz
rust-e9e12266ced4c43f07c53017f5ed094e93157a18.zip
Do not fetch HIR for reachable.
Diffstat (limited to 'compiler/rustc_passes')
-rw-r--r--compiler/rustc_passes/src/reachable.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs
index 9559ee9320f..051100c56f8 100644
--- a/compiler/rustc_passes/src/reachable.rs
+++ b/compiler/rustc_passes/src/reachable.rs
@@ -325,26 +325,23 @@ fn check_item<'tcx>(
     }
 
     // We need only trait impls here, not inherent impls, and only non-exported ones
-    let item = tcx.hir().item(id);
-    if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) =
-        item.kind
-    {
-        if !effective_visibilities.is_reachable(item.owner_id.def_id) {
-            worklist.extend(items.iter().map(|ii_ref| ii_ref.id.owner_id.def_id));
+    if effective_visibilities.is_reachable(id.owner_id.def_id) {
+        return;
+    }
 
-            let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res else {
-                unreachable!();
-            };
+    let items = tcx.associated_item_def_ids(id.owner_id);
+    worklist.extend(items.iter().map(|ii_ref| ii_ref.expect_local()));
 
-            if !trait_def_id.is_local() {
-                return;
-            }
+    let Some(trait_def_id) = tcx.trait_id_of_impl(id.owner_id.to_def_id()) else {
+        unreachable!();
+    };
 
-            worklist.extend(
-                tcx.provided_trait_methods(trait_def_id).map(|assoc| assoc.def_id.expect_local()),
-            );
-        }
+    if !trait_def_id.is_local() {
+        return;
     }
+
+    worklist
+        .extend(tcx.provided_trait_methods(trait_def_id).map(|assoc| assoc.def_id.expect_local()));
 }
 
 fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {