aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-29 12:25:46 +0000
committerAleksey Kladov <[email protected]>2019-10-29 12:25:46 +0000
commit2a5254c106df41dc53c34508e9f5ba77243b7a51 (patch)
tree23ba452140afc9d3305c741bad0f823aaf6f3c32 /crates/ra_hir_expand
parentd095d9273eb2c03d1c28e0122c21fccf4099660e (diff)
reduce visibility
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r--crates/ra_hir_expand/src/ast_id_map.rs22
-rw-r--r--crates/ra_hir_expand/src/lib.rs3
2 files changed, 7 insertions, 18 deletions
diff --git a/crates/ra_hir_expand/src/ast_id_map.rs b/crates/ra_hir_expand/src/ast_id_map.rs
index 2f43abe15..919ede0a0 100644
--- a/crates/ra_hir_expand/src/ast_id_map.rs
+++ b/crates/ra_hir_expand/src/ast_id_map.rs
@@ -8,11 +8,10 @@
8use std::{ 8use std::{
9 hash::{Hash, Hasher}, 9 hash::{Hash, Hasher},
10 marker::PhantomData, 10 marker::PhantomData,
11 ops,
12}; 11};
13 12
14use ra_arena::{impl_arena_id, Arena, RawId}; 13use ra_arena::{impl_arena_id, Arena, RawId};
15use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr}; 14use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
16 15
17/// `AstId` points to an AST node in a specific file. 16/// `AstId` points to an AST node in a specific file.
18#[derive(Debug)] 17#[derive(Debug)]
@@ -40,14 +39,8 @@ impl<N: AstNode> Hash for FileAstId<N> {
40 } 39 }
41} 40}
42 41
43impl<N: AstNode> From<FileAstId<N>> for ErasedFileAstId {
44 fn from(id: FileAstId<N>) -> Self {
45 id.raw
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 42#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
50pub struct ErasedFileAstId(RawId); 43struct ErasedFileAstId(RawId);
51impl_arena_id!(ErasedFileAstId); 44impl_arena_id!(ErasedFileAstId);
52 45
53/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back. 46/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back.
@@ -90,15 +83,12 @@ impl AstIdMap {
90 } 83 }
91 } 84 }
92 85
93 fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId { 86 pub fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
94 self.arena.alloc(SyntaxNodePtr::new(item)) 87 self.arena[id.raw].cast::<N>().unwrap()
95 } 88 }
96}
97 89
98impl ops::Index<ErasedFileAstId> for AstIdMap { 90 fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {
99 type Output = SyntaxNodePtr; 91 self.arena.alloc(SyntaxNodePtr::new(item))
100 fn index(&self, index: ErasedFileAstId) -> &SyntaxNodePtr {
101 &self.arena[index]
102 } 92 }
103} 93}
104 94
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 1fb124374..a31b9fa4c 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -172,7 +172,6 @@ impl<N: AstNode> AstId<N> {
172 172
173 pub fn to_node(&self, db: &impl AstDatabase) -> N { 173 pub fn to_node(&self, db: &impl AstDatabase) -> N {
174 let root = db.parse_or_expand(self.file_id).unwrap(); 174 let root = db.parse_or_expand(self.file_id).unwrap();
175 let node = db.ast_id_map(self.file_id)[self.file_ast_id.into()].to_node(&root); 175 db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
176 N::cast(node).unwrap()
177 } 176 }
178} 177}