aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres/raw.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/nameres/raw.rs')
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs20
1 files changed, 8 insertions, 12 deletions
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)]
31pub struct RawItems { 31pub 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)]
42pub struct ImportSourceMap { 42pub struct ImportSourceMap {
43 map: ArenaMap<ImportId, ImportSourcePtr>, 43 map: ArenaMap<LocalImportId, ImportSourcePtr>,
44} 44}
45 45
46type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; 46type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
@@ -51,11 +51,11 @@ fn to_node(ptr: ImportSourcePtr, file: &SourceFile) -> ImportSource {
51} 51}
52 52
53impl ImportSourceMap { 53impl 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
109impl Index<ImportId> for RawItems { 109impl 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)]
144pub(super) enum RawItemKind { 144pub(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)]
163pub struct ImportId(RawId);
164impl_arena_id!(ImportId);
165
166#[derive(Debug, Clone, PartialEq, Eq)] 162#[derive(Debug, Clone, PartialEq, Eq)]
167pub struct ImportData { 163pub struct ImportData {
168 pub(super) path: Path, 164 pub(super) path: Path,