diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 20 |
4 files changed, 22 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 1b2bc6f45..b74038b50 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -100,6 +100,10 @@ impl ModuleSource { | |||
100 | } | 100 | } |
101 | 101 | ||
102 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 102 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
103 | pub struct LocalImportId(RawId); | ||
104 | impl_arena_id!(LocalImportId); | ||
105 | |||
106 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
103 | pub struct ModuleId { | 107 | pub struct ModuleId { |
104 | pub krate: CrateId, | 108 | pub krate: CrateId, |
105 | pub module_id: CrateModuleId, | 109 | pub module_id: CrateModuleId, |
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 101203b7b..0b3b60a37 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -72,11 +72,9 @@ use rustc_hash::{FxHashMap, FxHashSet}; | |||
72 | use crate::{ | 72 | use crate::{ |
73 | builtin_type::BuiltinType, | 73 | builtin_type::BuiltinType, |
74 | db::DefDatabase, | 74 | db::DefDatabase, |
75 | nameres::{ | 75 | nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs}, |
76 | diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs, raw::ImportId, | ||
77 | }, | ||
78 | path::Path, | 76 | path::Path, |
79 | AstId, CrateModuleId, FunctionId, ImplId, ModuleDefId, ModuleId, TraitId, | 77 | AstId, CrateModuleId, FunctionId, ImplId, LocalImportId, ModuleDefId, ModuleId, TraitId, |
80 | }; | 78 | }; |
81 | 79 | ||
82 | /// Contains all top-level defs from a macro-expanded crate | 80 | /// Contains all top-level defs from a macro-expanded crate |
@@ -213,7 +211,7 @@ pub struct Resolution { | |||
213 | /// None for unresolved | 211 | /// None for unresolved |
214 | pub def: PerNs, | 212 | pub def: PerNs, |
215 | /// ident by which this is imported into local scope. | 213 | /// ident by which this is imported into local scope. |
216 | pub import: Option<ImportId>, | 214 | pub import: Option<LocalImportId>, |
217 | } | 215 | } |
218 | 216 | ||
219 | impl CrateDefMap { | 217 | impl CrateDefMap { |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 1894b072a..4a671b8f3 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -20,8 +20,8 @@ use crate::{ | |||
20 | }, | 20 | }, |
21 | path::{Path, PathKind}, | 21 | path::{Path, PathKind}, |
22 | AdtId, AstId, AstItemDef, ConstLoc, ContainerId, CrateModuleId, EnumId, EnumVariantId, | 22 | AdtId, AstId, AstItemDef, ConstLoc, ContainerId, CrateModuleId, EnumId, EnumVariantId, |
23 | FunctionLoc, ImplId, Intern, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, | 23 | FunctionLoc, ImplId, Intern, LocalImportId, LocationCtx, ModuleDefId, ModuleId, StaticId, |
24 | StructOrUnionId, TraitId, TypeAliasLoc, UnionId, | 24 | StructId, StructOrUnionId, TraitId, TypeAliasLoc, UnionId, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 27 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -94,8 +94,8 @@ impl MacroStackMonitor { | |||
94 | struct DefCollector<'a, DB> { | 94 | struct DefCollector<'a, DB> { |
95 | db: &'a DB, | 95 | db: &'a DB, |
96 | def_map: CrateDefMap, | 96 | def_map: CrateDefMap, |
97 | glob_imports: FxHashMap<CrateModuleId, Vec<(CrateModuleId, raw::ImportId)>>, | 97 | glob_imports: FxHashMap<CrateModuleId, Vec<(CrateModuleId, LocalImportId)>>, |
98 | unresolved_imports: Vec<(CrateModuleId, raw::ImportId, raw::ImportData)>, | 98 | unresolved_imports: Vec<(CrateModuleId, LocalImportId, raw::ImportData)>, |
99 | unexpanded_macros: Vec<(CrateModuleId, AstId<ast::MacroCall>, Path)>, | 99 | unexpanded_macros: Vec<(CrateModuleId, AstId<ast::MacroCall>, Path)>, |
100 | mod_dirs: FxHashMap<CrateModuleId, ModDir>, | 100 | mod_dirs: FxHashMap<CrateModuleId, ModDir>, |
101 | 101 | ||
@@ -293,7 +293,7 @@ where | |||
293 | &mut self, | 293 | &mut self, |
294 | module_id: CrateModuleId, | 294 | module_id: CrateModuleId, |
295 | def: PerNs, | 295 | def: PerNs, |
296 | import_id: raw::ImportId, | 296 | import_id: LocalImportId, |
297 | import: &raw::ImportData, | 297 | import: &raw::ImportData, |
298 | ) { | 298 | ) { |
299 | if import.is_glob { | 299 | if import.is_glob { |
@@ -388,7 +388,7 @@ where | |||
388 | fn update( | 388 | fn update( |
389 | &mut self, | 389 | &mut self, |
390 | module_id: CrateModuleId, | 390 | module_id: CrateModuleId, |
391 | import: Option<raw::ImportId>, | 391 | import: Option<LocalImportId>, |
392 | resolutions: &[(Name, Resolution)], | 392 | resolutions: &[(Name, Resolution)], |
393 | ) { | 393 | ) { |
394 | self.update_recursive(module_id, import, resolutions, 0) | 394 | self.update_recursive(module_id, import, resolutions, 0) |
@@ -397,7 +397,7 @@ where | |||
397 | fn update_recursive( | 397 | fn update_recursive( |
398 | &mut self, | 398 | &mut self, |
399 | module_id: CrateModuleId, | 399 | module_id: CrateModuleId, |
400 | import: Option<raw::ImportId>, | 400 | import: Option<LocalImportId>, |
401 | resolutions: &[(Name, Resolution)], | 401 | resolutions: &[(Name, Resolution)], |
402 | depth: usize, | 402 | depth: usize, |
403 | ) { | 403 | ) { |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 7618cb059..8ee6f54cd 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | attr::{Attr, Attrs}, | 20 | attr::{Attr, Attrs}, |
21 | db::DefDatabase, | 21 | db::DefDatabase, |
22 | path::Path, | 22 | path::Path, |
23 | FileAstId, HirFileId, ModuleSource, Source, | 23 | FileAstId, HirFileId, LocalImportId, ModuleSource, Source, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | /// `RawItems` is a set of top-level items in a file (except for impls). | 26 | /// `RawItems` is a set of top-level items in a file (except for impls). |
@@ -30,7 +30,7 @@ use crate::{ | |||
30 | #[derive(Debug, Default, PartialEq, Eq)] | 30 | #[derive(Debug, Default, PartialEq, Eq)] |
31 | pub struct RawItems { | 31 | pub struct RawItems { |
32 | modules: Arena<Module, ModuleData>, | 32 | modules: Arena<Module, ModuleData>, |
33 | imports: Arena<ImportId, ImportData>, | 33 | imports: Arena<LocalImportId, ImportData>, |
34 | defs: Arena<Def, DefData>, | 34 | defs: Arena<Def, DefData>, |
35 | macros: Arena<Macro, MacroData>, | 35 | macros: Arena<Macro, MacroData>, |
36 | impls: Arena<Impl, ImplData>, | 36 | impls: Arena<Impl, ImplData>, |
@@ -40,7 +40,7 @@ pub struct RawItems { | |||
40 | 40 | ||
41 | #[derive(Debug, Default, PartialEq, Eq)] | 41 | #[derive(Debug, Default, PartialEq, Eq)] |
42 | pub struct ImportSourceMap { | 42 | pub struct ImportSourceMap { |
43 | map: ArenaMap<ImportId, ImportSourcePtr>, | 43 | map: ArenaMap<LocalImportId, ImportSourcePtr>, |
44 | } | 44 | } |
45 | 45 | ||
46 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; | 46 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; |
@@ -51,11 +51,11 @@ fn to_node(ptr: ImportSourcePtr, file: &SourceFile) -> ImportSource { | |||
51 | } | 51 | } |
52 | 52 | ||
53 | impl ImportSourceMap { | 53 | impl ImportSourceMap { |
54 | fn insert(&mut self, import: ImportId, ptr: ImportSourcePtr) { | 54 | fn insert(&mut self, import: LocalImportId, ptr: ImportSourcePtr) { |
55 | self.map.insert(import, ptr) | 55 | self.map.insert(import, ptr) |
56 | } | 56 | } |
57 | 57 | ||
58 | pub fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource { | 58 | pub fn get(&self, source: &ModuleSource, import: LocalImportId) -> ImportSource { |
59 | let file = match source { | 59 | let file = match source { |
60 | ModuleSource::SourceFile(file) => file.clone(), | 60 | ModuleSource::SourceFile(file) => file.clone(), |
61 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), | 61 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), |
@@ -106,9 +106,9 @@ impl Index<Module> for RawItems { | |||
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | impl Index<ImportId> for RawItems { | 109 | impl Index<LocalImportId> for RawItems { |
110 | type Output = ImportData; | 110 | type Output = ImportData; |
111 | fn index(&self, idx: ImportId) -> &ImportData { | 111 | fn index(&self, idx: LocalImportId) -> &ImportData { |
112 | &self.imports[idx] | 112 | &self.imports[idx] |
113 | } | 113 | } |
114 | } | 114 | } |
@@ -143,7 +143,7 @@ pub(super) struct RawItem { | |||
143 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 143 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
144 | pub(super) enum RawItemKind { | 144 | pub(super) enum RawItemKind { |
145 | Module(Module), | 145 | Module(Module), |
146 | Import(ImportId), | 146 | Import(LocalImportId), |
147 | Def(Def), | 147 | Def(Def), |
148 | Macro(Macro), | 148 | Macro(Macro), |
149 | Impl(Impl), | 149 | Impl(Impl), |
@@ -159,10 +159,6 @@ pub(super) enum ModuleData { | |||
159 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, | 159 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, |
160 | } | 160 | } |
161 | 161 | ||
162 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
163 | pub struct ImportId(RawId); | ||
164 | impl_arena_id!(ImportId); | ||
165 | |||
166 | #[derive(Debug, Clone, PartialEq, Eq)] | 162 | #[derive(Debug, Clone, PartialEq, Eq)] |
167 | pub struct ImportData { | 163 | pub struct ImportData { |
168 | pub(super) path: Path, | 164 | pub(super) path: Path, |