aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-20 14:58:20 +0000
committerAleksey Kladov <[email protected]>2019-12-20 15:52:02 +0000
commit1b8ce5b37b597679796b3ebc57afd55af49449b0 (patch)
tree25851606a456296568234cd3b4f9a81ba3921a14
parent030e540ad19046e2037981ec8e15a6800b86bbe9 (diff)
Move impls to ItemScope
-rw-r--r--crates/ra_hir/src/code_model.rs2
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs2
-rw-r--r--crates/ra_hir_def/src/item_scope.rs7
-rw-r--r--crates/ra_hir_def/src/lang_item.rs2
-rw-r--r--crates/ra_hir_def/src/nameres.rs4
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/tests/macros.rs4
-rw-r--r--crates/ra_hir_ty/src/method_resolution.rs2
-rw-r--r--crates/ra_hir_ty/src/test_db.rs2
-rw-r--r--crates/ra_hir_ty/src/tests.rs2
10 files changed, 16 insertions, 13 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index ecf883272..fca3a2950 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -221,7 +221,7 @@ impl Module {
221 221
222 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { 222 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
223 let def_map = db.crate_def_map(self.id.krate); 223 let def_map = db.crate_def_map(self.id.krate);
224 def_map[self.id.local_id].impls.iter().copied().map(ImplBlock::from).collect() 224 def_map[self.id.local_id].scope.impls().map(ImplBlock::from).collect()
225 } 225 }
226 226
227 pub(crate) fn with_module_id(self, module_id: LocalModuleId) -> Module { 227 pub(crate) fn with_module_id(self, module_id: LocalModuleId) -> Module {
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index f5a65ad40..403ba8b57 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -80,7 +80,7 @@ impl ChildBySource for ModuleId {
80 80
81 module_data.scope.declarations().for_each(|item| add_module_def(db, &mut res, item)); 81 module_data.scope.declarations().for_each(|item| add_module_def(db, &mut res, item));
82 82
83 for &impl_ in module_data.impls.iter() { 83 for &impl_ in module_data.scope.impls.iter() {
84 let src = impl_.lookup(db).source(db); 84 let src = impl_.lookup(db).source(db);
85 res[keys::IMPL].insert(src, impl_) 85 res[keys::IMPL].insert(src, impl_)
86 } 86 }
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index 996d06db6..93e579bb0 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -5,11 +5,12 @@ use hir_expand::name::Name;
5use once_cell::sync::Lazy; 5use once_cell::sync::Lazy;
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7 7
8use crate::{per_ns::PerNs, BuiltinType, LocalImportId, MacroDefId, ModuleDefId, TraitId}; 8use crate::{per_ns::PerNs, BuiltinType, ImplId, LocalImportId, MacroDefId, ModuleDefId, TraitId};
9 9
10#[derive(Debug, Default, PartialEq, Eq)] 10#[derive(Debug, Default, PartialEq, Eq)]
11pub struct ItemScope { 11pub struct ItemScope {
12 pub(crate) items: FxHashMap<Name, Resolution>, 12 pub(crate) items: FxHashMap<Name, Resolution>,
13 pub(crate) impls: Vec<ImplId>,
13 /// Macros visible in current module in legacy textual scope 14 /// Macros visible in current module in legacy textual scope
14 /// 15 ///
15 /// For macros invoked by an unqualified identifier like `bar!()`, `legacy_macros` will be searched in first. 16 /// For macros invoked by an unqualified identifier like `bar!()`, `legacy_macros` will be searched in first.
@@ -59,6 +60,10 @@ impl ItemScope {
59 }) 60 })
60 } 61 }
61 62
63 pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ {
64 self.impls.iter().copied()
65 }
66
62 /// Iterate over all module scoped macros 67 /// Iterate over all module scoped macros
63 pub(crate) fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a { 68 pub(crate) fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
64 self.items 69 self.items
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs
index f4fdbdcfc..61b248815 100644
--- a/crates/ra_hir_def/src/lang_item.rs
+++ b/crates/ra_hir_def/src/lang_item.rs
@@ -81,7 +81,7 @@ impl LangItems {
81 // Look for impl targets 81 // Look for impl targets
82 let def_map = db.crate_def_map(module.krate); 82 let def_map = db.crate_def_map(module.krate);
83 let module_data = &def_map[module.local_id]; 83 let module_data = &def_map[module.local_id];
84 for &impl_block in module_data.impls.iter() { 84 for &impl_block in module_data.scope.impls.iter() {
85 self.collect_lang_item(db, impl_block, LangItemTarget::ImplBlockId) 85 self.collect_lang_item(db, impl_block, LangItemTarget::ImplBlockId)
86 } 86 }
87 87
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 3b318719e..5d4ca73a3 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -73,7 +73,7 @@ use crate::{
73 nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode}, 73 nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode},
74 path::ModPath, 74 path::ModPath,
75 per_ns::PerNs, 75 per_ns::PerNs,
76 AstId, ImplId, LocalModuleId, ModuleDefId, ModuleId, 76 AstId, LocalModuleId, ModuleDefId, ModuleId,
77}; 77};
78 78
79/// Contains all top-level defs from a macro-expanded crate 79/// Contains all top-level defs from a macro-expanded crate
@@ -169,8 +169,6 @@ pub struct ModuleData {
169 169
170 /// Where does this module come from? 170 /// Where does this module come from?
171 pub origin: ModuleOrigin, 171 pub origin: ModuleOrigin,
172
173 pub impls: Vec<ImplId>,
174} 172}
175 173
176impl CrateDefMap { 174impl CrateDefMap {
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index ea6ce5f97..c4f6bcd95 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -667,7 +667,7 @@ where
667 let impl_id = 667 let impl_id =
668 ImplLoc { container, ast_id: AstId::new(self.file_id, ast_id) } 668 ImplLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
669 .intern(self.def_collector.db); 669 .intern(self.def_collector.db);
670 self.def_collector.def_map.modules[self.module_id].impls.push(impl_id) 670 self.def_collector.def_map.modules[self.module_id].scope.impls.push(impl_id)
671 } 671 }
672 } 672 }
673 } 673 }
diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs
index cfa4ecb1a..d104f5993 100644
--- a/crates/ra_hir_def/src/nameres/tests/macros.rs
+++ b/crates/ra_hir_def/src/nameres/tests/macros.rs
@@ -610,7 +610,7 @@ fn expand_derive() {
610 struct Foo; 610 struct Foo;
611 ", 611 ",
612 ); 612 );
613 assert_eq!(map.modules[map.root].impls.len(), 1); 613 assert_eq!(map.modules[map.root].scope.impls().len(), 1);
614} 614}
615 615
616#[test] 616#[test]
@@ -622,5 +622,5 @@ fn expand_multiple_derive() {
622 struct Foo; 622 struct Foo;
623 ", 623 ",
624 ); 624 );
625 assert_eq!(map.modules[map.root].impls.len(), 2); 625 assert_eq!(map.modules[map.root].scope.impls().len(), 2);
626} 626}
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs
index 92fb4c081..888dc3116 100644
--- a/crates/ra_hir_ty/src/method_resolution.rs
+++ b/crates/ra_hir_ty/src/method_resolution.rs
@@ -58,7 +58,7 @@ impl CrateImplBlocks {
58 58
59 let crate_def_map = db.crate_def_map(krate); 59 let crate_def_map = db.crate_def_map(krate);
60 for (_module_id, module_data) in crate_def_map.modules.iter() { 60 for (_module_id, module_data) in crate_def_map.modules.iter() {
61 for &impl_id in module_data.impls.iter() { 61 for impl_id in module_data.scope.impls() {
62 match db.impl_trait(impl_id) { 62 match db.impl_trait(impl_id) {
63 Some(tr) => { 63 Some(tr) => {
64 res.impls_by_trait.entry(tr.trait_).or_default().push(impl_id); 64 res.impls_by_trait.entry(tr.trait_).or_default().push(impl_id);
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs
index 476f6df52..1a31b587b 100644
--- a/crates/ra_hir_ty/src/test_db.rs
+++ b/crates/ra_hir_ty/src/test_db.rs
@@ -98,7 +98,7 @@ impl TestDB {
98 } 98 }
99 } 99 }
100 100
101 for &impl_id in crate_def_map[module_id].impls.iter() { 101 for impl_id in crate_def_map[module_id].scope.impls() {
102 let impl_data = self.impl_data(impl_id); 102 let impl_data = self.impl_data(impl_id);
103 for item in impl_data.items.iter() { 103 for item in impl_data.items.iter() {
104 if let AssocItemId::FunctionId(f) = item { 104 if let AssocItemId::FunctionId(f) = item {
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index d724ee122..d447b4571 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -182,7 +182,7 @@ fn visit_module(
182 _ => (), 182 _ => (),
183 } 183 }
184 } 184 }
185 for &impl_id in crate_def_map[module_id].impls.iter() { 185 for impl_id in crate_def_map[module_id].scope.impls() {
186 let impl_data = db.impl_data(impl_id); 186 let impl_data = db.impl_data(impl_id);
187 for &item in impl_data.items.iter() { 187 for &item in impl_data.items.iter() {
188 match item { 188 match item {