diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-25 14:22:24 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-25 14:22:24 +0000 |
commit | 2c735ed734be9b9041921478e0049fffd7160f78 (patch) | |
tree | 724e39e3933126ee3129c3e4e0c971b443221afd /crates/hir/src/semantics | |
parent | 0a6b2b784618ffbc7775e9a3e3aaf42689bb2962 (diff) | |
parent | 5c241b07666bc7b29e97b8206e505944775266a0 (diff) |
Merge #7426
7426: Create all `ModuleId`s through a `DefMap` method r=jonas-schievink a=jonas-schievink
`ModuleId` needs to be able to represent blocks, and only the
associated `DefMap` will know how to construct that `ModuleId`
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir/src/semantics')
-rw-r--r-- | crates/hir/src/semantics/source_to_def.rs | 10 |
1 files changed, 4 insertions, 6 deletions
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> { | |||
30 | impl SourceToDefCtx<'_, '_> { | 30 | impl SourceToDefCtx<'_, '_> { |
31 | pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> { | 31 | pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> { |
32 | let _p = profile::span("SourceBinder::to_module_def"); | 32 | let _p = profile::span("SourceBinder::to_module_def"); |
33 | let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| { | 33 | self.db.relevant_crates(file).iter().find_map(|&crate_id| { |
34 | // FIXME: inner items | 34 | // FIXME: inner items |
35 | let crate_def_map = self.db.crate_def_map(crate_id); | 35 | let crate_def_map = self.db.crate_def_map(crate_id); |
36 | let local_id = crate_def_map.modules_for_file(file).next()?; | 36 | let local_id = crate_def_map.modules_for_file(file).next()?; |
37 | Some((crate_id, local_id)) | 37 | Some(crate_def_map.module_id(local_id)) |
38 | })?; | 38 | }) |
39 | Some(ModuleId::top_level(krate, local_id)) | ||
40 | } | 39 | } |
41 | 40 | ||
42 | pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> { | 41 | pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> { |
@@ -63,8 +62,7 @@ impl SourceToDefCtx<'_, '_> { | |||
63 | let child_name = src.value.name()?.as_name(); | 62 | let child_name = src.value.name()?.as_name(); |
64 | let def_map = parent_module.def_map(self.db.upcast()); | 63 | let def_map = parent_module.def_map(self.db.upcast()); |
65 | let child_id = *def_map[parent_module.local_id].children.get(&child_name)?; | 64 | let child_id = *def_map[parent_module.local_id].children.get(&child_name)?; |
66 | // FIXME: handle block expression modules | 65 | Some(def_map.module_id(child_id)) |
67 | Some(ModuleId::top_level(parent_module.krate(), child_id)) | ||
68 | } | 66 | } |
69 | 67 | ||
70 | pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> { | 68 | pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> { |