diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index ca261e8f54..227e931833 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 c69a2afeb6..463b1d4535 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 2f43abe152..919ede0a03 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,18 +83,15 @@ impl AstIdMap { } } + pub fn get(&self, id: FileAstId) -> AstPtr { + self.arena[id.raw].cast::().unwrap() + } + fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId { self.arena.alloc(SyntaxNodePtr::new(item)) } } -impl ops::Index for AstIdMap { - type Output = SyntaxNodePtr; - fn index(&self, index: ErasedFileAstId) -> &SyntaxNodePtr { - &self.arena[index] - } -} - /// Walks the subtree in bfs order, calling `f` for each node. fn bfs(node: &SyntaxNode, mut f: impl FnMut(SyntaxNode)) { let mut curr_layer = vec![node.clone()]; diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 1fb1243741..a31b9fa4cd 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) } }