diff options
Diffstat (limited to 'crates/ra_syntax/src/yellow.rs')
-rw-r--r-- | crates/ra_syntax/src/yellow.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs index a7bfb80e2..ed48739f8 100644 --- a/crates/ra_syntax/src/yellow.rs +++ b/crates/ra_syntax/src/yellow.rs | |||
@@ -2,10 +2,11 @@ mod builder; | |||
2 | pub mod syntax_error; | 2 | pub mod syntax_error; |
3 | mod syntax_text; | 3 | mod syntax_text; |
4 | 4 | ||
5 | use std::{fmt, borrow::Borrow}; | ||
6 | |||
5 | use self::syntax_text::SyntaxText; | 7 | use self::syntax_text::SyntaxText; |
6 | use crate::{SmolStr, SyntaxKind, TextRange}; | 8 | use crate::{SmolStr, SyntaxKind, TextRange}; |
7 | use rowan::{Types, TransparentNewType}; | 9 | use rowan::{Types, TransparentNewType}; |
8 | use std::fmt; | ||
9 | 10 | ||
10 | pub(crate) use self::builder::GreenBuilder; | 11 | pub(crate) use self::builder::GreenBuilder; |
11 | pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location}; | 12 | pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location}; |
@@ -25,6 +26,12 @@ pub struct TreeArc<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>( | |||
25 | pub(crate) rowan::TreeArc<RaTypes, T>, | 26 | pub(crate) rowan::TreeArc<RaTypes, T>, |
26 | ); | 27 | ); |
27 | 28 | ||
29 | impl<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>> Borrow<T> for TreeArc<T> { | ||
30 | fn borrow(&self) -> &T { | ||
31 | &*self | ||
32 | } | ||
33 | } | ||
34 | |||
28 | impl<T> TreeArc<T> | 35 | impl<T> TreeArc<T> |
29 | where | 36 | where |
30 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 37 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |
@@ -124,6 +131,14 @@ impl SyntaxNode { | |||
124 | } | 131 | } |
125 | } | 132 | } |
126 | 133 | ||
134 | impl ToOwned for SyntaxNode { | ||
135 | type Owned = TreeArc<SyntaxNode>; | ||
136 | fn to_owned(&self) -> TreeArc<SyntaxNode> { | ||
137 | let ptr = TreeArc(self.0.to_owned()); | ||
138 | TreeArc::cast(ptr) | ||
139 | } | ||
140 | } | ||
141 | |||
127 | impl SyntaxNode { | 142 | impl SyntaxNode { |
128 | pub(crate) fn root_data(&self) -> &Vec<SyntaxError> { | 143 | pub(crate) fn root_data(&self) -> &Vec<SyntaxError> { |
129 | self.0.root_data() | 144 | self.0.root_data() |
@@ -133,11 +148,6 @@ impl SyntaxNode { | |||
133 | self.0.replace_self(replacement) | 148 | self.0.replace_self(replacement) |
134 | } | 149 | } |
135 | 150 | ||
136 | pub fn to_owned(&self) -> TreeArc<SyntaxNode> { | ||
137 | let ptr = TreeArc(self.0.to_owned()); | ||
138 | TreeArc::cast(ptr) | ||
139 | } | ||
140 | |||
141 | pub fn kind(&self) -> SyntaxKind { | 151 | pub fn kind(&self) -> SyntaxKind { |
142 | self.0.kind() | 152 | self.0.kind() |
143 | } | 153 | } |