aboutsummaryrefslogtreecommitdiff
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
parentd095d9273eb2c03d1c28e0122c21fccf4099660e (diff)
reduce visibility
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/source_id.rs2
-rw-r--r--crates/ra_hir_expand/src/ast_id_map.rs22
-rw-r--r--crates/ra_hir_expand/src/lib.rs3
4 files changed, 9 insertions, 20 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index ca261e8f5..227e93183 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -80,7 +80,7 @@ pub use self::{
80 path::{Path, PathKind}, 80 path::{Path, PathKind},
81 resolve::ScopeDef, 81 resolve::ScopeDef,
82 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, 82 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
83 source_id::{AstIdMap, ErasedFileAstId}, 83 source_id::AstIdMap,
84 ty::{ 84 ty::{
85 display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, 85 display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
86 }, 86 },
diff --git a/crates/ra_hir/src/source_id.rs b/crates/ra_hir/src/source_id.rs
index c69a2afeb..463b1d453 100644
--- a/crates/ra_hir/src/source_id.rs
+++ b/crates/ra_hir/src/source_id.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3pub use hir_expand::{ 3pub use hir_expand::{
4 ast_id_map::{AstIdMap, ErasedFileAstId, FileAstId}, 4 ast_id_map::{AstIdMap, FileAstId},
5 AstId, 5 AstId,
6}; 6};
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}