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/src/lib.rs | 2 +- crates/ra_hir/src/source_id.rs | 2 +- crates/ra_hir_expand/src/ast_id_map.rs | 22 ++++++---------------- crates/ra_hir_expand/src/lib.rs | 3 +-- 4 files changed, 9 insertions(+), 20 deletions(-) (limited to 'crates') 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::{ path::{Path, PathKind}, resolve::ScopeDef, source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, - source_id::{AstIdMap, ErasedFileAstId}, + source_id::AstIdMap, ty::{ display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, }, 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 @@ //! FIXME: write short doc here pub use hir_expand::{ - ast_id_map::{AstIdMap, ErasedFileAstId, FileAstId}, + ast_id_map::{AstIdMap, FileAstId}, AstId, }; 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