diff options
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 16 |
4 files changed, 20 insertions, 28 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index 8b70e13c4..9e082c5f7 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -5,7 +5,7 @@ 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, ImplId, LocalImportId, MacroDefId, ModuleDefId, TraitId}; | 8 | use crate::{per_ns::PerNs, BuiltinType, ImplId, 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 { |
@@ -112,28 +112,23 @@ impl ItemScope { | |||
112 | self.legacy_macros.insert(name, mac); | 112 | self.legacy_macros.insert(name, mac); |
113 | } | 113 | } |
114 | 114 | ||
115 | pub(crate) fn push_res( | 115 | pub(crate) fn push_res(&mut self, name: Name, res: &Resolution, import: bool) -> bool { |
116 | &mut self, | ||
117 | name: Name, | ||
118 | res: &Resolution, | ||
119 | import: Option<LocalImportId>, | ||
120 | ) -> bool { | ||
121 | let mut changed = false; | 116 | let mut changed = false; |
122 | let existing = self.items.entry(name.clone()).or_default(); | 117 | let existing = self.items.entry(name.clone()).or_default(); |
123 | 118 | ||
124 | if existing.def.types.is_none() && res.def.types.is_some() { | 119 | if existing.def.types.is_none() && res.def.types.is_some() { |
125 | existing.def.types = res.def.types; | 120 | existing.def.types = res.def.types; |
126 | existing.import = import.is_some() || res.import; | 121 | existing.import = import || res.import; |
127 | changed = true; | 122 | changed = true; |
128 | } | 123 | } |
129 | if existing.def.values.is_none() && res.def.values.is_some() { | 124 | if existing.def.values.is_none() && res.def.values.is_some() { |
130 | existing.def.values = res.def.values; | 125 | existing.def.values = res.def.values; |
131 | existing.import = import.is_some() || res.import; | 126 | existing.import = import || res.import; |
132 | changed = true; | 127 | changed = true; |
133 | } | 128 | } |
134 | if existing.def.macros.is_none() && res.def.macros.is_some() { | 129 | if existing.def.macros.is_none() && res.def.macros.is_some() { |
135 | existing.def.macros = res.def.macros; | 130 | existing.def.macros = res.def.macros; |
136 | existing.import = import.is_some() || res.import; | 131 | existing.import = import || res.import; |
137 | changed = true; | 132 | changed = true; |
138 | } | 133 | } |
139 | 134 | ||
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 8cb5ab8d0..f6c7f38d1 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -52,10 +52,6 @@ use crate::body::Expander; | |||
52 | use crate::builtin_type::BuiltinType; | 52 | use crate::builtin_type::BuiltinType; |
53 | 53 | ||
54 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 54 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
55 | pub(crate) struct LocalImportId(RawId); | ||
56 | impl_arena_id!(LocalImportId); | ||
57 | |||
58 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
59 | pub struct ModuleId { | 55 | pub struct ModuleId { |
60 | pub krate: CrateId, | 56 | pub krate: CrateId, |
61 | pub local_id: LocalModuleId, | 57 | pub local_id: LocalModuleId, |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index c2db5472b..2b194f488 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -26,8 +26,7 @@ use crate::{ | |||
26 | path::{ModPath, PathKind}, | 26 | path::{ModPath, PathKind}, |
27 | per_ns::PerNs, | 27 | per_ns::PerNs, |
28 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, | 28 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, |
29 | LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, | 29 | LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, |
30 | TypeAliasLoc, UnionLoc, | ||
31 | }; | 30 | }; |
32 | 31 | ||
33 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 32 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -93,7 +92,7 @@ impl PartialResolvedImport { | |||
93 | #[derive(Clone, Debug, Eq, PartialEq)] | 92 | #[derive(Clone, Debug, Eq, PartialEq)] |
94 | struct ImportDirective { | 93 | struct ImportDirective { |
95 | module_id: LocalModuleId, | 94 | module_id: LocalModuleId, |
96 | import_id: LocalImportId, | 95 | import_id: raw::Import, |
97 | import: raw::ImportData, | 96 | import: raw::ImportData, |
98 | status: PartialResolvedImport, | 97 | status: PartialResolvedImport, |
99 | } | 98 | } |
@@ -110,7 +109,7 @@ struct MacroDirective { | |||
110 | struct DefCollector<'a, DB> { | 109 | struct DefCollector<'a, DB> { |
111 | db: &'a DB, | 110 | db: &'a DB, |
112 | def_map: CrateDefMap, | 111 | def_map: CrateDefMap, |
113 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, LocalImportId)>>, | 112 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, raw::Import)>>, |
114 | unresolved_imports: Vec<ImportDirective>, | 113 | unresolved_imports: Vec<ImportDirective>, |
115 | resolved_imports: Vec<ImportDirective>, | 114 | resolved_imports: Vec<ImportDirective>, |
116 | unexpanded_macros: Vec<MacroDirective>, | 115 | unexpanded_macros: Vec<MacroDirective>, |
@@ -442,7 +441,7 @@ where | |||
442 | fn update( | 441 | fn update( |
443 | &mut self, | 442 | &mut self, |
444 | module_id: LocalModuleId, | 443 | module_id: LocalModuleId, |
445 | import: Option<LocalImportId>, | 444 | import: Option<raw::Import>, |
446 | resolutions: &[(Name, Resolution)], | 445 | resolutions: &[(Name, Resolution)], |
447 | ) { | 446 | ) { |
448 | self.update_recursive(module_id, import, resolutions, 0) | 447 | self.update_recursive(module_id, import, resolutions, 0) |
@@ -451,7 +450,7 @@ where | |||
451 | fn update_recursive( | 450 | fn update_recursive( |
452 | &mut self, | 451 | &mut self, |
453 | module_id: LocalModuleId, | 452 | module_id: LocalModuleId, |
454 | import: Option<LocalImportId>, | 453 | import: Option<raw::Import>, |
455 | resolutions: &[(Name, Resolution)], | 454 | resolutions: &[(Name, Resolution)], |
456 | depth: usize, | 455 | depth: usize, |
457 | ) { | 456 | ) { |
@@ -462,7 +461,7 @@ where | |||
462 | let scope = &mut self.def_map.modules[module_id].scope; | 461 | let scope = &mut self.def_map.modules[module_id].scope; |
463 | let mut changed = false; | 462 | let mut changed = false; |
464 | for (name, res) in resolutions { | 463 | for (name, res) in resolutions { |
465 | changed |= scope.push_res(name.clone(), res, import); | 464 | changed |= scope.push_res(name.clone(), res, import.is_some()); |
466 | } | 465 | } |
467 | 466 | ||
468 | if !changed { | 467 | if !changed { |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 73e57f1e5..1b83b2247 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -20,9 +20,7 @@ use ra_syntax::{ | |||
20 | }; | 20 | }; |
21 | use test_utils::tested_by; | 21 | use test_utils::tested_by; |
22 | 22 | ||
23 | use crate::{ | 23 | use crate::{attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile}; |
24 | attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile, LocalImportId, | ||
25 | }; | ||
26 | 24 | ||
27 | /// `RawItems` is a set of top-level items in a file (except for impls). | 25 | /// `RawItems` is a set of top-level items in a file (except for impls). |
28 | /// | 26 | /// |
@@ -31,7 +29,7 @@ use crate::{ | |||
31 | #[derive(Debug, Default, PartialEq, Eq)] | 29 | #[derive(Debug, Default, PartialEq, Eq)] |
32 | pub struct RawItems { | 30 | pub struct RawItems { |
33 | modules: Arena<Module, ModuleData>, | 31 | modules: Arena<Module, ModuleData>, |
34 | imports: Arena<LocalImportId, ImportData>, | 32 | imports: Arena<Import, ImportData>, |
35 | defs: Arena<Def, DefData>, | 33 | defs: Arena<Def, DefData>, |
36 | macros: Arena<Macro, MacroData>, | 34 | macros: Arena<Macro, MacroData>, |
37 | impls: Arena<Impl, ImplData>, | 35 | impls: Arena<Impl, ImplData>, |
@@ -73,9 +71,9 @@ impl Index<Module> for RawItems { | |||
73 | } | 71 | } |
74 | } | 72 | } |
75 | 73 | ||
76 | impl Index<LocalImportId> for RawItems { | 74 | impl Index<Import> for RawItems { |
77 | type Output = ImportData; | 75 | type Output = ImportData; |
78 | fn index(&self, idx: LocalImportId) -> &ImportData { | 76 | fn index(&self, idx: Import) -> &ImportData { |
79 | &self.imports[idx] | 77 | &self.imports[idx] |
80 | } | 78 | } |
81 | } | 79 | } |
@@ -110,7 +108,7 @@ pub(super) struct RawItem { | |||
110 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 108 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
111 | pub(super) enum RawItemKind { | 109 | pub(super) enum RawItemKind { |
112 | Module(Module), | 110 | Module(Module), |
113 | Import(LocalImportId), | 111 | Import(Import), |
114 | Def(Def), | 112 | Def(Def), |
115 | Macro(Macro), | 113 | Macro(Macro), |
116 | Impl(Impl), | 114 | Impl(Impl), |
@@ -126,6 +124,10 @@ pub(super) enum ModuleData { | |||
126 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, | 124 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, |
127 | } | 125 | } |
128 | 126 | ||
127 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
128 | pub(crate) struct Import(RawId); | ||
129 | impl_arena_id!(Import); | ||
130 | |||
129 | #[derive(Debug, Clone, PartialEq, Eq)] | 131 | #[derive(Debug, Clone, PartialEq, Eq)] |
130 | pub struct ImportData { | 132 | pub struct ImportData { |
131 | pub(super) path: ModPath, | 133 | pub(super) path: ModPath, |