diff options
author | Aleksey Kladov <[email protected]> | 2020-04-10 23:27:00 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-10 23:27:00 +0100 |
commit | c1244c853c6bdc42bf91a77768963c0d287093ff (patch) | |
tree | c7f96c8f170c43d4a65451e089783ba6550ca020 /crates/ra_syntax/src | |
parent | ca9a5dd1654cc0d54ed5b2bb71ec8ed559470276 (diff) |
Forward compat
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ptr.rs | 17 |
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)] |
14 | pub struct SyntaxNodePtr { | 14 | pub 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 | ||
56 | impl<N: AstNode> Copy for AstPtr<N> {} | ||
57 | impl<N: AstNode> Clone for AstPtr<N> { | 56 | impl<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>> { |