diff options
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/src/ast_id_map.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/ra_hir_expand/src/ast_id_map.rs b/crates/ra_hir_expand/src/ast_id_map.rs index d19569245..f4d31526a 100644 --- a/crates/ra_hir_expand/src/ast_id_map.rs +++ b/crates/ra_hir_expand/src/ast_id_map.rs | |||
@@ -6,6 +6,8 @@ | |||
6 | //! changes. | 6 | //! changes. |
7 | 7 | ||
8 | use std::{ | 8 | use std::{ |
9 | any::type_name, | ||
10 | fmt, | ||
9 | hash::{Hash, Hasher}, | 11 | hash::{Hash, Hasher}, |
10 | marker::PhantomData, | 12 | marker::PhantomData, |
11 | }; | 13 | }; |
@@ -14,7 +16,6 @@ use ra_arena::{Arena, Idx}; | |||
14 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; | 16 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; |
15 | 17 | ||
16 | /// `AstId` points to an AST node in a specific file. | 18 | /// `AstId` points to an AST node in a specific file. |
17 | #[derive(Debug)] | ||
18 | pub struct FileAstId<N: AstNode> { | 19 | pub struct FileAstId<N: AstNode> { |
19 | raw: ErasedFileAstId, | 20 | raw: ErasedFileAstId, |
20 | _ty: PhantomData<fn() -> N>, | 21 | _ty: PhantomData<fn() -> N>, |
@@ -39,11 +40,17 @@ impl<N: AstNode> Hash for FileAstId<N> { | |||
39 | } | 40 | } |
40 | } | 41 | } |
41 | 42 | ||
43 | impl<N: AstNode> fmt::Debug for FileAstId<N> { | ||
44 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
45 | write!(f, "FileAstId::<{}>({})", type_name::<N>(), self.raw.into_raw()) | ||
46 | } | ||
47 | } | ||
48 | |||
42 | impl<N: AstNode> FileAstId<N> { | 49 | impl<N: AstNode> FileAstId<N> { |
43 | // Can't make this a From implementation because of coherence | 50 | // Can't make this a From implementation because of coherence |
44 | pub fn upcast<M: AstNode>(self) -> FileAstId<M> | 51 | pub fn upcast<M: AstNode>(self) -> FileAstId<M> |
45 | where | 52 | where |
46 | M: From<N>, | 53 | N: Into<M>, |
47 | { | 54 | { |
48 | FileAstId { raw: self.raw, _ty: PhantomData } | 55 | FileAstId { raw: self.raw, _ty: PhantomData } |
49 | } | 56 | } |
@@ -89,7 +96,7 @@ impl AstIdMap { | |||
89 | } | 96 | } |
90 | } | 97 | } |
91 | 98 | ||
92 | pub(crate) fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> { | 99 | pub fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> { |
93 | self.arena[id.raw].clone().cast::<N>().unwrap() | 100 | self.arena[id.raw].clone().cast::<N>().unwrap() |
94 | } | 101 | } |
95 | 102 | ||