diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2025-07-04 22:21:31 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2025-07-16 08:28:17 +0300 |
| commit | babe2c0d0f091f5ea9935176b478ea45b152e49e (patch) | |
| tree | 35c24447cb20b61e8020f1a03fd9ac09033a4245 /compiler/rustc_hir/src/def.rs | |
| parent | 3014e79f9c8d5510ea7b3a3b70d171d0948b1e96 (diff) | |
| download | rust-babe2c0d0f091f5ea9935176b478ea45b152e49e.tar.gz rust-babe2c0d0f091f5ea9935176b478ea45b152e49e.zip | |
resolve: Merge `NameBindingKind::Module` into `NameBindingKind::Res`
Diffstat (limited to 'compiler/rustc_hir/src/def.rs')
| -rw-r--r-- | compiler/rustc_hir/src/def.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index df010f87098..ca57c4f3164 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -295,6 +295,12 @@ impl DefKind { } } + /// This is a "module" in name resolution sense. + #[inline] + pub fn is_module_like(self) -> bool { + matches!(self, DefKind::Mod | DefKind::Enum | DefKind::Trait) + } + #[inline] pub fn is_fn_like(self) -> bool { matches!( @@ -720,6 +726,15 @@ impl<Id> Res<Id> { } } + /// If this is a "module" in name resolution sense, return its `DefId`. + #[inline] + pub fn module_like_def_id(&self) -> Option<DefId> { + match self { + Res::Def(def_kind, def_id) if def_kind.is_module_like() => Some(*def_id), + _ => None, + } + } + /// A human readable name for the res kind ("function", "module", etc.). pub fn descr(&self) -> &'static str { match *self { |
