diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-26 16:16:54 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-26 16:16:54 +0000 |
commit | a82755e24102bea85be450e0b210d45b05b9f246 (patch) | |
tree | 52f347ddfc4586e3dfa4467827b211d1684aaa74 /crates/ra_hir/src/code_model_impl | |
parent | 96acf4f7ec4257af0d5fd0415b31ab6757b475ad (diff) | |
parent | 1325a31e34a3b4bf5104a743bcb8217ef5c4f3cd (diff) |
Merge #1059
1059: Typed ids r=matklad a=matklad
just some type-safety and refactorings.
closes https://github.com/rust-analyzer/rust-analyzer/issues/1054
bors r+
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 790e2b80f..0edb8ade5 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -1,18 +1,18 @@ | |||
1 | use ra_db::FileId; | 1 | use ra_db::FileId; |
2 | use ra_syntax::{ast, TreeArc, AstNode}; | 2 | use ra_syntax::{ast, TreeArc}; |
3 | 3 | ||
4 | use crate::{ | 4 | use crate::{ |
5 | Module, ModuleSource, Name, | 5 | Module, ModuleSource, Name, AstId, |
6 | nameres::{CrateModuleId, ImportId}, | 6 | nameres::{CrateModuleId, ImportId}, |
7 | HirDatabase, DefDatabase, | 7 | HirDatabase, DefDatabase, |
8 | HirFileId, SourceItemId, | 8 | HirFileId, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | impl ModuleSource { | 11 | impl ModuleSource { |
12 | pub(crate) fn new( | 12 | pub(crate) fn new( |
13 | db: &impl DefDatabase, | 13 | db: &impl DefDatabase, |
14 | file_id: Option<FileId>, | 14 | file_id: Option<FileId>, |
15 | decl_id: Option<SourceItemId>, | 15 | decl_id: Option<AstId<ast::Module>>, |
16 | ) -> ModuleSource { | 16 | ) -> ModuleSource { |
17 | match (file_id, decl_id) { | 17 | match (file_id, decl_id) { |
18 | (Some(file_id), _) => { | 18 | (Some(file_id), _) => { |
@@ -20,8 +20,7 @@ impl ModuleSource { | |||
20 | ModuleSource::SourceFile(source_file) | 20 | ModuleSource::SourceFile(source_file) |
21 | } | 21 | } |
22 | (None, Some(item_id)) => { | 22 | (None, Some(item_id)) => { |
23 | let module = db.file_item(item_id); | 23 | let module = item_id.to_node(db); |
24 | let module = ast::Module::cast(&*module).unwrap(); | ||
25 | assert!(module.item_list().is_some(), "expected inline module"); | 24 | assert!(module.item_list().is_some(), "expected inline module"); |
26 | ModuleSource::Module(module.to_owned()) | 25 | ModuleSource::Module(module.to_owned()) |
27 | } | 26 | } |
@@ -55,7 +54,7 @@ impl Module { | |||
55 | let decl_id = def_map[self.module_id].declaration; | 54 | let decl_id = def_map[self.module_id].declaration; |
56 | let file_id = def_map[self.module_id].definition; | 55 | let file_id = def_map[self.module_id].definition; |
57 | let module_source = ModuleSource::new(db, file_id, decl_id); | 56 | let module_source = ModuleSource::new(db, file_id, decl_id); |
58 | let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id); | 57 | let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id()); |
59 | (file_id, module_source) | 58 | (file_id, module_source) |
60 | } | 59 | } |
61 | 60 | ||
@@ -65,9 +64,8 @@ impl Module { | |||
65 | ) -> Option<(HirFileId, TreeArc<ast::Module>)> { | 64 | ) -> Option<(HirFileId, TreeArc<ast::Module>)> { |
66 | let def_map = db.crate_def_map(self.krate); | 65 | let def_map = db.crate_def_map(self.krate); |
67 | let decl = def_map[self.module_id].declaration?; | 66 | let decl = def_map[self.module_id].declaration?; |
68 | let syntax_node = db.file_item(decl); | 67 | let ast = decl.to_node(db); |
69 | let ast = ast::Module::cast(&syntax_node).unwrap().to_owned(); | 68 | Some((decl.file_id(), ast)) |
70 | Some((decl.file_id, ast)) | ||
71 | } | 69 | } |
72 | 70 | ||
73 | pub(crate) fn import_source_impl( | 71 | pub(crate) fn import_source_impl( |