diff options
author | Aleksey Kladov <[email protected]> | 2018-08-17 19:10:55 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-17 19:10:55 +0100 |
commit | 70097504f78c4c41368a0b864a94df95fb9c27f7 (patch) | |
tree | c4034cab3c0d0b9488c0be538ae1d4c286570de9 /crates/libsyntax2/src/yellow/syntax.rs | |
parent | ed7ae78c6fd9e508f6e959c6a164cf8481f6b377 (diff) |
hide root
Diffstat (limited to 'crates/libsyntax2/src/yellow/syntax.rs')
-rw-r--r-- | crates/libsyntax2/src/yellow/syntax.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs index bb390751a..ef82ba408 100644 --- a/crates/libsyntax2/src/yellow/syntax.rs +++ b/crates/libsyntax2/src/yellow/syntax.rs | |||
@@ -3,14 +3,14 @@ use std::{fmt, sync::Arc}; | |||
3 | use smol_str::SmolStr; | 3 | use smol_str::SmolStr; |
4 | 4 | ||
5 | use { | 5 | use { |
6 | yellow::{RedNode, TreeRoot, SyntaxRoot, RedPtr}, | 6 | yellow::{RedNode, TreeRoot, SyntaxRoot, RedPtr, RefRoot, OwnedRoot}, |
7 | SyntaxKind::{self, *}, | 7 | SyntaxKind::{self, *}, |
8 | TextRange, TextUnit, | 8 | TextRange, TextUnit, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | 11 | ||
12 | #[derive(Clone, Copy)] | 12 | #[derive(Clone, Copy)] |
13 | pub struct SyntaxNode<R: TreeRoot = Arc<SyntaxRoot>> { | 13 | pub struct SyntaxNode<R: TreeRoot = OwnedRoot> { |
14 | pub(crate) root: R, | 14 | pub(crate) root: R, |
15 | // Guaranteed to not dangle, because `root` holds a | 15 | // Guaranteed to not dangle, because `root` holds a |
16 | // strong reference to red's ancestor | 16 | // strong reference to red's ancestor |
@@ -28,7 +28,7 @@ impl<R1: TreeRoot, R2: TreeRoot> PartialEq<SyntaxNode<R1>> for SyntaxNode<R2> { | |||
28 | 28 | ||
29 | impl<R: TreeRoot> Eq for SyntaxNode<R> {} | 29 | impl<R: TreeRoot> Eq for SyntaxNode<R> {} |
30 | 30 | ||
31 | pub type SyntaxNodeRef<'a> = SyntaxNode<&'a SyntaxRoot>; | 31 | pub type SyntaxNodeRef<'a> = SyntaxNode<RefRoot<'a>>; |
32 | 32 | ||
33 | #[test] | 33 | #[test] |
34 | fn syntax_node_ref_is_copy() { | 34 | fn syntax_node_ref_is_copy() { |
@@ -42,18 +42,18 @@ pub struct SyntaxError { | |||
42 | pub offset: TextUnit, | 42 | pub offset: TextUnit, |
43 | } | 43 | } |
44 | 44 | ||
45 | impl SyntaxNode<Arc<SyntaxRoot>> { | 45 | impl SyntaxNode<OwnedRoot> { |
46 | pub(crate) fn new_owned(root: SyntaxRoot) -> Self { | 46 | pub(crate) fn new_owned(root: SyntaxRoot) -> Self { |
47 | let root = Arc::new(root); | 47 | let root = OwnedRoot(Arc::new(root)); |
48 | let red = RedPtr::new(&root.red); | 48 | let red = RedPtr::new(&root.syntax_root().red); |
49 | SyntaxNode { root, red } | 49 | SyntaxNode { root, red } |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | impl<R: TreeRoot> SyntaxNode<R> { | 53 | impl<R: TreeRoot> SyntaxNode<R> { |
54 | pub fn as_ref<'a>(&'a self) -> SyntaxNode<&'a SyntaxRoot> { | 54 | pub fn as_ref<'a>(&'a self) -> SyntaxNode<RefRoot<'a>> { |
55 | SyntaxNode { | 55 | SyntaxNode { |
56 | root: &*self.root, | 56 | root: self.root.borrowed(), |
57 | red: self.red, | 57 | red: self.red, |
58 | } | 58 | } |
59 | } | 59 | } |