aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ptr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ptr.rs')
-rw-r--r--crates/ra_syntax/src/ptr.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs
index db6230aab..bc48a2e71 100644
--- a/crates/ra_syntax/src/ptr.rs
+++ b/crates/ra_syntax/src/ptr.rs
@@ -10,7 +10,7 @@ use crate::{AstNode, SyntaxKind, SyntaxNode, TextRange};
10 10
11/// A pointer to a syntax node inside a file. It can be used to remember a 11/// A pointer to a syntax node inside a file. It can be used to remember a
12/// specific node across reparses of the same file. 12/// specific node across reparses of the same file.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 13#[derive(Debug, Clone, PartialEq, Eq, Hash)]
14pub struct SyntaxNodePtr { 14pub struct SyntaxNodePtr {
15 pub(crate) range: TextRange, 15 pub(crate) range: TextRange,
16 kind: SyntaxKind, 16 kind: SyntaxKind,
@@ -21,7 +21,7 @@ impl SyntaxNodePtr {
21 SyntaxNodePtr { range: node.text_range(), kind: node.kind() } 21 SyntaxNodePtr { range: node.text_range(), kind: node.kind() }
22 } 22 }
23 23
24 pub fn to_node(self, root: &SyntaxNode) -> SyntaxNode { 24 pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode {
25 assert!(root.parent().is_none()); 25 assert!(root.parent().is_none());
26 successors(Some(root.clone()), |node| { 26 successors(Some(root.clone()), |node| {
27 node.children().find(|it| self.range.is_subrange(&it.text_range())) 27 node.children().find(|it| self.range.is_subrange(&it.text_range()))
@@ -30,11 +30,11 @@ impl SyntaxNodePtr {
30 .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) 30 .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self))
31 } 31 }
32 32
33 pub fn range(self) -> TextRange { 33 pub fn range(&self) -> TextRange {
34 self.range 34 self.range
35 } 35 }
36 36
37 pub fn kind(self) -> SyntaxKind { 37 pub fn kind(&self) -> SyntaxKind {
38 self.kind 38 self.kind
39 } 39 }
40 40
@@ -53,10 +53,9 @@ pub struct AstPtr<N: AstNode> {
53 _ty: PhantomData<fn() -> N>, 53 _ty: PhantomData<fn() -> N>,
54} 54}
55 55
56impl<N: AstNode> Copy for AstPtr<N> {}
57impl<N: AstNode> Clone for AstPtr<N> { 56impl<N: AstNode> Clone for AstPtr<N> {
58 fn clone(&self) -> AstPtr<N> { 57 fn clone(&self) -> AstPtr<N> {
59 *self 58 AstPtr { raw: self.raw.clone(), _ty: PhantomData }
60 } 59 }
61} 60}
62 61
@@ -79,13 +78,13 @@ impl<N: AstNode> AstPtr<N> {
79 AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } 78 AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData }
80 } 79 }
81 80
82 pub fn to_node(self, root: &SyntaxNode) -> N { 81 pub fn to_node(&self, root: &SyntaxNode) -> N {
83 let syntax_node = self.raw.to_node(root); 82 let syntax_node = self.raw.to_node(root);
84 N::cast(syntax_node).unwrap() 83 N::cast(syntax_node).unwrap()
85 } 84 }
86 85
87 pub fn syntax_node_ptr(self) -> SyntaxNodePtr { 86 pub fn syntax_node_ptr(&self) -> SyntaxNodePtr {
88 self.raw 87 self.raw.clone()
89 } 88 }
90 89
91 pub fn cast<U: AstNode>(self) -> Option<AstPtr<U>> { 90 pub fn cast<U: AstNode>(self) -> Option<AstPtr<U>> {