Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/lib.rs')
| -rw-r--r-- | crates/hir-def/src/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs index 46898ce542..88d4572196 100644 --- a/crates/hir-def/src/lib.rs +++ b/crates/hir-def/src/lib.rs @@ -422,6 +422,10 @@ impl ModuleId { } } + pub fn crate_def_map(self, db: &dyn DefDatabase) -> Arc<DefMap> { + db.crate_def_map(self.krate) + } + pub fn krate(self) -> CrateId { self.krate } @@ -438,6 +442,8 @@ impl ModuleId { }) } + /// Returns the module containing `self`, either the parent `mod`, or the module (or block) containing + /// the block, if `self` corresponds to a block expression. pub fn containing_module(self, db: &dyn DefDatabase) -> Option<ModuleId> { self.def_map(db).containing_module(self.local_id) } @@ -929,6 +935,18 @@ impl GenericDefId { GenericDefId::EnumVariantId(_) => (FileId::BOGUS.into(), None), } } + + pub fn assoc_trait_container(self, db: &dyn DefDatabase) -> Option<TraitId> { + match match self { + GenericDefId::FunctionId(f) => f.lookup(db).container, + GenericDefId::TypeAliasId(t) => t.lookup(db).container, + GenericDefId::ConstId(c) => c.lookup(db).container, + _ => return None, + } { + ItemContainerId::TraitId(trait_) => Some(trait_), + _ => None, + } + } } impl From<AssocItemId> for GenericDefId { |