diff options
Diffstat (limited to 'crates/hir/src/semantics')
-rw-r--r-- | crates/hir/src/semantics/source_to_def.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 9bf60c72a..faede3269 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs | |||
@@ -31,11 +31,12 @@ 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 | let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| { |
34 | // FIXME: inner items | ||
34 | let crate_def_map = self.db.crate_def_map(crate_id); | 35 | let crate_def_map = self.db.crate_def_map(crate_id); |
35 | let local_id = crate_def_map.modules_for_file(file).next()?; | 36 | let local_id = crate_def_map.modules_for_file(file).next()?; |
36 | Some((crate_id, local_id)) | 37 | Some((crate_id, local_id)) |
37 | })?; | 38 | })?; |
38 | Some(ModuleId { krate, local_id }) | 39 | Some(ModuleId::top_level(krate, local_id)) |
39 | } | 40 | } |
40 | 41 | ||
41 | pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> { | 42 | pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> { |
@@ -60,9 +61,10 @@ impl SourceToDefCtx<'_, '_> { | |||
60 | }?; | 61 | }?; |
61 | 62 | ||
62 | let child_name = src.value.name()?.as_name(); | 63 | let child_name = src.value.name()?.as_name(); |
63 | let def_map = self.db.crate_def_map(parent_module.krate); | 64 | let def_map = parent_module.def_map(self.db.upcast()); |
64 | let child_id = *def_map[parent_module.local_id].children.get(&child_name)?; | 65 | let child_id = *def_map[parent_module.local_id].children.get(&child_name)?; |
65 | Some(ModuleId { krate: parent_module.krate, local_id: child_id }) | 66 | // FIXME: handle block expression modules |
67 | Some(ModuleId::top_level(parent_module.krate(), child_id)) | ||
66 | } | 68 | } |
67 | 69 | ||
68 | pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> { | 70 | pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> { |
@@ -185,7 +187,7 @@ impl SourceToDefCtx<'_, '_> { | |||
185 | ) -> Option<MacroDefId> { | 187 | ) -> Option<MacroDefId> { |
186 | let kind = MacroDefKind::Declarative; | 188 | let kind = MacroDefKind::Declarative; |
187 | let file_id = src.file_id.original_file(self.db.upcast()); | 189 | let file_id = src.file_id.original_file(self.db.upcast()); |
188 | let krate = self.file_to_def(file_id)?.krate; | 190 | let krate = self.file_to_def(file_id)?.krate(); |
189 | let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); | 191 | let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); |
190 | let ast_id = Some(AstId::new(src.file_id, file_ast_id.upcast())); | 192 | let ast_id = Some(AstId::new(src.file_id, file_ast_id.upcast())); |
191 | Some(MacroDefId { krate, ast_id, kind, local_inner: false }) | 193 | Some(MacroDefId { krate, ast_id, kind, local_inner: false }) |