From 2a5254c106df41dc53c34508e9f5ba77243b7a51 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 29 Oct 2019 15:25:46 +0300 Subject: reduce visibility --- crates/ra_hir_expand/src/ast_id_map.rs | 22 ++++++---------------- crates/ra_hir_expand/src/lib.rs | 3 +-- 2 files changed, 7 insertions(+), 18 deletions(-) (limited to 'crates/ra_hir_expand') 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 @@ use std::{ hash::{Hash, Hasher}, marker::PhantomData, - ops, }; use ra_arena::{impl_arena_id, Arena, RawId}; -use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr}; +use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; /// `AstId` points to an AST node in a specific file. #[derive(Debug)] @@ -40,14 +39,8 @@ impl Hash for FileAstId { } } -impl From> for ErasedFileAstId { - fn from(id: FileAstId) -> Self { - id.raw - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct ErasedFileAstId(RawId); +struct ErasedFileAstId(RawId); impl_arena_id!(ErasedFileAstId); /// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back. @@ -90,15 +83,12 @@ impl AstIdMap { } } - fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId { - self.arena.alloc(SyntaxNodePtr::new(item)) + pub fn get(&self, id: FileAstId) -> AstPtr { + self.arena[id.raw].cast::().unwrap() } -} -impl ops::Index for AstIdMap { - type Output = SyntaxNodePtr; - fn index(&self, index: ErasedFileAstId) -> &SyntaxNodePtr { - &self.arena[index] + fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId { + self.arena.alloc(SyntaxNodePtr::new(item)) } } 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 AstId { pub fn to_node(&self, db: &impl AstDatabase) -> N { let root = db.parse_or_expand(self.file_id).unwrap(); - let node = db.ast_id_map(self.file_id)[self.file_ast_id.into()].to_node(&root); - N::cast(node).unwrap() + db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) } } -- cgit v1.2.3