aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ptr.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs
index e049fce61..db6230aab 100644
--- a/crates/ra_syntax/src/ptr.rs
+++ b/crates/ra_syntax/src/ptr.rs
@@ -1,6 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use std::{iter::successors, marker::PhantomData}; 3use std::{
4 hash::{Hash, Hasher},
5 iter::successors,
6 marker::PhantomData,
7};
4 8
5use crate::{AstNode, SyntaxKind, SyntaxNode, TextRange}; 9use crate::{AstNode, SyntaxKind, SyntaxNode, TextRange};
6 10
@@ -43,7 +47,7 @@ impl SyntaxNodePtr {
43} 47}
44 48
45/// Like `SyntaxNodePtr`, but remembers the type of node 49/// Like `SyntaxNodePtr`, but remembers the type of node
46#[derive(Debug, Hash)] 50#[derive(Debug)]
47pub struct AstPtr<N: AstNode> { 51pub struct AstPtr<N: AstNode> {
48 raw: SyntaxNodePtr, 52 raw: SyntaxNodePtr,
49 _ty: PhantomData<fn() -> N>, 53 _ty: PhantomData<fn() -> N>,
@@ -64,6 +68,12 @@ impl<N: AstNode> PartialEq for AstPtr<N> {
64 } 68 }
65} 69}
66 70
71impl<N: AstNode> Hash for AstPtr<N> {
72 fn hash<H: Hasher>(&self, state: &mut H) {
73 self.raw.hash(state)
74 }
75}
76
67impl<N: AstNode> AstPtr<N> { 77impl<N: AstNode> AstPtr<N> {
68 pub fn new(node: &N) -> AstPtr<N> { 78 pub fn new(node: &N) -> AstPtr<N> {
69 AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } 79 AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData }