From 0dcec31553f0fe42d7c18e6471655e8fa2258bfc Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 1 Mar 2021 19:36:34 +0100 Subject: Fix `find_path` when inner items are present --- crates/hir_def/src/nameres.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/hir_def/src/nameres.rs') diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 6a3456f2e..003d668ca 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -343,6 +343,18 @@ impl DefMap { Some(self.block?.parent) } + /// Returns the module containing `local_mod`, either the parent `mod`, or the module containing + /// the block, if `self` corresponds to a block expression. + pub fn containing_module(&self, local_mod: LocalModuleId) -> Option { + match &self[local_mod].parent { + Some(parent) => Some(self.module_id(*parent)), + None => match &self.block { + Some(block) => Some(block.parent), + None => None, + }, + } + } + // FIXME: this can use some more human-readable format (ideally, an IR // even), as this should be a great debugging aid. pub fn dump(&self, db: &dyn DefDatabase) -> String { -- cgit v1.2.3