From c1244c853c6bdc42bf91a77768963c0d287093ff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 00:27:00 +0200 Subject: Forward compat --- crates/ra_syntax/src/ptr.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'crates/ra_syntax') 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}; /// A pointer to a syntax node inside a file. It can be used to remember a /// specific node across reparses of the same file. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SyntaxNodePtr { pub(crate) range: TextRange, kind: SyntaxKind, @@ -21,7 +21,7 @@ impl SyntaxNodePtr { SyntaxNodePtr { range: node.text_range(), kind: node.kind() } } - pub fn to_node(self, root: &SyntaxNode) -> SyntaxNode { + pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode { assert!(root.parent().is_none()); successors(Some(root.clone()), |node| { node.children().find(|it| self.range.is_subrange(&it.text_range())) @@ -30,11 +30,11 @@ impl SyntaxNodePtr { .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) } - pub fn range(self) -> TextRange { + pub fn range(&self) -> TextRange { self.range } - pub fn kind(self) -> SyntaxKind { + pub fn kind(&self) -> SyntaxKind { self.kind } @@ -53,10 +53,9 @@ pub struct AstPtr { _ty: PhantomData N>, } -impl Copy for AstPtr {} impl Clone for AstPtr { fn clone(&self) -> AstPtr { - *self + AstPtr { raw: self.raw.clone(), _ty: PhantomData } } } @@ -79,13 +78,13 @@ impl AstPtr { AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } } - pub fn to_node(self, root: &SyntaxNode) -> N { + pub fn to_node(&self, root: &SyntaxNode) -> N { let syntax_node = self.raw.to_node(root); N::cast(syntax_node).unwrap() } - pub fn syntax_node_ptr(self) -> SyntaxNodePtr { - self.raw + pub fn syntax_node_ptr(&self) -> SyntaxNodePtr { + self.raw.clone() } pub fn cast(self) -> Option> { -- cgit v1.2.3