diff options
author | Jonas Schievink <[email protected]> | 2020-06-22 14:07:06 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-06-24 15:53:16 +0100 |
commit | 4b03b39d5b4b00daffb120a4d2d9ea4a55a9a7ac (patch) | |
tree | 85431e53ce86bbcf16ba9b38fcc5f2ad27378722 /crates/ra_hir_expand/src/ast_id_map.rs | |
parent | b94caeb88b4aab7219d4b2f5c8c6c668199247fb (diff) |
draw the rest of the owl
Diffstat (limited to 'crates/ra_hir_expand/src/ast_id_map.rs')
-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 | ||