diff options
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index b7416ede6..43c97a0bf 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs | |||
@@ -12,7 +12,7 @@ use ra_syntax::{ | |||
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, | 14 | DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, |
15 | AstIdMap, FileAstId, | 15 | AstIdMap, FileAstId, Either, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | /// `RawItems` is a set of top-level items in a file (except for impls). | 18 | /// `RawItems` is a set of top-level items in a file (except for impls). |
@@ -34,28 +34,15 @@ pub struct ImportSourceMap { | |||
34 | map: ArenaMap<ImportId, ImportSourcePtr>, | 34 | map: ArenaMap<ImportId, ImportSourcePtr>, |
35 | } | 35 | } |
36 | 36 | ||
37 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 37 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; |
38 | enum ImportSourcePtr { | 38 | type ImportSource = Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>>; |
39 | UseTree(AstPtr<ast::UseTree>), | ||
40 | ExternCrate(AstPtr<ast::ExternCrateItem>), | ||
41 | } | ||
42 | 39 | ||
43 | impl ImportSourcePtr { | 40 | impl ImportSourcePtr { |
44 | fn to_node(self, file: &SourceFile) -> ImportSource { | 41 | fn to_node(self, file: &SourceFile) -> ImportSource { |
45 | match self { | 42 | self.map(|ptr| ptr.to_node(file).to_owned(), |ptr| ptr.to_node(file).to_owned()) |
46 | ImportSourcePtr::UseTree(ptr) => ImportSource::UseTree(ptr.to_node(file).to_owned()), | ||
47 | ImportSourcePtr::ExternCrate(ptr) => { | ||
48 | ImportSource::ExternCrate(ptr.to_node(file).to_owned()) | ||
49 | } | ||
50 | } | ||
51 | } | 43 | } |
52 | } | 44 | } |
53 | 45 | ||
54 | pub enum ImportSource { | ||
55 | UseTree(TreeArc<ast::UseTree>), | ||
56 | ExternCrate(TreeArc<ast::ExternCrateItem>), | ||
57 | } | ||
58 | |||
59 | impl ImportSourceMap { | 46 | impl ImportSourceMap { |
60 | fn insert(&mut self, import: ImportId, ptr: ImportSourcePtr) { | 47 | fn insert(&mut self, import: ImportId, ptr: ImportSourcePtr) { |
61 | self.map.insert(import, ptr) | 48 | self.map.insert(import, ptr) |
@@ -281,11 +268,7 @@ impl RawItemsCollector { | |||
281 | Path::expand_use_item(use_item, |path, use_tree, is_glob, alias| { | 268 | Path::expand_use_item(use_item, |path, use_tree, is_glob, alias| { |
282 | let import_data = | 269 | let import_data = |
283 | ImportData { path, alias, is_glob, is_prelude, is_extern_crate: false }; | 270 | ImportData { path, alias, is_glob, is_prelude, is_extern_crate: false }; |
284 | self.push_import( | 271 | self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree))); |
285 | current_module, | ||
286 | import_data, | ||
287 | ImportSourcePtr::UseTree(AstPtr::new(use_tree)), | ||
288 | ); | ||
289 | }) | 272 | }) |
290 | } | 273 | } |
291 | 274 | ||
@@ -304,11 +287,7 @@ impl RawItemsCollector { | |||
304 | is_prelude: false, | 287 | is_prelude: false, |
305 | is_extern_crate: true, | 288 | is_extern_crate: true, |
306 | }; | 289 | }; |
307 | self.push_import( | 290 | self.push_import(current_module, import_data, Either::B(AstPtr::new(extern_crate))); |
308 | current_module, | ||
309 | import_data, | ||
310 | ImportSourcePtr::ExternCrate(AstPtr::new(extern_crate)), | ||
311 | ); | ||
312 | } | 291 | } |
313 | } | 292 | } |
314 | 293 | ||