diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/child_by_source.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lang_item.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/macros.rs | 4 |
6 files changed, 12 insertions, 9 deletions
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; | |||
5 | use once_cell::sync::Lazy; | 5 | use once_cell::sync::Lazy; |
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | 7 | ||
8 | use crate::{per_ns::PerNs, BuiltinType, LocalImportId, MacroDefId, ModuleDefId, TraitId}; | 8 | use crate::{per_ns::PerNs, BuiltinType, ImplId, LocalImportId, MacroDefId, ModuleDefId, TraitId}; |
9 | 9 | ||
10 | #[derive(Debug, Default, PartialEq, Eq)] | 10 | #[derive(Debug, Default, PartialEq, Eq)] |
11 | pub struct ItemScope { | 11 | pub 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 | ||
176 | impl CrateDefMap { | 174 | impl 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 | } |