aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/yellow/syntax.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/yellow/syntax.rs')
-rw-r--r--crates/libsyntax2/src/yellow/syntax.rs16
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};
3use smol_str::SmolStr; 3use smol_str::SmolStr;
4 4
5use { 5use {
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)]
13pub struct SyntaxNode<R: TreeRoot = Arc<SyntaxRoot>> { 13pub 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
29impl<R: TreeRoot> Eq for SyntaxNode<R> {} 29impl<R: TreeRoot> Eq for SyntaxNode<R> {}
30 30
31pub type SyntaxNodeRef<'a> = SyntaxNode<&'a SyntaxRoot>; 31pub type SyntaxNodeRef<'a> = SyntaxNode<RefRoot<'a>>;
32 32
33#[test] 33#[test]
34fn syntax_node_ref_is_copy() { 34fn syntax_node_ref_is_copy() {
@@ -42,18 +42,18 @@ pub struct SyntaxError {
42 pub offset: TextUnit, 42 pub offset: TextUnit,
43} 43}
44 44
45impl SyntaxNode<Arc<SyntaxRoot>> { 45impl 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
53impl<R: TreeRoot> SyntaxNode<R> { 53impl<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 }