diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2025-08-02 22:42:54 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2025-08-02 22:42:54 +0000 |
| commit | aba0b65707f9980babb6dcc2855f32a3b21f05e7 (patch) | |
| tree | 80110cff55fa604221381bd8d12798049712526d | |
| parent | bc177055f748d87f358fc360ba19932ca79b7c68 (diff) | |
| download | rust-aba0b65707f9980babb6dcc2855f32a3b21f05e7.tar.gz rust-aba0b65707f9980babb6dcc2855f32a3b21f05e7.zip | |
Use DefKind in should_explore.
| -rw-r--r-- | compiler/rustc_passes/src/dead.rs | 44 |
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. |
