about summary refs log tree commit diff
path: root/compiler/rustc_passes/src/dead.rs
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2025-08-02 22:42:54 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2025-08-02 22:42:54 +0000
commitaba0b65707f9980babb6dcc2855f32a3b21f05e7 (patch)
tree80110cff55fa604221381bd8d12798049712526d /compiler/rustc_passes/src/dead.rs
parentbc177055f748d87f358fc360ba19932ca79b7c68 (diff)
downloadrust-aba0b65707f9980babb6dcc2855f32a3b21f05e7.tar.gz
rust-aba0b65707f9980babb6dcc2855f32a3b21f05e7.zip
Use DefKind in should_explore.
Diffstat (limited to 'compiler/rustc_passes/src/dead.rs')
-rw-r--r--compiler/rustc_passes/src/dead.rs44
1 files changed, 34 insertions, 10 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs
index f8d1ef29882..bf5a31f7dde 100644
--- a/compiler/rustc_passes/src/dead.rs
+++ b/compiler/rustc_passes/src/dead.rs
@@ -33,16 +33,40 @@ use crate::errors::{
 // function, then we should explore its block to check for codes that
 // may need to be marked as live.
 fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
-    matches!(
-        tcx.hir_node_by_def_id(def_id),
-        Node::Item(..)
-            | Node::ImplItem(..)
-            | Node::ForeignItem(..)
-            | Node::TraitItem(..)
-            | Node::Variant(..)
-            | Node::AnonConst(..)
-            | Node::OpaqueTy(..)
-    )
+    match tcx.def_kind(def_id) {
+        DefKind::Mod
+        | DefKind::Struct
+        | DefKind::Union
+        | DefKind::Enum
+        | DefKind::Variant
+        | DefKind::Trait
+        | DefKind::TyAlias
+        | DefKind::ForeignTy
+        | DefKind::TraitAlias
+        | DefKind::AssocTy
+        | DefKind::Fn
+        | DefKind::Const
+        | DefKind::Static { .. }
+        | DefKind::AssocFn
+        | DefKind::AssocConst
+        | DefKind::Macro(_)
+        | DefKind::GlobalAsm
+        | DefKind::Impl { .. }
+        | DefKind::OpaqueTy
+        | DefKind::AnonConst
+        | DefKind::InlineConst
+        | DefKind::ExternCrate
+        | DefKind::Use
+        | DefKind::ForeignMod => true,
+
+        DefKind::TyParam
+        | DefKind::ConstParam
+        | DefKind::Ctor(..)
+        | DefKind::Field
+        | DefKind::LifetimeParam
+        | DefKind::Closure
+        | DefKind::SyntheticCoroutineBody => false,
+    }
 }
 
 /// Returns the local def id of the ADT if the given ty refers to a local one.