From 5c241b07666bc7b29e97b8206e505944775266a0 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 25 Jan 2021 15:21:33 +0100 Subject: Create all `ModuleId`s through a `DefMap` method `ModuleId` needs to be able to represent blocks, and only the associated `DefMap` will know how to construct that `ModuleId` --- crates/hir/src/semantics/source_to_def.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'crates/hir/src/semantics') diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index faede3269..6c612ee86 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -30,13 +30,12 @@ pub(super) struct SourceToDefCtx<'a, 'b> { impl SourceToDefCtx<'_, '_> { pub(super) fn file_to_def(&mut self, file: FileId) -> Option { let _p = profile::span("SourceBinder::to_module_def"); - let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| { + self.db.relevant_crates(file).iter().find_map(|&crate_id| { // FIXME: inner items let crate_def_map = self.db.crate_def_map(crate_id); let local_id = crate_def_map.modules_for_file(file).next()?; - Some((crate_id, local_id)) - })?; - Some(ModuleId::top_level(krate, local_id)) + Some(crate_def_map.module_id(local_id)) + }) } pub(super) fn module_to_def(&mut self, src: InFile) -> Option { @@ -63,8 +62,7 @@ impl SourceToDefCtx<'_, '_> { let child_name = src.value.name()?.as_name(); let def_map = parent_module.def_map(self.db.upcast()); let child_id = *def_map[parent_module.local_id].children.get(&child_name)?; - // FIXME: handle block expression modules - Some(ModuleId::top_level(parent_module.krate(), child_id)) + Some(def_map.module_id(child_id)) } pub(super) fn trait_to_def(&mut self, src: InFile) -> Option { -- cgit v1.2.3