diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 16 | ||||
-rw-r--r-- | crates/ra_syntax/src/algo/visit.rs | 30 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 328 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 4850 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs.tera | 93 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 15 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 38 | ||||
-rw-r--r-- | crates/ra_syntax/src/reparsing.rs | 35 | ||||
-rw-r--r-- | crates/ra_syntax/src/syntax_kinds/generated.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/utils.rs | 17 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation.rs | 15 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/byte.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/byte_string.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/char.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/string.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow.rs | 148 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_text.rs | 6 |
17 files changed, 2221 insertions, 3412 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index 4b3548ea9..13f50d2ef 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -1,19 +1,23 @@ | |||
1 | pub mod visit; | 1 | pub mod visit; |
2 | 2 | ||
3 | use crate::{SyntaxNode, SyntaxNodeRef, TextRange, TextUnit}; | 3 | use rowan::TransparentNewType; |
4 | |||
5 | use crate::{SyntaxNode, TextRange, TextUnit}; | ||
4 | 6 | ||
5 | pub use rowan::LeafAtOffset; | 7 | pub use rowan::LeafAtOffset; |
6 | 8 | ||
7 | pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset<SyntaxNodeRef> { | 9 | pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset<&SyntaxNode> { |
8 | match node.0.leaf_at_offset(offset) { | 10 | match node.0.leaf_at_offset(offset) { |
9 | LeafAtOffset::None => LeafAtOffset::None, | 11 | LeafAtOffset::None => LeafAtOffset::None, |
10 | LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode(n)), | 12 | LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode::from_repr(n)), |
11 | LeafAtOffset::Between(l, r) => LeafAtOffset::Between(SyntaxNode(l), SyntaxNode(r)), | 13 | LeafAtOffset::Between(l, r) => { |
14 | LeafAtOffset::Between(SyntaxNode::from_repr(l), SyntaxNode::from_repr(r)) | ||
15 | } | ||
12 | } | 16 | } |
13 | } | 17 | } |
14 | 18 | ||
15 | pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { | 19 | pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { |
16 | SyntaxNode(root.0.covering_node(range)) | 20 | SyntaxNode::from_repr(root.0.covering_node(range)) |
17 | } | 21 | } |
18 | 22 | ||
19 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { | 23 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { |
diff --git a/crates/ra_syntax/src/algo/visit.rs b/crates/ra_syntax/src/algo/visit.rs index c021f464c..38f21594c 100644 --- a/crates/ra_syntax/src/algo/visit.rs +++ b/crates/ra_syntax/src/algo/visit.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{AstNode, SyntaxNodeRef}; | 1 | use crate::{AstNode, SyntaxNode}; |
2 | 2 | ||
3 | use std::marker::PhantomData; | 3 | use std::marker::PhantomData; |
4 | 4 | ||
@@ -15,11 +15,11 @@ pub fn visitor_ctx<'a, T, C>(ctx: C) -> impl VisitorCtx<'a, Output = T, Ctx = C> | |||
15 | 15 | ||
16 | pub trait Visitor<'a>: Sized { | 16 | pub trait Visitor<'a>: Sized { |
17 | type Output; | 17 | type Output; |
18 | fn accept(self, node: SyntaxNodeRef<'a>) -> Option<Self::Output>; | 18 | fn accept(self, node: &'a SyntaxNode) -> Option<Self::Output>; |
19 | fn visit<N, F>(self, f: F) -> Vis<Self, N, F> | 19 | fn visit<N, F>(self, f: F) -> Vis<Self, N, F> |
20 | where | 20 | where |
21 | N: AstNode<'a>, | 21 | N: AstNode + 'a, |
22 | F: FnOnce(N) -> Self::Output, | 22 | F: FnOnce(&'a N) -> Self::Output, |
23 | { | 23 | { |
24 | Vis { | 24 | Vis { |
25 | inner: self, | 25 | inner: self, |
@@ -32,11 +32,11 @@ pub trait Visitor<'a>: Sized { | |||
32 | pub trait VisitorCtx<'a>: Sized { | 32 | pub trait VisitorCtx<'a>: Sized { |
33 | type Output; | 33 | type Output; |
34 | type Ctx; | 34 | type Ctx; |
35 | fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx>; | 35 | fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx>; |
36 | fn visit<N, F>(self, f: F) -> VisCtx<Self, N, F> | 36 | fn visit<N, F>(self, f: F) -> VisCtx<Self, N, F> |
37 | where | 37 | where |
38 | N: AstNode<'a>, | 38 | N: AstNode + 'a, |
39 | F: FnOnce(N, Self::Ctx) -> Self::Output, | 39 | F: FnOnce(&'a N, Self::Ctx) -> Self::Output, |
40 | { | 40 | { |
41 | VisCtx { | 41 | VisCtx { |
42 | inner: self, | 42 | inner: self, |
@@ -54,7 +54,7 @@ struct EmptyVisitor<T> { | |||
54 | impl<'a, T> Visitor<'a> for EmptyVisitor<T> { | 54 | impl<'a, T> Visitor<'a> for EmptyVisitor<T> { |
55 | type Output = T; | 55 | type Output = T; |
56 | 56 | ||
57 | fn accept(self, _node: SyntaxNodeRef<'a>) -> Option<T> { | 57 | fn accept(self, _node: &'a SyntaxNode) -> Option<T> { |
58 | None | 58 | None |
59 | } | 59 | } |
60 | } | 60 | } |
@@ -69,7 +69,7 @@ impl<'a, T, C> VisitorCtx<'a> for EmptyVisitorCtx<T, C> { | |||
69 | type Output = T; | 69 | type Output = T; |
70 | type Ctx = C; | 70 | type Ctx = C; |
71 | 71 | ||
72 | fn accept(self, _node: SyntaxNodeRef<'a>) -> Result<T, C> { | 72 | fn accept(self, _node: &'a SyntaxNode) -> Result<T, C> { |
73 | Err(self.ctx) | 73 | Err(self.ctx) |
74 | } | 74 | } |
75 | } | 75 | } |
@@ -84,12 +84,12 @@ pub struct Vis<V, N, F> { | |||
84 | impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> | 84 | impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> |
85 | where | 85 | where |
86 | V: Visitor<'a>, | 86 | V: Visitor<'a>, |
87 | N: AstNode<'a>, | 87 | N: AstNode + 'a, |
88 | F: FnOnce(N) -> <V as Visitor<'a>>::Output, | 88 | F: FnOnce(&'a N) -> <V as Visitor<'a>>::Output, |
89 | { | 89 | { |
90 | type Output = <V as Visitor<'a>>::Output; | 90 | type Output = <V as Visitor<'a>>::Output; |
91 | 91 | ||
92 | fn accept(self, node: SyntaxNodeRef<'a>) -> Option<Self::Output> { | 92 | fn accept(self, node: &'a SyntaxNode) -> Option<Self::Output> { |
93 | let Vis { inner, f, .. } = self; | 93 | let Vis { inner, f, .. } = self; |
94 | inner.accept(node).or_else(|| N::cast(node).map(f)) | 94 | inner.accept(node).or_else(|| N::cast(node).map(f)) |
95 | } | 95 | } |
@@ -105,13 +105,13 @@ pub struct VisCtx<V, N, F> { | |||
105 | impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> | 105 | impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> |
106 | where | 106 | where |
107 | V: VisitorCtx<'a>, | 107 | V: VisitorCtx<'a>, |
108 | N: AstNode<'a>, | 108 | N: AstNode + 'a, |
109 | F: FnOnce(N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output, | 109 | F: FnOnce(&'a N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output, |
110 | { | 110 | { |
111 | type Output = <V as VisitorCtx<'a>>::Output; | 111 | type Output = <V as VisitorCtx<'a>>::Output; |
112 | type Ctx = <V as VisitorCtx<'a>>::Ctx; | 112 | type Ctx = <V as VisitorCtx<'a>>::Ctx; |
113 | 113 | ||
114 | fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx> { | 114 | fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx> { |
115 | let VisCtx { inner, f, .. } = self; | 115 | let VisCtx { inner, f, .. } = self; |
116 | inner.accept(node).or_else(|ctx| match N::cast(node) { | 116 | inner.accept(node).or_else(|ctx| match N::cast(node) { |
117 | None => Err(ctx), | 117 | None => Err(ctx), |
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 9df8ec663..d25b5642b 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -1,119 +1,121 @@ | |||
1 | mod generated; | 1 | mod generated; |
2 | 2 | ||
3 | use std::marker::PhantomData; | 3 | use std::marker::PhantomData; |
4 | use std::string::String as RustString; | ||
5 | 4 | ||
6 | use itertools::Itertools; | 5 | use itertools::Itertools; |
7 | 6 | ||
8 | pub use self::generated::*; | 7 | pub use self::generated::*; |
9 | use crate::{ | 8 | use crate::{ |
10 | yellow::{RefRoot, SyntaxNodeChildren}, | 9 | yellow::{SyntaxNode, SyntaxNodeChildren, TreePtr, RaTypes}, |
11 | SmolStr, | 10 | SmolStr, |
12 | SyntaxKind::*, | 11 | SyntaxKind::*, |
13 | SyntaxNodeRef, | ||
14 | }; | 12 | }; |
15 | 13 | ||
16 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The | 14 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The |
17 | /// conversion itself has zero runtime cost: ast and syntax nodes have exactly | 15 | /// conversion itself has zero runtime cost: ast and syntax nodes have exactly |
18 | /// the same representation: a pointer to the tree root and a pointer to the | 16 | /// the same representation: a pointer to the tree root and a pointer to the |
19 | /// node itself. | 17 | /// node itself. |
20 | pub trait AstNode<'a>: Clone + Copy + 'a { | 18 | pub trait AstNode: rowan::TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>> { |
21 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> | 19 | fn cast(syntax: &SyntaxNode) -> Option<&Self> |
22 | where | 20 | where |
23 | Self: Sized; | 21 | Self: Sized; |
24 | fn syntax(self) -> SyntaxNodeRef<'a>; | 22 | fn syntax(&self) -> &SyntaxNode; |
23 | fn to_owned(&self) -> TreePtr<Self>; | ||
25 | } | 24 | } |
26 | 25 | ||
27 | pub trait NameOwner<'a>: AstNode<'a> { | 26 | pub trait AstToken: AstNode { |
28 | fn name(self) -> Option<Name<'a>> { | 27 | fn text(&self) -> &SmolStr { |
28 | self.syntax().leaf_text().unwrap() | ||
29 | } | ||
30 | } | ||
31 | |||
32 | pub trait NameOwner: AstNode { | ||
33 | fn name(&self) -> Option<&Name> { | ||
29 | child_opt(self) | 34 | child_opt(self) |
30 | } | 35 | } |
31 | } | 36 | } |
32 | 37 | ||
33 | pub trait VisibilityOwner<'a>: AstNode<'a> { | 38 | pub trait VisibilityOwner: AstNode { |
34 | fn visibility(self) -> Option<Visibility<'a>> { | 39 | fn visibility(&self) -> Option<&Visibility> { |
35 | child_opt(self) | 40 | child_opt(self) |
36 | } | 41 | } |
37 | } | 42 | } |
38 | 43 | ||
39 | pub trait LoopBodyOwner<'a>: AstNode<'a> { | 44 | pub trait LoopBodyOwner: AstNode { |
40 | fn loop_body(self) -> Option<Block<'a>> { | 45 | fn loop_body(&self) -> Option<&Block> { |
41 | child_opt(self) | 46 | child_opt(self) |
42 | } | 47 | } |
43 | } | 48 | } |
44 | 49 | ||
45 | pub trait ArgListOwner<'a>: AstNode<'a> { | 50 | pub trait ArgListOwner: AstNode { |
46 | fn arg_list(self) -> Option<ArgList<'a>> { | 51 | fn arg_list(&self) -> Option<&ArgList> { |
47 | child_opt(self) | 52 | child_opt(self) |
48 | } | 53 | } |
49 | } | 54 | } |
50 | 55 | ||
51 | pub trait FnDefOwner<'a>: AstNode<'a> { | 56 | pub trait FnDefOwner: AstNode { |
52 | fn functions(self) -> AstChildren<'a, FnDef<'a>> { | 57 | fn functions(&self) -> AstChildren<FnDef> { |
53 | children(self) | 58 | children(self) |
54 | } | 59 | } |
55 | } | 60 | } |
56 | 61 | ||
57 | // ModuleItem | ||
58 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 62 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
59 | pub enum ItemOrMacro<'a> { | 63 | pub enum ItemOrMacro<'a> { |
60 | Item(ModuleItem<'a>), | 64 | Item(&'a ModuleItem), |
61 | Macro(MacroCall<'a>), | 65 | Macro(&'a MacroCall), |
62 | } | 66 | } |
63 | 67 | ||
64 | impl<'a> AstNode<'a> for ItemOrMacro<'a> { | 68 | pub trait ModuleItemOwner: AstNode { |
65 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 69 | fn items(&self) -> AstChildren<ModuleItem> { |
66 | let res = if let Some(item) = ModuleItem::cast(syntax) { | 70 | children(self) |
67 | ItemOrMacro::Item(item) | ||
68 | } else if let Some(macro_call) = MacroCall::cast(syntax) { | ||
69 | ItemOrMacro::Macro(macro_call) | ||
70 | } else { | ||
71 | return None; | ||
72 | }; | ||
73 | Some(res) | ||
74 | } | 71 | } |
75 | fn syntax(self) -> SyntaxNodeRef<'a> { | 72 | fn items_with_macros(&self) -> ItemOrMacroIter { |
76 | match self { | 73 | ItemOrMacroIter(self.syntax().children()) |
77 | ItemOrMacro::Item(it) => it.syntax(), | ||
78 | ItemOrMacro::Macro(it) => it.syntax(), | ||
79 | } | ||
80 | } | 74 | } |
81 | } | 75 | } |
82 | 76 | ||
83 | pub trait ModuleItemOwner<'a>: AstNode<'a> { | 77 | #[derive(Debug)] |
84 | fn items(self) -> AstChildren<'a, ModuleItem<'a>> { | 78 | pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>); |
85 | children(self) | ||
86 | } | ||
87 | 79 | ||
88 | fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> { | 80 | impl<'a> Iterator for ItemOrMacroIter<'a> { |
89 | children(self) | 81 | type Item = ItemOrMacro<'a>; |
82 | fn next(&mut self) -> Option<ItemOrMacro<'a>> { | ||
83 | loop { | ||
84 | let n = self.0.next()?; | ||
85 | if let Some(item) = ModuleItem::cast(n) { | ||
86 | return Some(ItemOrMacro::Item(item)); | ||
87 | } | ||
88 | if let Some(call) = MacroCall::cast(n) { | ||
89 | return Some(ItemOrMacro::Macro(call)); | ||
90 | } | ||
91 | } | ||
90 | } | 92 | } |
91 | } | 93 | } |
92 | 94 | ||
93 | pub trait TypeParamsOwner<'a>: AstNode<'a> { | 95 | pub trait TypeParamsOwner: AstNode { |
94 | fn type_param_list(self) -> Option<TypeParamList<'a>> { | 96 | fn type_param_list(&self) -> Option<&TypeParamList> { |
95 | child_opt(self) | 97 | child_opt(self) |
96 | } | 98 | } |
97 | 99 | ||
98 | fn where_clause(self) -> Option<WhereClause<'a>> { | 100 | fn where_clause(&self) -> Option<&WhereClause> { |
99 | child_opt(self) | 101 | child_opt(self) |
100 | } | 102 | } |
101 | } | 103 | } |
102 | 104 | ||
103 | pub trait AttrsOwner<'a>: AstNode<'a> { | 105 | pub trait AttrsOwner: AstNode { |
104 | fn attrs(self) -> AstChildren<'a, Attr<'a>> { | 106 | fn attrs(&self) -> AstChildren<Attr> { |
105 | children(self) | 107 | children(self) |
106 | } | 108 | } |
107 | } | 109 | } |
108 | 110 | ||
109 | pub trait DocCommentsOwner<'a>: AstNode<'a> { | 111 | pub trait DocCommentsOwner: AstNode { |
110 | fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { | 112 | fn doc_comments(&self) -> AstChildren<Comment> { |
111 | children(self) | 113 | children(self) |
112 | } | 114 | } |
113 | 115 | ||
114 | /// Returns the textual content of a doc comment block as a single string. | 116 | /// Returns the textual content of a doc comment block as a single string. |
115 | /// That is, strips leading `///` and joins lines | 117 | /// That is, strips leading `///` and joins lines |
116 | fn doc_comment_text(self) -> RustString { | 118 | fn doc_comment_text(&self) -> std::string::String { |
117 | self.doc_comments() | 119 | self.doc_comments() |
118 | .filter(|comment| comment.is_doc_comment()) | 120 | .filter(|comment| comment.is_doc_comment()) |
119 | .map(|comment| { | 121 | .map(|comment| { |
@@ -130,13 +132,13 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> { | |||
130 | } | 132 | } |
131 | } | 133 | } |
132 | 134 | ||
133 | impl<'a> FnDef<'a> { | 135 | impl FnDef { |
134 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 136 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
135 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) | 137 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) |
136 | } | 138 | } |
137 | } | 139 | } |
138 | 140 | ||
139 | impl<'a> Attr<'a> { | 141 | impl Attr { |
140 | pub fn as_atom(&self) -> Option<SmolStr> { | 142 | pub fn as_atom(&self) -> Option<SmolStr> { |
141 | let tt = self.value()?; | 143 | let tt = self.value()?; |
142 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; | 144 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; |
@@ -147,7 +149,7 @@ impl<'a> Attr<'a> { | |||
147 | } | 149 | } |
148 | } | 150 | } |
149 | 151 | ||
150 | pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> { | 152 | pub fn as_call(&self) -> Option<(SmolStr, &TokenTree)> { |
151 | let tt = self.value()?; | 153 | let tt = self.value()?; |
152 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; | 154 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; |
153 | let args = TokenTree::cast(args)?; | 155 | let args = TokenTree::cast(args)?; |
@@ -159,41 +161,7 @@ impl<'a> Attr<'a> { | |||
159 | } | 161 | } |
160 | } | 162 | } |
161 | 163 | ||
162 | impl<'a> Lifetime<'a> { | 164 | impl Comment { |
163 | pub fn text(&self) -> SmolStr { | ||
164 | self.syntax().leaf_text().unwrap().clone() | ||
165 | } | ||
166 | } | ||
167 | |||
168 | impl<'a> Char<'a> { | ||
169 | pub fn text(&self) -> &SmolStr { | ||
170 | &self.syntax().leaf_text().unwrap() | ||
171 | } | ||
172 | } | ||
173 | |||
174 | impl<'a> Byte<'a> { | ||
175 | pub fn text(&self) -> &SmolStr { | ||
176 | &self.syntax().leaf_text().unwrap() | ||
177 | } | ||
178 | } | ||
179 | |||
180 | impl<'a> ByteString<'a> { | ||
181 | pub fn text(&self) -> &SmolStr { | ||
182 | &self.syntax().leaf_text().unwrap() | ||
183 | } | ||
184 | } | ||
185 | |||
186 | impl<'a> String<'a> { | ||
187 | pub fn text(&self) -> &SmolStr { | ||
188 | &self.syntax().leaf_text().unwrap() | ||
189 | } | ||
190 | } | ||
191 | |||
192 | impl<'a> Comment<'a> { | ||
193 | pub fn text(&self) -> &SmolStr { | ||
194 | self.syntax().leaf_text().unwrap() | ||
195 | } | ||
196 | |||
197 | pub fn flavor(&self) -> CommentFlavor { | 165 | pub fn flavor(&self) -> CommentFlavor { |
198 | let text = self.text(); | 166 | let text = self.text(); |
199 | if text.starts_with("///") { | 167 | if text.starts_with("///") { |
@@ -251,50 +219,46 @@ impl CommentFlavor { | |||
251 | } | 219 | } |
252 | } | 220 | } |
253 | 221 | ||
254 | impl<'a> Whitespace<'a> { | 222 | impl Whitespace { |
255 | pub fn text(&self) -> &SmolStr { | ||
256 | &self.syntax().leaf_text().unwrap() | ||
257 | } | ||
258 | |||
259 | pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> { | 223 | pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> { |
260 | self.text().chars().filter(|&c| c == '\n').map(|_| &()) | 224 | self.text().chars().filter(|&c| c == '\n').map(|_| &()) |
261 | } | 225 | } |
262 | 226 | ||
263 | pub fn has_newlines(&self) -> bool { | 227 | pub fn has_newlines(&self) -> bool { |
264 | self.count_newlines_lazy().count() > 0 | 228 | self.text().contains('\n') |
265 | } | 229 | } |
266 | } | 230 | } |
267 | 231 | ||
268 | impl<'a> Name<'a> { | 232 | impl Name { |
269 | pub fn text(&self) -> SmolStr { | 233 | pub fn text(&self) -> &SmolStr { |
270 | let ident = self.syntax().first_child().unwrap(); | 234 | let ident = self.syntax().first_child().unwrap(); |
271 | ident.leaf_text().unwrap().clone() | 235 | ident.leaf_text().unwrap() |
272 | } | 236 | } |
273 | } | 237 | } |
274 | 238 | ||
275 | impl<'a> NameRef<'a> { | 239 | impl NameRef { |
276 | pub fn text(&self) -> SmolStr { | 240 | pub fn text(&self) -> &SmolStr { |
277 | let ident = self.syntax().first_child().unwrap(); | 241 | let ident = self.syntax().first_child().unwrap(); |
278 | ident.leaf_text().unwrap().clone() | 242 | ident.leaf_text().unwrap() |
279 | } | 243 | } |
280 | } | 244 | } |
281 | 245 | ||
282 | impl<'a> ImplBlock<'a> { | 246 | impl ImplBlock { |
283 | pub fn target_type(self) -> Option<TypeRef<'a>> { | 247 | pub fn target_type(&self) -> Option<&TypeRef> { |
284 | match self.target() { | 248 | match self.target() { |
285 | (Some(t), None) | (_, Some(t)) => Some(t), | 249 | (Some(t), None) | (_, Some(t)) => Some(t), |
286 | _ => None, | 250 | _ => None, |
287 | } | 251 | } |
288 | } | 252 | } |
289 | 253 | ||
290 | pub fn target_trait(self) -> Option<TypeRef<'a>> { | 254 | pub fn target_trait(&self) -> Option<&TypeRef> { |
291 | match self.target() { | 255 | match self.target() { |
292 | (Some(t), Some(_)) => Some(t), | 256 | (Some(t), Some(_)) => Some(t), |
293 | _ => None, | 257 | _ => None, |
294 | } | 258 | } |
295 | } | 259 | } |
296 | 260 | ||
297 | fn target(self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) { | 261 | fn target(&self) -> (Option<&TypeRef>, Option<&TypeRef>) { |
298 | let mut types = children(self); | 262 | let mut types = children(self); |
299 | let first = types.next(); | 263 | let first = types.next(); |
300 | let second = types.next(); | 264 | let second = types.next(); |
@@ -302,8 +266,8 @@ impl<'a> ImplBlock<'a> { | |||
302 | } | 266 | } |
303 | } | 267 | } |
304 | 268 | ||
305 | impl<'a> Module<'a> { | 269 | impl Module { |
306 | pub fn has_semi(self) -> bool { | 270 | pub fn has_semi(&self) -> bool { |
307 | match self.syntax().last_child() { | 271 | match self.syntax().last_child() { |
308 | None => false, | 272 | None => false, |
309 | Some(node) => node.kind() == SEMI, | 273 | Some(node) => node.kind() == SEMI, |
@@ -311,8 +275,8 @@ impl<'a> Module<'a> { | |||
311 | } | 275 | } |
312 | } | 276 | } |
313 | 277 | ||
314 | impl<'a> LetStmt<'a> { | 278 | impl LetStmt { |
315 | pub fn has_semi(self) -> bool { | 279 | pub fn has_semi(&self) -> bool { |
316 | match self.syntax().last_child() { | 280 | match self.syntax().last_child() { |
317 | None => false, | 281 | None => false, |
318 | Some(node) => node.kind() == SEMI, | 282 | Some(node) => node.kind() == SEMI, |
@@ -320,35 +284,35 @@ impl<'a> LetStmt<'a> { | |||
320 | } | 284 | } |
321 | } | 285 | } |
322 | 286 | ||
323 | impl<'a> IfExpr<'a> { | 287 | impl IfExpr { |
324 | pub fn then_branch(self) -> Option<Block<'a>> { | 288 | pub fn then_branch(&self) -> Option<&Block> { |
325 | self.blocks().nth(0) | 289 | self.blocks().nth(0) |
326 | } | 290 | } |
327 | pub fn else_branch(self) -> Option<Block<'a>> { | 291 | pub fn else_branch(&self) -> Option<&Block> { |
328 | self.blocks().nth(1) | 292 | self.blocks().nth(1) |
329 | } | 293 | } |
330 | fn blocks(self) -> AstChildren<'a, Block<'a>> { | 294 | fn blocks(&self) -> AstChildren<Block> { |
331 | children(self) | 295 | children(self) |
332 | } | 296 | } |
333 | } | 297 | } |
334 | 298 | ||
335 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 299 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
336 | pub enum PathSegmentKind<'a> { | 300 | pub enum PathSegmentKind<'a> { |
337 | Name(NameRef<'a>), | 301 | Name(&'a NameRef), |
338 | SelfKw, | 302 | SelfKw, |
339 | SuperKw, | 303 | SuperKw, |
340 | CrateKw, | 304 | CrateKw, |
341 | } | 305 | } |
342 | 306 | ||
343 | impl<'a> PathSegment<'a> { | 307 | impl PathSegment { |
344 | pub fn parent_path(self) -> Path<'a> { | 308 | pub fn parent_path(&self) -> &Path { |
345 | self.syntax() | 309 | self.syntax() |
346 | .parent() | 310 | .parent() |
347 | .and_then(Path::cast) | 311 | .and_then(Path::cast) |
348 | .expect("segments are always nested in paths") | 312 | .expect("segments are always nested in paths") |
349 | } | 313 | } |
350 | 314 | ||
351 | pub fn kind(self) -> Option<PathSegmentKind<'a>> { | 315 | pub fn kind(&self) -> Option<PathSegmentKind> { |
352 | let res = if let Some(name_ref) = self.name_ref() { | 316 | let res = if let Some(name_ref) = self.name_ref() { |
353 | PathSegmentKind::Name(name_ref) | 317 | PathSegmentKind::Name(name_ref) |
354 | } else { | 318 | } else { |
@@ -363,20 +327,20 @@ impl<'a> PathSegment<'a> { | |||
363 | } | 327 | } |
364 | } | 328 | } |
365 | 329 | ||
366 | impl<'a> Path<'a> { | 330 | impl Path { |
367 | pub fn parent_path(self) -> Option<Path<'a>> { | 331 | pub fn parent_path(&self) -> Option<&Path> { |
368 | self.syntax().parent().and_then(Path::cast) | 332 | self.syntax().parent().and_then(Path::cast) |
369 | } | 333 | } |
370 | } | 334 | } |
371 | 335 | ||
372 | impl<'a> UseTree<'a> { | 336 | impl UseTree { |
373 | pub fn has_star(self) -> bool { | 337 | pub fn has_star(&self) -> bool { |
374 | self.syntax().children().any(|it| it.kind() == STAR) | 338 | self.syntax().children().any(|it| it.kind() == STAR) |
375 | } | 339 | } |
376 | } | 340 | } |
377 | 341 | ||
378 | impl<'a> UseTreeList<'a> { | 342 | impl UseTreeList { |
379 | pub fn parent_use_tree(self) -> UseTree<'a> { | 343 | pub fn parent_use_tree(&self) -> &UseTree { |
380 | self.syntax() | 344 | self.syntax() |
381 | .parent() | 345 | .parent() |
382 | .and_then(UseTree::cast) | 346 | .and_then(UseTree::cast) |
@@ -384,22 +348,22 @@ impl<'a> UseTreeList<'a> { | |||
384 | } | 348 | } |
385 | } | 349 | } |
386 | 350 | ||
387 | fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { | 351 | fn child_opt<P: AstNode, C: AstNode>(parent: &P) -> Option<&C> { |
388 | children(parent).next() | 352 | children(parent).next() |
389 | } | 353 | } |
390 | 354 | ||
391 | fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> { | 355 | fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> { |
392 | AstChildren::new(parent.syntax()) | 356 | AstChildren::new(parent.syntax()) |
393 | } | 357 | } |
394 | 358 | ||
395 | #[derive(Debug)] | 359 | #[derive(Debug)] |
396 | pub struct AstChildren<'a, N> { | 360 | pub struct AstChildren<'a, N> { |
397 | inner: SyntaxNodeChildren<RefRoot<'a>>, | 361 | inner: SyntaxNodeChildren<'a>, |
398 | ph: PhantomData<N>, | 362 | ph: PhantomData<N>, |
399 | } | 363 | } |
400 | 364 | ||
401 | impl<'a, N> AstChildren<'a, N> { | 365 | impl<'a, N> AstChildren<'a, N> { |
402 | fn new(parent: SyntaxNodeRef<'a>) -> Self { | 366 | fn new(parent: &'a SyntaxNode) -> Self { |
403 | AstChildren { | 367 | AstChildren { |
404 | inner: parent.children(), | 368 | inner: parent.children(), |
405 | ph: PhantomData, | 369 | ph: PhantomData, |
@@ -407,9 +371,9 @@ impl<'a, N> AstChildren<'a, N> { | |||
407 | } | 371 | } |
408 | } | 372 | } |
409 | 373 | ||
410 | impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | 374 | impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> { |
411 | type Item = N; | 375 | type Item = &'a N; |
412 | fn next(&mut self) -> Option<N> { | 376 | fn next(&mut self) -> Option<&'a N> { |
413 | loop { | 377 | loop { |
414 | if let Some(n) = N::cast(self.inner.next()?) { | 378 | if let Some(n) = N::cast(self.inner.next()?) { |
415 | return Some(n); | 379 | return Some(n); |
@@ -420,13 +384,13 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | |||
420 | 384 | ||
421 | #[derive(Debug, Clone, PartialEq, Eq)] | 385 | #[derive(Debug, Clone, PartialEq, Eq)] |
422 | pub enum StructFlavor<'a> { | 386 | pub enum StructFlavor<'a> { |
423 | Tuple(PosFieldList<'a>), | 387 | Tuple(&'a PosFieldList), |
424 | Named(NamedFieldDefList<'a>), | 388 | Named(&'a NamedFieldDefList), |
425 | Unit, | 389 | Unit, |
426 | } | 390 | } |
427 | 391 | ||
428 | impl<'a> StructFlavor<'a> { | 392 | impl StructFlavor<'_> { |
429 | fn from_node<N: AstNode<'a>>(node: N) -> StructFlavor<'a> { | 393 | fn from_node<N: AstNode>(node: &N) -> StructFlavor { |
430 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { | 394 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { |
431 | StructFlavor::Named(nfdl) | 395 | StructFlavor::Named(nfdl) |
432 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { | 396 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { |
@@ -437,31 +401,31 @@ impl<'a> StructFlavor<'a> { | |||
437 | } | 401 | } |
438 | } | 402 | } |
439 | 403 | ||
440 | impl<'a> StructDef<'a> { | 404 | impl StructDef { |
441 | pub fn flavor(self) -> StructFlavor<'a> { | 405 | pub fn flavor(&self) -> StructFlavor { |
442 | StructFlavor::from_node(self) | 406 | StructFlavor::from_node(self) |
443 | } | 407 | } |
444 | } | 408 | } |
445 | 409 | ||
446 | impl<'a> EnumVariant<'a> { | 410 | impl EnumVariant { |
447 | pub fn flavor(self) -> StructFlavor<'a> { | 411 | pub fn flavor(&self) -> StructFlavor { |
448 | StructFlavor::from_node(self) | 412 | StructFlavor::from_node(self) |
449 | } | 413 | } |
450 | } | 414 | } |
451 | 415 | ||
452 | impl<'a> PointerType<'a> { | 416 | impl PointerType { |
453 | pub fn is_mut(&self) -> bool { | 417 | pub fn is_mut(&self) -> bool { |
454 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 418 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
455 | } | 419 | } |
456 | } | 420 | } |
457 | 421 | ||
458 | impl<'a> ReferenceType<'a> { | 422 | impl ReferenceType { |
459 | pub fn is_mut(&self) -> bool { | 423 | pub fn is_mut(&self) -> bool { |
460 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 424 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
461 | } | 425 | } |
462 | } | 426 | } |
463 | 427 | ||
464 | impl<'a> RefExpr<'a> { | 428 | impl RefExpr { |
465 | pub fn is_mut(&self) -> bool { | 429 | pub fn is_mut(&self) -> bool { |
466 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 430 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
467 | } | 431 | } |
@@ -477,7 +441,7 @@ pub enum PrefixOp { | |||
477 | Neg, | 441 | Neg, |
478 | } | 442 | } |
479 | 443 | ||
480 | impl<'a> PrefixExpr<'a> { | 444 | impl PrefixExpr { |
481 | pub fn op(&self) -> Option<PrefixOp> { | 445 | pub fn op(&self) -> Option<PrefixOp> { |
482 | match self.syntax().first_child()?.kind() { | 446 | match self.syntax().first_child()?.kind() { |
483 | STAR => Some(PrefixOp::Deref), | 447 | STAR => Some(PrefixOp::Deref), |
@@ -504,10 +468,55 @@ pub enum BinOp { | |||
504 | LesserTest, | 468 | LesserTest, |
505 | /// The `>` operator for comparison | 469 | /// The `>` operator for comparison |
506 | GreaterTest, | 470 | GreaterTest, |
507 | // TODO: lots of others | 471 | /// The `+` operator for addition |
508 | } | 472 | Addition, |
509 | 473 | /// The `*` operator for multiplication | |
510 | impl<'a> BinExpr<'a> { | 474 | Multiplication, |
475 | /// The `-` operator for subtraction | ||
476 | Subtraction, | ||
477 | /// The `/` operator for division | ||
478 | Division, | ||
479 | /// The `%` operator for remainder after division | ||
480 | Remainder, | ||
481 | /// The `<<` operator for left shift | ||
482 | LeftShift, | ||
483 | /// The `>>` operator for right shift | ||
484 | RightShift, | ||
485 | /// The `^` operator for bitwise XOR | ||
486 | BitwiseXor, | ||
487 | /// The `|` operator for bitwise OR | ||
488 | BitwiseOr, | ||
489 | /// The `&` operator for bitwise AND | ||
490 | BitwiseAnd, | ||
491 | /// The `..` operator for right-open ranges | ||
492 | RangeRightOpen, | ||
493 | /// The `..=` operator for right-closed ranges | ||
494 | RangeRightClosed, | ||
495 | /// The `=` operator for assignment | ||
496 | Assignment, | ||
497 | /// The `+=` operator for assignment after additon | ||
498 | AddAssign, | ||
499 | /// The `/=` operator for assignment after division | ||
500 | DivAssign, | ||
501 | /// The `*=` operator for assignment after multiplication | ||
502 | MulAssign, | ||
503 | /// The `%=` operator for assignment after remainders | ||
504 | RemAssign, | ||
505 | /// The `>>=` operator for assignment after shifting right | ||
506 | ShrAssign, | ||
507 | /// The `<<=` operator for assignment after shifting left | ||
508 | ShlAssign, | ||
509 | /// The `-=` operator for assignment after subtraction | ||
510 | SubAssign, | ||
511 | /// The `|=` operator for assignment after bitwise OR | ||
512 | BitOrAssign, | ||
513 | /// The `&=` operator for assignment after bitwise AND | ||
514 | BitAndAssign, | ||
515 | /// The `^=` operator for assignment after bitwise XOR | ||
516 | BitXorAssign, | ||
517 | } | ||
518 | |||
519 | impl BinExpr { | ||
511 | pub fn op(&self) -> Option<BinOp> { | 520 | pub fn op(&self) -> Option<BinOp> { |
512 | self.syntax() | 521 | self.syntax() |
513 | .children() | 522 | .children() |
@@ -519,20 +528,43 @@ impl<'a> BinExpr<'a> { | |||
519 | GTEQ => Some(BinOp::GreaterEqualTest), | 528 | GTEQ => Some(BinOp::GreaterEqualTest), |
520 | L_ANGLE => Some(BinOp::LesserTest), | 529 | L_ANGLE => Some(BinOp::LesserTest), |
521 | R_ANGLE => Some(BinOp::GreaterTest), | 530 | R_ANGLE => Some(BinOp::GreaterTest), |
531 | PLUS => Some(BinOp::Addition), | ||
532 | STAR => Some(BinOp::Multiplication), | ||
533 | MINUS => Some(BinOp::Subtraction), | ||
534 | SLASH => Some(BinOp::Division), | ||
535 | PERCENT => Some(BinOp::Remainder), | ||
536 | SHL => Some(BinOp::LeftShift), | ||
537 | SHR => Some(BinOp::RightShift), | ||
538 | CARET => Some(BinOp::BitwiseXor), | ||
539 | PIPE => Some(BinOp::BitwiseOr), | ||
540 | AMP => Some(BinOp::BitwiseAnd), | ||
541 | DOTDOT => Some(BinOp::RangeRightOpen), | ||
542 | DOTDOTEQ => Some(BinOp::RangeRightClosed), | ||
543 | EQ => Some(BinOp::Assignment), | ||
544 | PLUSEQ => Some(BinOp::AddAssign), | ||
545 | SLASHEQ => Some(BinOp::DivAssign), | ||
546 | STAREQ => Some(BinOp::MulAssign), | ||
547 | PERCENTEQ => Some(BinOp::RemAssign), | ||
548 | SHREQ => Some(BinOp::ShrAssign), | ||
549 | SHLEQ => Some(BinOp::ShlAssign), | ||
550 | MINUSEQ => Some(BinOp::SubAssign), | ||
551 | PIPEEQ => Some(BinOp::BitOrAssign), | ||
552 | AMPEQ => Some(BinOp::BitAndAssign), | ||
553 | CARETEQ => Some(BinOp::BitXorAssign), | ||
522 | _ => None, | 554 | _ => None, |
523 | }) | 555 | }) |
524 | .next() | 556 | .next() |
525 | } | 557 | } |
526 | 558 | ||
527 | pub fn lhs(self) -> Option<Expr<'a>> { | 559 | pub fn lhs(&self) -> Option<&Expr> { |
528 | children(self).nth(0) | 560 | children(self).nth(0) |
529 | } | 561 | } |
530 | 562 | ||
531 | pub fn rhs(self) -> Option<Expr<'a>> { | 563 | pub fn rhs(&self) -> Option<&Expr> { |
532 | children(self).nth(1) | 564 | children(self).nth(1) |
533 | } | 565 | } |
534 | 566 | ||
535 | pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) { | 567 | pub fn sub_exprs(&self) -> (Option<&Expr>, Option<&Expr>) { |
536 | let mut children = children(self); | 568 | let mut children = children(self); |
537 | let first = children.next(); | 569 | let first = children.next(); |
538 | let second = children.next(); | 570 | let second = children.next(); |
@@ -550,7 +582,7 @@ pub enum SelfParamFlavor { | |||
550 | MutRef, | 582 | MutRef, |
551 | } | 583 | } |
552 | 584 | ||
553 | impl<'a> SelfParam<'a> { | 585 | impl SelfParam { |
554 | pub fn flavor(&self) -> SelfParamFlavor { | 586 | pub fn flavor(&self) -> SelfParamFlavor { |
555 | let borrowed = self.syntax().children().any(|n| n.kind() == AMP); | 587 | let borrowed = self.syntax().children().any(|n| n.kind() == AMP); |
556 | if borrowed { | 588 | if borrowed { |
@@ -573,7 +605,7 @@ impl<'a> SelfParam<'a> { | |||
573 | 605 | ||
574 | #[test] | 606 | #[test] |
575 | fn test_doc_comment_of_items() { | 607 | fn test_doc_comment_of_items() { |
576 | let file = SourceFileNode::parse( | 608 | let file = SourceFile::parse( |
577 | r#" | 609 | r#" |
578 | //! doc | 610 | //! doc |
579 | // non-doc | 611 | // non-doc |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 24f72393a..547e3c003 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -9,4648 +9,3394 @@ | |||
9 | 9 | ||
10 | #![cfg_attr(rustfmt, rustfmt_skip)] | 10 | #![cfg_attr(rustfmt, rustfmt_skip)] |
11 | 11 | ||
12 | use std::hash::{Hash, Hasher}; | 12 | use rowan::TransparentNewType; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | ast, | 15 | SyntaxNode, SyntaxKind::*, |
16 | SyntaxNode, SyntaxNodeRef, AstNode, | 16 | yellow::{RaTypes, TreePtr}, |
17 | yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot}, | 17 | ast::{self, AstNode}, |
18 | SyntaxKind::*, | ||
19 | }; | 18 | }; |
20 | 19 | ||
21 | // ArgList | 20 | // ArgList |
22 | #[derive(Debug, Clone, Copy,)] | 21 | #[derive(Debug, PartialEq, Eq, Hash)] |
23 | pub struct ArgListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 22 | #[repr(transparent)] |
24 | pub(crate) syntax: SyntaxNode<R>, | 23 | pub struct ArgList { |
24 | pub(crate) syntax: SyntaxNode, | ||
25 | } | 25 | } |
26 | pub type ArgList<'a> = ArgListNode<RefRoot<'a>>; | 26 | unsafe impl TransparentNewType for ArgList { |
27 | 27 | type Repr = rowan::SyntaxNode<RaTypes>; | |
28 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArgListNode<R1>> for ArgListNode<R2> { | ||
29 | fn eq(&self, other: &ArgListNode<R1>) -> bool { self.syntax == other.syntax } | ||
30 | } | ||
31 | impl<R: TreeRoot<RaTypes>> Eq for ArgListNode<R> {} | ||
32 | impl<R: TreeRoot<RaTypes>> Hash for ArgListNode<R> { | ||
33 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
34 | } | 28 | } |
35 | 29 | ||
36 | impl<'a> AstNode<'a> for ArgList<'a> { | 30 | impl AstNode for ArgList { |
37 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 31 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
38 | match syntax.kind() { | 32 | match syntax.kind() { |
39 | ARG_LIST => Some(ArgList { syntax }), | 33 | ARG_LIST => Some(ArgList::from_repr(syntax.into_repr())), |
40 | _ => None, | 34 | _ => None, |
41 | } | 35 | } |
42 | } | 36 | } |
43 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 37 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
44 | } | 38 | fn to_owned(&self) -> TreePtr<ArgList> { TreePtr::cast(self.syntax.to_owned()) } |
45 | |||
46 | impl<R: TreeRoot<RaTypes>> ArgListNode<R> { | ||
47 | pub fn borrowed(&self) -> ArgList { | ||
48 | ArgListNode { syntax: self.syntax.borrowed() } | ||
49 | } | ||
50 | pub fn owned(&self) -> ArgListNode { | ||
51 | ArgListNode { syntax: self.syntax.owned() } | ||
52 | } | ||
53 | } | 39 | } |
54 | 40 | ||
55 | 41 | ||
56 | impl<'a> ArgList<'a> { | 42 | impl ArgList { |
57 | pub fn args(self) -> impl Iterator<Item = Expr<'a>> + 'a { | 43 | pub fn args(&self) -> impl Iterator<Item = &Expr> { |
58 | super::children(self) | 44 | super::children(self) |
59 | } | 45 | } |
60 | } | 46 | } |
61 | 47 | ||
62 | // ArrayExpr | 48 | // ArrayExpr |
63 | #[derive(Debug, Clone, Copy,)] | 49 | #[derive(Debug, PartialEq, Eq, Hash)] |
64 | pub struct ArrayExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 50 | #[repr(transparent)] |
65 | pub(crate) syntax: SyntaxNode<R>, | 51 | pub struct ArrayExpr { |
52 | pub(crate) syntax: SyntaxNode, | ||
66 | } | 53 | } |
67 | pub type ArrayExpr<'a> = ArrayExprNode<RefRoot<'a>>; | 54 | unsafe impl TransparentNewType for ArrayExpr { |
68 | 55 | type Repr = rowan::SyntaxNode<RaTypes>; | |
69 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayExprNode<R1>> for ArrayExprNode<R2> { | ||
70 | fn eq(&self, other: &ArrayExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
71 | } | ||
72 | impl<R: TreeRoot<RaTypes>> Eq for ArrayExprNode<R> {} | ||
73 | impl<R: TreeRoot<RaTypes>> Hash for ArrayExprNode<R> { | ||
74 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
75 | } | 56 | } |
76 | 57 | ||
77 | impl<'a> AstNode<'a> for ArrayExpr<'a> { | 58 | impl AstNode for ArrayExpr { |
78 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 59 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
79 | match syntax.kind() { | 60 | match syntax.kind() { |
80 | ARRAY_EXPR => Some(ArrayExpr { syntax }), | 61 | ARRAY_EXPR => Some(ArrayExpr::from_repr(syntax.into_repr())), |
81 | _ => None, | 62 | _ => None, |
82 | } | 63 | } |
83 | } | 64 | } |
84 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 65 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
85 | } | 66 | fn to_owned(&self) -> TreePtr<ArrayExpr> { TreePtr::cast(self.syntax.to_owned()) } |
86 | |||
87 | impl<R: TreeRoot<RaTypes>> ArrayExprNode<R> { | ||
88 | pub fn borrowed(&self) -> ArrayExpr { | ||
89 | ArrayExprNode { syntax: self.syntax.borrowed() } | ||
90 | } | ||
91 | pub fn owned(&self) -> ArrayExprNode { | ||
92 | ArrayExprNode { syntax: self.syntax.owned() } | ||
93 | } | ||
94 | } | 67 | } |
95 | 68 | ||
96 | 69 | ||
97 | impl<'a> ArrayExpr<'a> {} | 70 | impl ArrayExpr {} |
98 | 71 | ||
99 | // ArrayType | 72 | // ArrayType |
100 | #[derive(Debug, Clone, Copy,)] | 73 | #[derive(Debug, PartialEq, Eq, Hash)] |
101 | pub struct ArrayTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 74 | #[repr(transparent)] |
102 | pub(crate) syntax: SyntaxNode<R>, | 75 | pub struct ArrayType { |
103 | } | 76 | pub(crate) syntax: SyntaxNode, |
104 | pub type ArrayType<'a> = ArrayTypeNode<RefRoot<'a>>; | ||
105 | |||
106 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayTypeNode<R1>> for ArrayTypeNode<R2> { | ||
107 | fn eq(&self, other: &ArrayTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
108 | } | 77 | } |
109 | impl<R: TreeRoot<RaTypes>> Eq for ArrayTypeNode<R> {} | 78 | unsafe impl TransparentNewType for ArrayType { |
110 | impl<R: TreeRoot<RaTypes>> Hash for ArrayTypeNode<R> { | 79 | type Repr = rowan::SyntaxNode<RaTypes>; |
111 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
112 | } | 80 | } |
113 | 81 | ||
114 | impl<'a> AstNode<'a> for ArrayType<'a> { | 82 | impl AstNode for ArrayType { |
115 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 83 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
116 | match syntax.kind() { | 84 | match syntax.kind() { |
117 | ARRAY_TYPE => Some(ArrayType { syntax }), | 85 | ARRAY_TYPE => Some(ArrayType::from_repr(syntax.into_repr())), |
118 | _ => None, | 86 | _ => None, |
119 | } | 87 | } |
120 | } | 88 | } |
121 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 89 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
90 | fn to_owned(&self) -> TreePtr<ArrayType> { TreePtr::cast(self.syntax.to_owned()) } | ||
122 | } | 91 | } |
123 | 92 | ||
124 | impl<R: TreeRoot<RaTypes>> ArrayTypeNode<R> { | ||
125 | pub fn borrowed(&self) -> ArrayType { | ||
126 | ArrayTypeNode { syntax: self.syntax.borrowed() } | ||
127 | } | ||
128 | pub fn owned(&self) -> ArrayTypeNode { | ||
129 | ArrayTypeNode { syntax: self.syntax.owned() } | ||
130 | } | ||
131 | } | ||
132 | 93 | ||
133 | 94 | impl ArrayType { | |
134 | impl<'a> ArrayType<'a> { | 95 | pub fn type_ref(&self) -> Option<&TypeRef> { |
135 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
136 | super::child_opt(self) | 96 | super::child_opt(self) |
137 | } | 97 | } |
138 | 98 | ||
139 | pub fn expr(self) -> Option<Expr<'a>> { | 99 | pub fn expr(&self) -> Option<&Expr> { |
140 | super::child_opt(self) | 100 | super::child_opt(self) |
141 | } | 101 | } |
142 | } | 102 | } |
143 | 103 | ||
144 | // Attr | 104 | // Attr |
145 | #[derive(Debug, Clone, Copy,)] | 105 | #[derive(Debug, PartialEq, Eq, Hash)] |
146 | pub struct AttrNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 106 | #[repr(transparent)] |
147 | pub(crate) syntax: SyntaxNode<R>, | 107 | pub struct Attr { |
148 | } | 108 | pub(crate) syntax: SyntaxNode, |
149 | pub type Attr<'a> = AttrNode<RefRoot<'a>>; | ||
150 | |||
151 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<AttrNode<R1>> for AttrNode<R2> { | ||
152 | fn eq(&self, other: &AttrNode<R1>) -> bool { self.syntax == other.syntax } | ||
153 | } | 109 | } |
154 | impl<R: TreeRoot<RaTypes>> Eq for AttrNode<R> {} | 110 | unsafe impl TransparentNewType for Attr { |
155 | impl<R: TreeRoot<RaTypes>> Hash for AttrNode<R> { | 111 | type Repr = rowan::SyntaxNode<RaTypes>; |
156 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
157 | } | 112 | } |
158 | 113 | ||
159 | impl<'a> AstNode<'a> for Attr<'a> { | 114 | impl AstNode for Attr { |
160 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 115 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
161 | match syntax.kind() { | 116 | match syntax.kind() { |
162 | ATTR => Some(Attr { syntax }), | 117 | ATTR => Some(Attr::from_repr(syntax.into_repr())), |
163 | _ => None, | 118 | _ => None, |
164 | } | 119 | } |
165 | } | 120 | } |
166 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 121 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
167 | } | 122 | fn to_owned(&self) -> TreePtr<Attr> { TreePtr::cast(self.syntax.to_owned()) } |
168 | |||
169 | impl<R: TreeRoot<RaTypes>> AttrNode<R> { | ||
170 | pub fn borrowed(&self) -> Attr { | ||
171 | AttrNode { syntax: self.syntax.borrowed() } | ||
172 | } | ||
173 | pub fn owned(&self) -> AttrNode { | ||
174 | AttrNode { syntax: self.syntax.owned() } | ||
175 | } | ||
176 | } | 123 | } |
177 | 124 | ||
178 | 125 | ||
179 | impl<'a> Attr<'a> { | 126 | impl Attr { |
180 | pub fn value(self) -> Option<TokenTree<'a>> { | 127 | pub fn value(&self) -> Option<&TokenTree> { |
181 | super::child_opt(self) | 128 | super::child_opt(self) |
182 | } | 129 | } |
183 | } | 130 | } |
184 | 131 | ||
185 | // BinExpr | 132 | // BinExpr |
186 | #[derive(Debug, Clone, Copy,)] | 133 | #[derive(Debug, PartialEq, Eq, Hash)] |
187 | pub struct BinExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 134 | #[repr(transparent)] |
188 | pub(crate) syntax: SyntaxNode<R>, | 135 | pub struct BinExpr { |
189 | } | 136 | pub(crate) syntax: SyntaxNode, |
190 | pub type BinExpr<'a> = BinExprNode<RefRoot<'a>>; | ||
191 | |||
192 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BinExprNode<R1>> for BinExprNode<R2> { | ||
193 | fn eq(&self, other: &BinExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
194 | } | 137 | } |
195 | impl<R: TreeRoot<RaTypes>> Eq for BinExprNode<R> {} | 138 | unsafe impl TransparentNewType for BinExpr { |
196 | impl<R: TreeRoot<RaTypes>> Hash for BinExprNode<R> { | 139 | type Repr = rowan::SyntaxNode<RaTypes>; |
197 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
198 | } | 140 | } |
199 | 141 | ||
200 | impl<'a> AstNode<'a> for BinExpr<'a> { | 142 | impl AstNode for BinExpr { |
201 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 143 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
202 | match syntax.kind() { | 144 | match syntax.kind() { |
203 | BIN_EXPR => Some(BinExpr { syntax }), | 145 | BIN_EXPR => Some(BinExpr::from_repr(syntax.into_repr())), |
204 | _ => None, | 146 | _ => None, |
205 | } | 147 | } |
206 | } | 148 | } |
207 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 149 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
208 | } | 150 | fn to_owned(&self) -> TreePtr<BinExpr> { TreePtr::cast(self.syntax.to_owned()) } |
209 | |||
210 | impl<R: TreeRoot<RaTypes>> BinExprNode<R> { | ||
211 | pub fn borrowed(&self) -> BinExpr { | ||
212 | BinExprNode { syntax: self.syntax.borrowed() } | ||
213 | } | ||
214 | pub fn owned(&self) -> BinExprNode { | ||
215 | BinExprNode { syntax: self.syntax.owned() } | ||
216 | } | ||
217 | } | 151 | } |
218 | 152 | ||
219 | 153 | ||
220 | impl<'a> BinExpr<'a> {} | 154 | impl BinExpr {} |
221 | 155 | ||
222 | // BindPat | 156 | // BindPat |
223 | #[derive(Debug, Clone, Copy,)] | 157 | #[derive(Debug, PartialEq, Eq, Hash)] |
224 | pub struct BindPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 158 | #[repr(transparent)] |
225 | pub(crate) syntax: SyntaxNode<R>, | 159 | pub struct BindPat { |
160 | pub(crate) syntax: SyntaxNode, | ||
226 | } | 161 | } |
227 | pub type BindPat<'a> = BindPatNode<RefRoot<'a>>; | 162 | unsafe impl TransparentNewType for BindPat { |
228 | 163 | type Repr = rowan::SyntaxNode<RaTypes>; | |
229 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BindPatNode<R1>> for BindPatNode<R2> { | ||
230 | fn eq(&self, other: &BindPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
231 | } | ||
232 | impl<R: TreeRoot<RaTypes>> Eq for BindPatNode<R> {} | ||
233 | impl<R: TreeRoot<RaTypes>> Hash for BindPatNode<R> { | ||
234 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
235 | } | 164 | } |
236 | 165 | ||
237 | impl<'a> AstNode<'a> for BindPat<'a> { | 166 | impl AstNode for BindPat { |
238 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 167 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
239 | match syntax.kind() { | 168 | match syntax.kind() { |
240 | BIND_PAT => Some(BindPat { syntax }), | 169 | BIND_PAT => Some(BindPat::from_repr(syntax.into_repr())), |
241 | _ => None, | 170 | _ => None, |
242 | } | 171 | } |
243 | } | 172 | } |
244 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 173 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
245 | } | 174 | fn to_owned(&self) -> TreePtr<BindPat> { TreePtr::cast(self.syntax.to_owned()) } |
246 | |||
247 | impl<R: TreeRoot<RaTypes>> BindPatNode<R> { | ||
248 | pub fn borrowed(&self) -> BindPat { | ||
249 | BindPatNode { syntax: self.syntax.borrowed() } | ||
250 | } | ||
251 | pub fn owned(&self) -> BindPatNode { | ||
252 | BindPatNode { syntax: self.syntax.owned() } | ||
253 | } | ||
254 | } | 175 | } |
255 | 176 | ||
256 | 177 | ||
257 | impl<'a> ast::NameOwner<'a> for BindPat<'a> {} | 178 | impl ast::NameOwner for BindPat {} |
258 | impl<'a> BindPat<'a> {} | 179 | impl BindPat {} |
259 | 180 | ||
260 | // Block | 181 | // Block |
261 | #[derive(Debug, Clone, Copy,)] | 182 | #[derive(Debug, PartialEq, Eq, Hash)] |
262 | pub struct BlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 183 | #[repr(transparent)] |
263 | pub(crate) syntax: SyntaxNode<R>, | 184 | pub struct Block { |
264 | } | 185 | pub(crate) syntax: SyntaxNode, |
265 | pub type Block<'a> = BlockNode<RefRoot<'a>>; | ||
266 | |||
267 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockNode<R1>> for BlockNode<R2> { | ||
268 | fn eq(&self, other: &BlockNode<R1>) -> bool { self.syntax == other.syntax } | ||
269 | } | 186 | } |
270 | impl<R: TreeRoot<RaTypes>> Eq for BlockNode<R> {} | 187 | unsafe impl TransparentNewType for Block { |
271 | impl<R: TreeRoot<RaTypes>> Hash for BlockNode<R> { | 188 | type Repr = rowan::SyntaxNode<RaTypes>; |
272 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
273 | } | 189 | } |
274 | 190 | ||
275 | impl<'a> AstNode<'a> for Block<'a> { | 191 | impl AstNode for Block { |
276 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 192 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
277 | match syntax.kind() { | 193 | match syntax.kind() { |
278 | BLOCK => Some(Block { syntax }), | 194 | BLOCK => Some(Block::from_repr(syntax.into_repr())), |
279 | _ => None, | 195 | _ => None, |
280 | } | 196 | } |
281 | } | 197 | } |
282 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 198 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
199 | fn to_owned(&self) -> TreePtr<Block> { TreePtr::cast(self.syntax.to_owned()) } | ||
283 | } | 200 | } |
284 | 201 | ||
285 | impl<R: TreeRoot<RaTypes>> BlockNode<R> { | ||
286 | pub fn borrowed(&self) -> Block { | ||
287 | BlockNode { syntax: self.syntax.borrowed() } | ||
288 | } | ||
289 | pub fn owned(&self) -> BlockNode { | ||
290 | BlockNode { syntax: self.syntax.owned() } | ||
291 | } | ||
292 | } | ||
293 | 202 | ||
294 | 203 | impl Block { | |
295 | impl<'a> Block<'a> { | 204 | pub fn statements(&self) -> impl Iterator<Item = &Stmt> { |
296 | pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a { | ||
297 | super::children(self) | 205 | super::children(self) |
298 | } | 206 | } |
299 | 207 | ||
300 | pub fn expr(self) -> Option<Expr<'a>> { | 208 | pub fn expr(&self) -> Option<&Expr> { |
301 | super::child_opt(self) | 209 | super::child_opt(self) |
302 | } | 210 | } |
303 | } | 211 | } |
304 | 212 | ||
305 | // BlockExpr | 213 | // BlockExpr |
306 | #[derive(Debug, Clone, Copy,)] | 214 | #[derive(Debug, PartialEq, Eq, Hash)] |
307 | pub struct BlockExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 215 | #[repr(transparent)] |
308 | pub(crate) syntax: SyntaxNode<R>, | 216 | pub struct BlockExpr { |
217 | pub(crate) syntax: SyntaxNode, | ||
309 | } | 218 | } |
310 | pub type BlockExpr<'a> = BlockExprNode<RefRoot<'a>>; | 219 | unsafe impl TransparentNewType for BlockExpr { |
311 | 220 | type Repr = rowan::SyntaxNode<RaTypes>; | |
312 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockExprNode<R1>> for BlockExprNode<R2> { | ||
313 | fn eq(&self, other: &BlockExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
314 | } | ||
315 | impl<R: TreeRoot<RaTypes>> Eq for BlockExprNode<R> {} | ||
316 | impl<R: TreeRoot<RaTypes>> Hash for BlockExprNode<R> { | ||
317 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
318 | } | 221 | } |
319 | 222 | ||
320 | impl<'a> AstNode<'a> for BlockExpr<'a> { | 223 | impl AstNode for BlockExpr { |
321 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 224 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
322 | match syntax.kind() { | 225 | match syntax.kind() { |
323 | BLOCK_EXPR => Some(BlockExpr { syntax }), | 226 | BLOCK_EXPR => Some(BlockExpr::from_repr(syntax.into_repr())), |
324 | _ => None, | 227 | _ => None, |
325 | } | 228 | } |
326 | } | 229 | } |
327 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 230 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
328 | } | 231 | fn to_owned(&self) -> TreePtr<BlockExpr> { TreePtr::cast(self.syntax.to_owned()) } |
329 | |||
330 | impl<R: TreeRoot<RaTypes>> BlockExprNode<R> { | ||
331 | pub fn borrowed(&self) -> BlockExpr { | ||
332 | BlockExprNode { syntax: self.syntax.borrowed() } | ||
333 | } | ||
334 | pub fn owned(&self) -> BlockExprNode { | ||
335 | BlockExprNode { syntax: self.syntax.owned() } | ||
336 | } | ||
337 | } | 232 | } |
338 | 233 | ||
339 | 234 | ||
340 | impl<'a> BlockExpr<'a> { | 235 | impl BlockExpr { |
341 | pub fn block(self) -> Option<Block<'a>> { | 236 | pub fn block(&self) -> Option<&Block> { |
342 | super::child_opt(self) | 237 | super::child_opt(self) |
343 | } | 238 | } |
344 | } | 239 | } |
345 | 240 | ||
346 | // BreakExpr | 241 | // BreakExpr |
347 | #[derive(Debug, Clone, Copy,)] | 242 | #[derive(Debug, PartialEq, Eq, Hash)] |
348 | pub struct BreakExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 243 | #[repr(transparent)] |
349 | pub(crate) syntax: SyntaxNode<R>, | 244 | pub struct BreakExpr { |
245 | pub(crate) syntax: SyntaxNode, | ||
350 | } | 246 | } |
351 | pub type BreakExpr<'a> = BreakExprNode<RefRoot<'a>>; | 247 | unsafe impl TransparentNewType for BreakExpr { |
352 | 248 | type Repr = rowan::SyntaxNode<RaTypes>; | |
353 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BreakExprNode<R1>> for BreakExprNode<R2> { | ||
354 | fn eq(&self, other: &BreakExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
355 | } | ||
356 | impl<R: TreeRoot<RaTypes>> Eq for BreakExprNode<R> {} | ||
357 | impl<R: TreeRoot<RaTypes>> Hash for BreakExprNode<R> { | ||
358 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
359 | } | 249 | } |
360 | 250 | ||
361 | impl<'a> AstNode<'a> for BreakExpr<'a> { | 251 | impl AstNode for BreakExpr { |
362 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 252 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
363 | match syntax.kind() { | 253 | match syntax.kind() { |
364 | BREAK_EXPR => Some(BreakExpr { syntax }), | 254 | BREAK_EXPR => Some(BreakExpr::from_repr(syntax.into_repr())), |
365 | _ => None, | 255 | _ => None, |
366 | } | 256 | } |
367 | } | 257 | } |
368 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 258 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
369 | } | 259 | fn to_owned(&self) -> TreePtr<BreakExpr> { TreePtr::cast(self.syntax.to_owned()) } |
370 | |||
371 | impl<R: TreeRoot<RaTypes>> BreakExprNode<R> { | ||
372 | pub fn borrowed(&self) -> BreakExpr { | ||
373 | BreakExprNode { syntax: self.syntax.borrowed() } | ||
374 | } | ||
375 | pub fn owned(&self) -> BreakExprNode { | ||
376 | BreakExprNode { syntax: self.syntax.owned() } | ||
377 | } | ||
378 | } | 260 | } |
379 | 261 | ||
380 | 262 | ||
381 | impl<'a> BreakExpr<'a> { | 263 | impl BreakExpr { |
382 | pub fn expr(self) -> Option<Expr<'a>> { | 264 | pub fn expr(&self) -> Option<&Expr> { |
383 | super::child_opt(self) | 265 | super::child_opt(self) |
384 | } | 266 | } |
385 | } | 267 | } |
386 | 268 | ||
387 | // Byte | 269 | // Byte |
388 | #[derive(Debug, Clone, Copy,)] | 270 | #[derive(Debug, PartialEq, Eq, Hash)] |
389 | pub struct ByteNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 271 | #[repr(transparent)] |
390 | pub(crate) syntax: SyntaxNode<R>, | 272 | pub struct Byte { |
273 | pub(crate) syntax: SyntaxNode, | ||
391 | } | 274 | } |
392 | pub type Byte<'a> = ByteNode<RefRoot<'a>>; | 275 | unsafe impl TransparentNewType for Byte { |
393 | 276 | type Repr = rowan::SyntaxNode<RaTypes>; | |
394 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteNode<R1>> for ByteNode<R2> { | ||
395 | fn eq(&self, other: &ByteNode<R1>) -> bool { self.syntax == other.syntax } | ||
396 | } | ||
397 | impl<R: TreeRoot<RaTypes>> Eq for ByteNode<R> {} | ||
398 | impl<R: TreeRoot<RaTypes>> Hash for ByteNode<R> { | ||
399 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
400 | } | 277 | } |
401 | 278 | ||
402 | impl<'a> AstNode<'a> for Byte<'a> { | 279 | impl AstNode for Byte { |
403 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 280 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
404 | match syntax.kind() { | 281 | match syntax.kind() { |
405 | BYTE => Some(Byte { syntax }), | 282 | BYTE => Some(Byte::from_repr(syntax.into_repr())), |
406 | _ => None, | 283 | _ => None, |
407 | } | 284 | } |
408 | } | 285 | } |
409 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 286 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
410 | } | 287 | fn to_owned(&self) -> TreePtr<Byte> { TreePtr::cast(self.syntax.to_owned()) } |
411 | |||
412 | impl<R: TreeRoot<RaTypes>> ByteNode<R> { | ||
413 | pub fn borrowed(&self) -> Byte { | ||
414 | ByteNode { syntax: self.syntax.borrowed() } | ||
415 | } | ||
416 | pub fn owned(&self) -> ByteNode { | ||
417 | ByteNode { syntax: self.syntax.owned() } | ||
418 | } | ||
419 | } | 288 | } |
420 | 289 | ||
421 | 290 | ||
422 | impl<'a> Byte<'a> {} | 291 | impl ast::AstToken for Byte {} |
292 | impl Byte {} | ||
423 | 293 | ||
424 | // ByteString | 294 | // ByteString |
425 | #[derive(Debug, Clone, Copy,)] | 295 | #[derive(Debug, PartialEq, Eq, Hash)] |
426 | pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 296 | #[repr(transparent)] |
427 | pub(crate) syntax: SyntaxNode<R>, | 297 | pub struct ByteString { |
428 | } | 298 | pub(crate) syntax: SyntaxNode, |
429 | pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>; | ||
430 | |||
431 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteStringNode<R1>> for ByteStringNode<R2> { | ||
432 | fn eq(&self, other: &ByteStringNode<R1>) -> bool { self.syntax == other.syntax } | ||
433 | } | 299 | } |
434 | impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {} | 300 | unsafe impl TransparentNewType for ByteString { |
435 | impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> { | 301 | type Repr = rowan::SyntaxNode<RaTypes>; |
436 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
437 | } | 302 | } |
438 | 303 | ||
439 | impl<'a> AstNode<'a> for ByteString<'a> { | 304 | impl AstNode for ByteString { |
440 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 305 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
441 | match syntax.kind() { | 306 | match syntax.kind() { |
442 | BYTE_STRING => Some(ByteString { syntax }), | 307 | BYTE_STRING => Some(ByteString::from_repr(syntax.into_repr())), |
443 | _ => None, | 308 | _ => None, |
444 | } | 309 | } |
445 | } | 310 | } |
446 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 311 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
447 | } | 312 | fn to_owned(&self) -> TreePtr<ByteString> { TreePtr::cast(self.syntax.to_owned()) } |
448 | |||
449 | impl<R: TreeRoot<RaTypes>> ByteStringNode<R> { | ||
450 | pub fn borrowed(&self) -> ByteString { | ||
451 | ByteStringNode { syntax: self.syntax.borrowed() } | ||
452 | } | ||
453 | pub fn owned(&self) -> ByteStringNode { | ||
454 | ByteStringNode { syntax: self.syntax.owned() } | ||
455 | } | ||
456 | } | 313 | } |
457 | 314 | ||
458 | 315 | ||
459 | impl<'a> ByteString<'a> {} | 316 | impl ast::AstToken for ByteString {} |
317 | impl ByteString {} | ||
460 | 318 | ||
461 | // CallExpr | 319 | // CallExpr |
462 | #[derive(Debug, Clone, Copy,)] | 320 | #[derive(Debug, PartialEq, Eq, Hash)] |
463 | pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 321 | #[repr(transparent)] |
464 | pub(crate) syntax: SyntaxNode<R>, | 322 | pub struct CallExpr { |
465 | } | 323 | pub(crate) syntax: SyntaxNode, |
466 | pub type CallExpr<'a> = CallExprNode<RefRoot<'a>>; | ||
467 | |||
468 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CallExprNode<R1>> for CallExprNode<R2> { | ||
469 | fn eq(&self, other: &CallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
470 | } | 324 | } |
471 | impl<R: TreeRoot<RaTypes>> Eq for CallExprNode<R> {} | 325 | unsafe impl TransparentNewType for CallExpr { |
472 | impl<R: TreeRoot<RaTypes>> Hash for CallExprNode<R> { | 326 | type Repr = rowan::SyntaxNode<RaTypes>; |
473 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
474 | } | 327 | } |
475 | 328 | ||
476 | impl<'a> AstNode<'a> for CallExpr<'a> { | 329 | impl AstNode for CallExpr { |
477 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 330 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
478 | match syntax.kind() { | 331 | match syntax.kind() { |
479 | CALL_EXPR => Some(CallExpr { syntax }), | 332 | CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())), |
480 | _ => None, | 333 | _ => None, |
481 | } | 334 | } |
482 | } | 335 | } |
483 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 336 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
484 | } | 337 | fn to_owned(&self) -> TreePtr<CallExpr> { TreePtr::cast(self.syntax.to_owned()) } |
485 | |||
486 | impl<R: TreeRoot<RaTypes>> CallExprNode<R> { | ||
487 | pub fn borrowed(&self) -> CallExpr { | ||
488 | CallExprNode { syntax: self.syntax.borrowed() } | ||
489 | } | ||
490 | pub fn owned(&self) -> CallExprNode { | ||
491 | CallExprNode { syntax: self.syntax.owned() } | ||
492 | } | ||
493 | } | 338 | } |
494 | 339 | ||
495 | 340 | ||
496 | impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} | 341 | impl ast::ArgListOwner for CallExpr {} |
497 | impl<'a> CallExpr<'a> { | 342 | impl CallExpr { |
498 | pub fn expr(self) -> Option<Expr<'a>> { | 343 | pub fn expr(&self) -> Option<&Expr> { |
499 | super::child_opt(self) | 344 | super::child_opt(self) |
500 | } | 345 | } |
501 | } | 346 | } |
502 | 347 | ||
503 | // CastExpr | 348 | // CastExpr |
504 | #[derive(Debug, Clone, Copy,)] | 349 | #[derive(Debug, PartialEq, Eq, Hash)] |
505 | pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 350 | #[repr(transparent)] |
506 | pub(crate) syntax: SyntaxNode<R>, | 351 | pub struct CastExpr { |
352 | pub(crate) syntax: SyntaxNode, | ||
507 | } | 353 | } |
508 | pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; | 354 | unsafe impl TransparentNewType for CastExpr { |
509 | 355 | type Repr = rowan::SyntaxNode<RaTypes>; | |
510 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CastExprNode<R1>> for CastExprNode<R2> { | ||
511 | fn eq(&self, other: &CastExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
512 | } | ||
513 | impl<R: TreeRoot<RaTypes>> Eq for CastExprNode<R> {} | ||
514 | impl<R: TreeRoot<RaTypes>> Hash for CastExprNode<R> { | ||
515 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
516 | } | 356 | } |
517 | 357 | ||
518 | impl<'a> AstNode<'a> for CastExpr<'a> { | 358 | impl AstNode for CastExpr { |
519 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 359 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
520 | match syntax.kind() { | 360 | match syntax.kind() { |
521 | CAST_EXPR => Some(CastExpr { syntax }), | 361 | CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())), |
522 | _ => None, | 362 | _ => None, |
523 | } | 363 | } |
524 | } | 364 | } |
525 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 365 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
526 | } | 366 | fn to_owned(&self) -> TreePtr<CastExpr> { TreePtr::cast(self.syntax.to_owned()) } |
527 | |||
528 | impl<R: TreeRoot<RaTypes>> CastExprNode<R> { | ||
529 | pub fn borrowed(&self) -> CastExpr { | ||
530 | CastExprNode { syntax: self.syntax.borrowed() } | ||
531 | } | ||
532 | pub fn owned(&self) -> CastExprNode { | ||
533 | CastExprNode { syntax: self.syntax.owned() } | ||
534 | } | ||
535 | } | 367 | } |
536 | 368 | ||
537 | 369 | ||
538 | impl<'a> CastExpr<'a> { | 370 | impl CastExpr { |
539 | pub fn expr(self) -> Option<Expr<'a>> { | 371 | pub fn expr(&self) -> Option<&Expr> { |
540 | super::child_opt(self) | 372 | super::child_opt(self) |
541 | } | 373 | } |
542 | 374 | ||
543 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 375 | pub fn type_ref(&self) -> Option<&TypeRef> { |
544 | super::child_opt(self) | 376 | super::child_opt(self) |
545 | } | 377 | } |
546 | } | 378 | } |
547 | 379 | ||
548 | // Char | 380 | // Char |
549 | #[derive(Debug, Clone, Copy,)] | 381 | #[derive(Debug, PartialEq, Eq, Hash)] |
550 | pub struct CharNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 382 | #[repr(transparent)] |
551 | pub(crate) syntax: SyntaxNode<R>, | 383 | pub struct Char { |
552 | } | 384 | pub(crate) syntax: SyntaxNode, |
553 | pub type Char<'a> = CharNode<RefRoot<'a>>; | ||
554 | |||
555 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CharNode<R1>> for CharNode<R2> { | ||
556 | fn eq(&self, other: &CharNode<R1>) -> bool { self.syntax == other.syntax } | ||
557 | } | 385 | } |
558 | impl<R: TreeRoot<RaTypes>> Eq for CharNode<R> {} | 386 | unsafe impl TransparentNewType for Char { |
559 | impl<R: TreeRoot<RaTypes>> Hash for CharNode<R> { | 387 | type Repr = rowan::SyntaxNode<RaTypes>; |
560 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
561 | } | 388 | } |
562 | 389 | ||
563 | impl<'a> AstNode<'a> for Char<'a> { | 390 | impl AstNode for Char { |
564 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 391 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
565 | match syntax.kind() { | 392 | match syntax.kind() { |
566 | CHAR => Some(Char { syntax }), | 393 | CHAR => Some(Char::from_repr(syntax.into_repr())), |
567 | _ => None, | 394 | _ => None, |
568 | } | 395 | } |
569 | } | 396 | } |
570 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 397 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
398 | fn to_owned(&self) -> TreePtr<Char> { TreePtr::cast(self.syntax.to_owned()) } | ||
571 | } | 399 | } |
572 | 400 | ||
573 | impl<R: TreeRoot<RaTypes>> CharNode<R> { | ||
574 | pub fn borrowed(&self) -> Char { | ||
575 | CharNode { syntax: self.syntax.borrowed() } | ||
576 | } | ||
577 | pub fn owned(&self) -> CharNode { | ||
578 | CharNode { syntax: self.syntax.owned() } | ||
579 | } | ||
580 | } | ||
581 | 401 | ||
582 | 402 | impl ast::AstToken for Char {} | |
583 | impl<'a> Char<'a> {} | 403 | impl Char {} |
584 | 404 | ||
585 | // Comment | 405 | // Comment |
586 | #[derive(Debug, Clone, Copy,)] | 406 | #[derive(Debug, PartialEq, Eq, Hash)] |
587 | pub struct CommentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 407 | #[repr(transparent)] |
588 | pub(crate) syntax: SyntaxNode<R>, | 408 | pub struct Comment { |
589 | } | 409 | pub(crate) syntax: SyntaxNode, |
590 | pub type Comment<'a> = CommentNode<RefRoot<'a>>; | ||
591 | |||
592 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CommentNode<R1>> for CommentNode<R2> { | ||
593 | fn eq(&self, other: &CommentNode<R1>) -> bool { self.syntax == other.syntax } | ||
594 | } | 410 | } |
595 | impl<R: TreeRoot<RaTypes>> Eq for CommentNode<R> {} | 411 | unsafe impl TransparentNewType for Comment { |
596 | impl<R: TreeRoot<RaTypes>> Hash for CommentNode<R> { | 412 | type Repr = rowan::SyntaxNode<RaTypes>; |
597 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
598 | } | 413 | } |
599 | 414 | ||
600 | impl<'a> AstNode<'a> for Comment<'a> { | 415 | impl AstNode for Comment { |
601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 416 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
602 | match syntax.kind() { | 417 | match syntax.kind() { |
603 | COMMENT => Some(Comment { syntax }), | 418 | COMMENT => Some(Comment::from_repr(syntax.into_repr())), |
604 | _ => None, | 419 | _ => None, |
605 | } | 420 | } |
606 | } | 421 | } |
607 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 422 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
608 | } | 423 | fn to_owned(&self) -> TreePtr<Comment> { TreePtr::cast(self.syntax.to_owned()) } |
609 | |||
610 | impl<R: TreeRoot<RaTypes>> CommentNode<R> { | ||
611 | pub fn borrowed(&self) -> Comment { | ||
612 | CommentNode { syntax: self.syntax.borrowed() } | ||
613 | } | ||
614 | pub fn owned(&self) -> CommentNode { | ||
615 | CommentNode { syntax: self.syntax.owned() } | ||
616 | } | ||
617 | } | 424 | } |
618 | 425 | ||
619 | 426 | ||
620 | impl<'a> Comment<'a> {} | 427 | impl ast::AstToken for Comment {} |
428 | impl Comment {} | ||
621 | 429 | ||
622 | // Condition | 430 | // Condition |
623 | #[derive(Debug, Clone, Copy,)] | 431 | #[derive(Debug, PartialEq, Eq, Hash)] |
624 | pub struct ConditionNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 432 | #[repr(transparent)] |
625 | pub(crate) syntax: SyntaxNode<R>, | 433 | pub struct Condition { |
434 | pub(crate) syntax: SyntaxNode, | ||
626 | } | 435 | } |
627 | pub type Condition<'a> = ConditionNode<RefRoot<'a>>; | 436 | unsafe impl TransparentNewType for Condition { |
628 | 437 | type Repr = rowan::SyntaxNode<RaTypes>; | |
629 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConditionNode<R1>> for ConditionNode<R2> { | ||
630 | fn eq(&self, other: &ConditionNode<R1>) -> bool { self.syntax == other.syntax } | ||
631 | } | ||
632 | impl<R: TreeRoot<RaTypes>> Eq for ConditionNode<R> {} | ||
633 | impl<R: TreeRoot<RaTypes>> Hash for ConditionNode<R> { | ||
634 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
635 | } | 438 | } |
636 | 439 | ||
637 | impl<'a> AstNode<'a> for Condition<'a> { | 440 | impl AstNode for Condition { |
638 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 441 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
639 | match syntax.kind() { | 442 | match syntax.kind() { |
640 | CONDITION => Some(Condition { syntax }), | 443 | CONDITION => Some(Condition::from_repr(syntax.into_repr())), |
641 | _ => None, | 444 | _ => None, |
642 | } | 445 | } |
643 | } | 446 | } |
644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 447 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
645 | } | 448 | fn to_owned(&self) -> TreePtr<Condition> { TreePtr::cast(self.syntax.to_owned()) } |
646 | |||
647 | impl<R: TreeRoot<RaTypes>> ConditionNode<R> { | ||
648 | pub fn borrowed(&self) -> Condition { | ||
649 | ConditionNode { syntax: self.syntax.borrowed() } | ||
650 | } | ||
651 | pub fn owned(&self) -> ConditionNode { | ||
652 | ConditionNode { syntax: self.syntax.owned() } | ||
653 | } | ||
654 | } | 449 | } |
655 | 450 | ||
656 | 451 | ||
657 | impl<'a> Condition<'a> { | 452 | impl Condition { |
658 | pub fn pat(self) -> Option<Pat<'a>> { | 453 | pub fn pat(&self) -> Option<&Pat> { |
659 | super::child_opt(self) | 454 | super::child_opt(self) |
660 | } | 455 | } |
661 | 456 | ||
662 | pub fn expr(self) -> Option<Expr<'a>> { | 457 | pub fn expr(&self) -> Option<&Expr> { |
663 | super::child_opt(self) | 458 | super::child_opt(self) |
664 | } | 459 | } |
665 | } | 460 | } |
666 | 461 | ||
667 | // ConstDef | 462 | // ConstDef |
668 | #[derive(Debug, Clone, Copy,)] | 463 | #[derive(Debug, PartialEq, Eq, Hash)] |
669 | pub struct ConstDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 464 | #[repr(transparent)] |
670 | pub(crate) syntax: SyntaxNode<R>, | 465 | pub struct ConstDef { |
466 | pub(crate) syntax: SyntaxNode, | ||
671 | } | 467 | } |
672 | pub type ConstDef<'a> = ConstDefNode<RefRoot<'a>>; | 468 | unsafe impl TransparentNewType for ConstDef { |
673 | 469 | type Repr = rowan::SyntaxNode<RaTypes>; | |
674 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConstDefNode<R1>> for ConstDefNode<R2> { | ||
675 | fn eq(&self, other: &ConstDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
676 | } | ||
677 | impl<R: TreeRoot<RaTypes>> Eq for ConstDefNode<R> {} | ||
678 | impl<R: TreeRoot<RaTypes>> Hash for ConstDefNode<R> { | ||
679 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
680 | } | 470 | } |
681 | 471 | ||
682 | impl<'a> AstNode<'a> for ConstDef<'a> { | 472 | impl AstNode for ConstDef { |
683 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 473 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
684 | match syntax.kind() { | 474 | match syntax.kind() { |
685 | CONST_DEF => Some(ConstDef { syntax }), | 475 | CONST_DEF => Some(ConstDef::from_repr(syntax.into_repr())), |
686 | _ => None, | 476 | _ => None, |
687 | } | 477 | } |
688 | } | 478 | } |
689 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 479 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
690 | } | 480 | fn to_owned(&self) -> TreePtr<ConstDef> { TreePtr::cast(self.syntax.to_owned()) } |
691 | |||
692 | impl<R: TreeRoot<RaTypes>> ConstDefNode<R> { | ||
693 | pub fn borrowed(&self) -> ConstDef { | ||
694 | ConstDefNode { syntax: self.syntax.borrowed() } | ||
695 | } | ||
696 | pub fn owned(&self) -> ConstDefNode { | ||
697 | ConstDefNode { syntax: self.syntax.owned() } | ||
698 | } | ||
699 | } | 481 | } |
700 | 482 | ||
701 | 483 | ||
702 | impl<'a> ast::VisibilityOwner<'a> for ConstDef<'a> {} | 484 | impl ast::VisibilityOwner for ConstDef {} |
703 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} | 485 | impl ast::NameOwner for ConstDef {} |
704 | impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} | 486 | impl ast::TypeParamsOwner for ConstDef {} |
705 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} | 487 | impl ast::AttrsOwner for ConstDef {} |
706 | impl<'a> ast::DocCommentsOwner<'a> for ConstDef<'a> {} | 488 | impl ast::DocCommentsOwner for ConstDef {} |
707 | impl<'a> ConstDef<'a> {} | 489 | impl ConstDef {} |
708 | 490 | ||
709 | // ContinueExpr | 491 | // ContinueExpr |
710 | #[derive(Debug, Clone, Copy,)] | 492 | #[derive(Debug, PartialEq, Eq, Hash)] |
711 | pub struct ContinueExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 493 | #[repr(transparent)] |
712 | pub(crate) syntax: SyntaxNode<R>, | 494 | pub struct ContinueExpr { |
495 | pub(crate) syntax: SyntaxNode, | ||
713 | } | 496 | } |
714 | pub type ContinueExpr<'a> = ContinueExprNode<RefRoot<'a>>; | 497 | unsafe impl TransparentNewType for ContinueExpr { |
715 | 498 | type Repr = rowan::SyntaxNode<RaTypes>; | |
716 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ContinueExprNode<R1>> for ContinueExprNode<R2> { | ||
717 | fn eq(&self, other: &ContinueExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
718 | } | ||
719 | impl<R: TreeRoot<RaTypes>> Eq for ContinueExprNode<R> {} | ||
720 | impl<R: TreeRoot<RaTypes>> Hash for ContinueExprNode<R> { | ||
721 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
722 | } | 499 | } |
723 | 500 | ||
724 | impl<'a> AstNode<'a> for ContinueExpr<'a> { | 501 | impl AstNode for ContinueExpr { |
725 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 502 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
726 | match syntax.kind() { | 503 | match syntax.kind() { |
727 | CONTINUE_EXPR => Some(ContinueExpr { syntax }), | 504 | CONTINUE_EXPR => Some(ContinueExpr::from_repr(syntax.into_repr())), |
728 | _ => None, | 505 | _ => None, |
729 | } | 506 | } |
730 | } | 507 | } |
731 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 508 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
509 | fn to_owned(&self) -> TreePtr<ContinueExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
732 | } | 510 | } |
733 | 511 | ||
734 | impl<R: TreeRoot<RaTypes>> ContinueExprNode<R> { | ||
735 | pub fn borrowed(&self) -> ContinueExpr { | ||
736 | ContinueExprNode { syntax: self.syntax.borrowed() } | ||
737 | } | ||
738 | pub fn owned(&self) -> ContinueExprNode { | ||
739 | ContinueExprNode { syntax: self.syntax.owned() } | ||
740 | } | ||
741 | } | ||
742 | 512 | ||
743 | 513 | impl ContinueExpr {} | |
744 | impl<'a> ContinueExpr<'a> {} | ||
745 | 514 | ||
746 | // DynTraitType | 515 | // DynTraitType |
747 | #[derive(Debug, Clone, Copy,)] | 516 | #[derive(Debug, PartialEq, Eq, Hash)] |
748 | pub struct DynTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 517 | #[repr(transparent)] |
749 | pub(crate) syntax: SyntaxNode<R>, | 518 | pub struct DynTraitType { |
750 | } | 519 | pub(crate) syntax: SyntaxNode, |
751 | pub type DynTraitType<'a> = DynTraitTypeNode<RefRoot<'a>>; | ||
752 | |||
753 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<DynTraitTypeNode<R1>> for DynTraitTypeNode<R2> { | ||
754 | fn eq(&self, other: &DynTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
755 | } | 520 | } |
756 | impl<R: TreeRoot<RaTypes>> Eq for DynTraitTypeNode<R> {} | 521 | unsafe impl TransparentNewType for DynTraitType { |
757 | impl<R: TreeRoot<RaTypes>> Hash for DynTraitTypeNode<R> { | 522 | type Repr = rowan::SyntaxNode<RaTypes>; |
758 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
759 | } | 523 | } |
760 | 524 | ||
761 | impl<'a> AstNode<'a> for DynTraitType<'a> { | 525 | impl AstNode for DynTraitType { |
762 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 526 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
763 | match syntax.kind() { | 527 | match syntax.kind() { |
764 | DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), | 528 | DYN_TRAIT_TYPE => Some(DynTraitType::from_repr(syntax.into_repr())), |
765 | _ => None, | 529 | _ => None, |
766 | } | 530 | } |
767 | } | 531 | } |
768 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 532 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
533 | fn to_owned(&self) -> TreePtr<DynTraitType> { TreePtr::cast(self.syntax.to_owned()) } | ||
769 | } | 534 | } |
770 | 535 | ||
771 | impl<R: TreeRoot<RaTypes>> DynTraitTypeNode<R> { | ||
772 | pub fn borrowed(&self) -> DynTraitType { | ||
773 | DynTraitTypeNode { syntax: self.syntax.borrowed() } | ||
774 | } | ||
775 | pub fn owned(&self) -> DynTraitTypeNode { | ||
776 | DynTraitTypeNode { syntax: self.syntax.owned() } | ||
777 | } | ||
778 | } | ||
779 | 536 | ||
780 | 537 | impl DynTraitType {} | |
781 | impl<'a> DynTraitType<'a> {} | ||
782 | 538 | ||
783 | // EnumDef | 539 | // EnumDef |
784 | #[derive(Debug, Clone, Copy,)] | 540 | #[derive(Debug, PartialEq, Eq, Hash)] |
785 | pub struct EnumDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 541 | #[repr(transparent)] |
786 | pub(crate) syntax: SyntaxNode<R>, | 542 | pub struct EnumDef { |
787 | } | 543 | pub(crate) syntax: SyntaxNode, |
788 | pub type EnumDef<'a> = EnumDefNode<RefRoot<'a>>; | ||
789 | |||
790 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumDefNode<R1>> for EnumDefNode<R2> { | ||
791 | fn eq(&self, other: &EnumDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
792 | } | 544 | } |
793 | impl<R: TreeRoot<RaTypes>> Eq for EnumDefNode<R> {} | 545 | unsafe impl TransparentNewType for EnumDef { |
794 | impl<R: TreeRoot<RaTypes>> Hash for EnumDefNode<R> { | 546 | type Repr = rowan::SyntaxNode<RaTypes>; |
795 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
796 | } | 547 | } |
797 | 548 | ||
798 | impl<'a> AstNode<'a> for EnumDef<'a> { | 549 | impl AstNode for EnumDef { |
799 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 550 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
800 | match syntax.kind() { | 551 | match syntax.kind() { |
801 | ENUM_DEF => Some(EnumDef { syntax }), | 552 | ENUM_DEF => Some(EnumDef::from_repr(syntax.into_repr())), |
802 | _ => None, | 553 | _ => None, |
803 | } | 554 | } |
804 | } | 555 | } |
805 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 556 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
806 | } | 557 | fn to_owned(&self) -> TreePtr<EnumDef> { TreePtr::cast(self.syntax.to_owned()) } |
807 | |||
808 | impl<R: TreeRoot<RaTypes>> EnumDefNode<R> { | ||
809 | pub fn borrowed(&self) -> EnumDef { | ||
810 | EnumDefNode { syntax: self.syntax.borrowed() } | ||
811 | } | ||
812 | pub fn owned(&self) -> EnumDefNode { | ||
813 | EnumDefNode { syntax: self.syntax.owned() } | ||
814 | } | ||
815 | } | 558 | } |
816 | 559 | ||
817 | 560 | ||
818 | impl<'a> ast::VisibilityOwner<'a> for EnumDef<'a> {} | 561 | impl ast::VisibilityOwner for EnumDef {} |
819 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} | 562 | impl ast::NameOwner for EnumDef {} |
820 | impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} | 563 | impl ast::TypeParamsOwner for EnumDef {} |
821 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} | 564 | impl ast::AttrsOwner for EnumDef {} |
822 | impl<'a> ast::DocCommentsOwner<'a> for EnumDef<'a> {} | 565 | impl ast::DocCommentsOwner for EnumDef {} |
823 | impl<'a> EnumDef<'a> { | 566 | impl EnumDef { |
824 | pub fn variant_list(self) -> Option<EnumVariantList<'a>> { | 567 | pub fn variant_list(&self) -> Option<&EnumVariantList> { |
825 | super::child_opt(self) | 568 | super::child_opt(self) |
826 | } | 569 | } |
827 | } | 570 | } |
828 | 571 | ||
829 | // EnumVariant | 572 | // EnumVariant |
830 | #[derive(Debug, Clone, Copy,)] | 573 | #[derive(Debug, PartialEq, Eq, Hash)] |
831 | pub struct EnumVariantNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 574 | #[repr(transparent)] |
832 | pub(crate) syntax: SyntaxNode<R>, | 575 | pub struct EnumVariant { |
576 | pub(crate) syntax: SyntaxNode, | ||
833 | } | 577 | } |
834 | pub type EnumVariant<'a> = EnumVariantNode<RefRoot<'a>>; | 578 | unsafe impl TransparentNewType for EnumVariant { |
835 | 579 | type Repr = rowan::SyntaxNode<RaTypes>; | |
836 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumVariantNode<R1>> for EnumVariantNode<R2> { | ||
837 | fn eq(&self, other: &EnumVariantNode<R1>) -> bool { self.syntax == other.syntax } | ||
838 | } | ||
839 | impl<R: TreeRoot<RaTypes>> Eq for EnumVariantNode<R> {} | ||
840 | impl<R: TreeRoot<RaTypes>> Hash for EnumVariantNode<R> { | ||
841 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
842 | } | 580 | } |
843 | 581 | ||
844 | impl<'a> AstNode<'a> for EnumVariant<'a> { | 582 | impl AstNode for EnumVariant { |
845 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 583 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
846 | match syntax.kind() { | 584 | match syntax.kind() { |
847 | ENUM_VARIANT => Some(EnumVariant { syntax }), | 585 | ENUM_VARIANT => Some(EnumVariant::from_repr(syntax.into_repr())), |
848 | _ => None, | 586 | _ => None, |
849 | } | 587 | } |
850 | } | 588 | } |
851 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 589 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
852 | } | 590 | fn to_owned(&self) -> TreePtr<EnumVariant> { TreePtr::cast(self.syntax.to_owned()) } |
853 | |||
854 | impl<R: TreeRoot<RaTypes>> EnumVariantNode<R> { | ||
855 | pub fn borrowed(&self) -> EnumVariant { | ||
856 | EnumVariantNode { syntax: self.syntax.borrowed() } | ||
857 | } | ||
858 | pub fn owned(&self) -> EnumVariantNode { | ||
859 | EnumVariantNode { syntax: self.syntax.owned() } | ||
860 | } | ||
861 | } | 591 | } |
862 | 592 | ||
863 | 593 | ||
864 | impl<'a> ast::NameOwner<'a> for EnumVariant<'a> {} | 594 | impl ast::NameOwner for EnumVariant {} |
865 | impl<'a> EnumVariant<'a> { | 595 | impl EnumVariant { |
866 | pub fn expr(self) -> Option<Expr<'a>> { | 596 | pub fn expr(&self) -> Option<&Expr> { |
867 | super::child_opt(self) | 597 | super::child_opt(self) |
868 | } | 598 | } |
869 | } | 599 | } |
870 | 600 | ||
871 | // EnumVariantList | 601 | // EnumVariantList |
872 | #[derive(Debug, Clone, Copy,)] | 602 | #[derive(Debug, PartialEq, Eq, Hash)] |
873 | pub struct EnumVariantListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 603 | #[repr(transparent)] |
874 | pub(crate) syntax: SyntaxNode<R>, | 604 | pub struct EnumVariantList { |
875 | } | 605 | pub(crate) syntax: SyntaxNode, |
876 | pub type EnumVariantList<'a> = EnumVariantListNode<RefRoot<'a>>; | ||
877 | |||
878 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumVariantListNode<R1>> for EnumVariantListNode<R2> { | ||
879 | fn eq(&self, other: &EnumVariantListNode<R1>) -> bool { self.syntax == other.syntax } | ||
880 | } | 606 | } |
881 | impl<R: TreeRoot<RaTypes>> Eq for EnumVariantListNode<R> {} | 607 | unsafe impl TransparentNewType for EnumVariantList { |
882 | impl<R: TreeRoot<RaTypes>> Hash for EnumVariantListNode<R> { | 608 | type Repr = rowan::SyntaxNode<RaTypes>; |
883 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
884 | } | 609 | } |
885 | 610 | ||
886 | impl<'a> AstNode<'a> for EnumVariantList<'a> { | 611 | impl AstNode for EnumVariantList { |
887 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 612 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
888 | match syntax.kind() { | 613 | match syntax.kind() { |
889 | ENUM_VARIANT_LIST => Some(EnumVariantList { syntax }), | 614 | ENUM_VARIANT_LIST => Some(EnumVariantList::from_repr(syntax.into_repr())), |
890 | _ => None, | 615 | _ => None, |
891 | } | 616 | } |
892 | } | 617 | } |
893 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 618 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
619 | fn to_owned(&self) -> TreePtr<EnumVariantList> { TreePtr::cast(self.syntax.to_owned()) } | ||
894 | } | 620 | } |
895 | 621 | ||
896 | impl<R: TreeRoot<RaTypes>> EnumVariantListNode<R> { | ||
897 | pub fn borrowed(&self) -> EnumVariantList { | ||
898 | EnumVariantListNode { syntax: self.syntax.borrowed() } | ||
899 | } | ||
900 | pub fn owned(&self) -> EnumVariantListNode { | ||
901 | EnumVariantListNode { syntax: self.syntax.owned() } | ||
902 | } | ||
903 | } | ||
904 | 622 | ||
905 | 623 | impl EnumVariantList { | |
906 | impl<'a> EnumVariantList<'a> { | 624 | pub fn variants(&self) -> impl Iterator<Item = &EnumVariant> { |
907 | pub fn variants(self) -> impl Iterator<Item = EnumVariant<'a>> + 'a { | ||
908 | super::children(self) | 625 | super::children(self) |
909 | } | 626 | } |
910 | } | 627 | } |
911 | 628 | ||
912 | // Expr | 629 | // Expr |
913 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 630 | #[derive(Debug, PartialEq, Eq, Hash)] |
914 | pub enum Expr<'a> { | 631 | #[repr(transparent)] |
915 | TupleExpr(TupleExpr<'a>), | 632 | pub struct Expr { |
916 | ArrayExpr(ArrayExpr<'a>), | 633 | pub(crate) syntax: SyntaxNode, |
917 | ParenExpr(ParenExpr<'a>), | 634 | } |
918 | PathExpr(PathExpr<'a>), | 635 | unsafe impl TransparentNewType for Expr { |
919 | LambdaExpr(LambdaExpr<'a>), | 636 | type Repr = rowan::SyntaxNode<RaTypes>; |
920 | IfExpr(IfExpr<'a>), | ||
921 | LoopExpr(LoopExpr<'a>), | ||
922 | ForExpr(ForExpr<'a>), | ||
923 | WhileExpr(WhileExpr<'a>), | ||
924 | ContinueExpr(ContinueExpr<'a>), | ||
925 | BreakExpr(BreakExpr<'a>), | ||
926 | Label(Label<'a>), | ||
927 | BlockExpr(BlockExpr<'a>), | ||
928 | ReturnExpr(ReturnExpr<'a>), | ||
929 | MatchExpr(MatchExpr<'a>), | ||
930 | StructLit(StructLit<'a>), | ||
931 | CallExpr(CallExpr<'a>), | ||
932 | IndexExpr(IndexExpr<'a>), | ||
933 | MethodCallExpr(MethodCallExpr<'a>), | ||
934 | FieldExpr(FieldExpr<'a>), | ||
935 | TryExpr(TryExpr<'a>), | ||
936 | CastExpr(CastExpr<'a>), | ||
937 | RefExpr(RefExpr<'a>), | ||
938 | PrefixExpr(PrefixExpr<'a>), | ||
939 | RangeExpr(RangeExpr<'a>), | ||
940 | BinExpr(BinExpr<'a>), | ||
941 | Literal(Literal<'a>), | ||
942 | } | ||
943 | |||
944 | impl<'a> AstNode<'a> for Expr<'a> { | ||
945 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
946 | match syntax.kind() { | ||
947 | TUPLE_EXPR => Some(Expr::TupleExpr(TupleExpr { syntax })), | ||
948 | ARRAY_EXPR => Some(Expr::ArrayExpr(ArrayExpr { syntax })), | ||
949 | PAREN_EXPR => Some(Expr::ParenExpr(ParenExpr { syntax })), | ||
950 | PATH_EXPR => Some(Expr::PathExpr(PathExpr { syntax })), | ||
951 | LAMBDA_EXPR => Some(Expr::LambdaExpr(LambdaExpr { syntax })), | ||
952 | IF_EXPR => Some(Expr::IfExpr(IfExpr { syntax })), | ||
953 | LOOP_EXPR => Some(Expr::LoopExpr(LoopExpr { syntax })), | ||
954 | FOR_EXPR => Some(Expr::ForExpr(ForExpr { syntax })), | ||
955 | WHILE_EXPR => Some(Expr::WhileExpr(WhileExpr { syntax })), | ||
956 | CONTINUE_EXPR => Some(Expr::ContinueExpr(ContinueExpr { syntax })), | ||
957 | BREAK_EXPR => Some(Expr::BreakExpr(BreakExpr { syntax })), | ||
958 | LABEL => Some(Expr::Label(Label { syntax })), | ||
959 | BLOCK_EXPR => Some(Expr::BlockExpr(BlockExpr { syntax })), | ||
960 | RETURN_EXPR => Some(Expr::ReturnExpr(ReturnExpr { syntax })), | ||
961 | MATCH_EXPR => Some(Expr::MatchExpr(MatchExpr { syntax })), | ||
962 | STRUCT_LIT => Some(Expr::StructLit(StructLit { syntax })), | ||
963 | CALL_EXPR => Some(Expr::CallExpr(CallExpr { syntax })), | ||
964 | INDEX_EXPR => Some(Expr::IndexExpr(IndexExpr { syntax })), | ||
965 | METHOD_CALL_EXPR => Some(Expr::MethodCallExpr(MethodCallExpr { syntax })), | ||
966 | FIELD_EXPR => Some(Expr::FieldExpr(FieldExpr { syntax })), | ||
967 | TRY_EXPR => Some(Expr::TryExpr(TryExpr { syntax })), | ||
968 | CAST_EXPR => Some(Expr::CastExpr(CastExpr { syntax })), | ||
969 | REF_EXPR => Some(Expr::RefExpr(RefExpr { syntax })), | ||
970 | PREFIX_EXPR => Some(Expr::PrefixExpr(PrefixExpr { syntax })), | ||
971 | RANGE_EXPR => Some(Expr::RangeExpr(RangeExpr { syntax })), | ||
972 | BIN_EXPR => Some(Expr::BinExpr(BinExpr { syntax })), | ||
973 | LITERAL => Some(Expr::Literal(Literal { syntax })), | ||
974 | _ => None, | ||
975 | } | ||
976 | } | ||
977 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
978 | match self { | ||
979 | Expr::TupleExpr(inner) => inner.syntax(), | ||
980 | Expr::ArrayExpr(inner) => inner.syntax(), | ||
981 | Expr::ParenExpr(inner) => inner.syntax(), | ||
982 | Expr::PathExpr(inner) => inner.syntax(), | ||
983 | Expr::LambdaExpr(inner) => inner.syntax(), | ||
984 | Expr::IfExpr(inner) => inner.syntax(), | ||
985 | Expr::LoopExpr(inner) => inner.syntax(), | ||
986 | Expr::ForExpr(inner) => inner.syntax(), | ||
987 | Expr::WhileExpr(inner) => inner.syntax(), | ||
988 | Expr::ContinueExpr(inner) => inner.syntax(), | ||
989 | Expr::BreakExpr(inner) => inner.syntax(), | ||
990 | Expr::Label(inner) => inner.syntax(), | ||
991 | Expr::BlockExpr(inner) => inner.syntax(), | ||
992 | Expr::ReturnExpr(inner) => inner.syntax(), | ||
993 | Expr::MatchExpr(inner) => inner.syntax(), | ||
994 | Expr::StructLit(inner) => inner.syntax(), | ||
995 | Expr::CallExpr(inner) => inner.syntax(), | ||
996 | Expr::IndexExpr(inner) => inner.syntax(), | ||
997 | Expr::MethodCallExpr(inner) => inner.syntax(), | ||
998 | Expr::FieldExpr(inner) => inner.syntax(), | ||
999 | Expr::TryExpr(inner) => inner.syntax(), | ||
1000 | Expr::CastExpr(inner) => inner.syntax(), | ||
1001 | Expr::RefExpr(inner) => inner.syntax(), | ||
1002 | Expr::PrefixExpr(inner) => inner.syntax(), | ||
1003 | Expr::RangeExpr(inner) => inner.syntax(), | ||
1004 | Expr::BinExpr(inner) => inner.syntax(), | ||
1005 | Expr::Literal(inner) => inner.syntax(), | ||
1006 | } | ||
1007 | } | ||
1008 | } | 637 | } |
1009 | 638 | ||
1010 | impl<'a> Expr<'a> {} | 639 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
640 | pub enum ExprKind<'a> { | ||
641 | TupleExpr(&'a TupleExpr), | ||
642 | ArrayExpr(&'a ArrayExpr), | ||
643 | ParenExpr(&'a ParenExpr), | ||
644 | PathExpr(&'a PathExpr), | ||
645 | LambdaExpr(&'a LambdaExpr), | ||
646 | IfExpr(&'a IfExpr), | ||
647 | LoopExpr(&'a LoopExpr), | ||
648 | ForExpr(&'a ForExpr), | ||
649 | WhileExpr(&'a WhileExpr), | ||
650 | ContinueExpr(&'a ContinueExpr), | ||
651 | BreakExpr(&'a BreakExpr), | ||
652 | Label(&'a Label), | ||
653 | BlockExpr(&'a BlockExpr), | ||
654 | ReturnExpr(&'a ReturnExpr), | ||
655 | MatchExpr(&'a MatchExpr), | ||
656 | StructLit(&'a StructLit), | ||
657 | CallExpr(&'a CallExpr), | ||
658 | IndexExpr(&'a IndexExpr), | ||
659 | MethodCallExpr(&'a MethodCallExpr), | ||
660 | FieldExpr(&'a FieldExpr), | ||
661 | TryExpr(&'a TryExpr), | ||
662 | CastExpr(&'a CastExpr), | ||
663 | RefExpr(&'a RefExpr), | ||
664 | PrefixExpr(&'a PrefixExpr), | ||
665 | RangeExpr(&'a RangeExpr), | ||
666 | BinExpr(&'a BinExpr), | ||
667 | Literal(&'a Literal), | ||
668 | } | ||
669 | |||
670 | impl AstNode for Expr { | ||
671 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
672 | match syntax.kind() { | ||
673 | | TUPLE_EXPR | ||
674 | | ARRAY_EXPR | ||
675 | | PAREN_EXPR | ||
676 | | PATH_EXPR | ||
677 | | LAMBDA_EXPR | ||
678 | | IF_EXPR | ||
679 | | LOOP_EXPR | ||
680 | | FOR_EXPR | ||
681 | | WHILE_EXPR | ||
682 | | CONTINUE_EXPR | ||
683 | | BREAK_EXPR | ||
684 | | LABEL | ||
685 | | BLOCK_EXPR | ||
686 | | RETURN_EXPR | ||
687 | | MATCH_EXPR | ||
688 | | STRUCT_LIT | ||
689 | | CALL_EXPR | ||
690 | | INDEX_EXPR | ||
691 | | METHOD_CALL_EXPR | ||
692 | | FIELD_EXPR | ||
693 | | TRY_EXPR | ||
694 | | CAST_EXPR | ||
695 | | REF_EXPR | ||
696 | | PREFIX_EXPR | ||
697 | | RANGE_EXPR | ||
698 | | BIN_EXPR | ||
699 | | LITERAL => Some(Expr::from_repr(syntax.into_repr())), | ||
700 | _ => None, | ||
701 | } | ||
702 | } | ||
703 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
704 | fn to_owned(&self) -> TreePtr<Expr> { TreePtr::cast(self.syntax.to_owned()) } | ||
705 | } | ||
706 | |||
707 | impl Expr { | ||
708 | pub fn kind(&self) -> ExprKind { | ||
709 | match self.syntax.kind() { | ||
710 | TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(&self.syntax).unwrap()), | ||
711 | ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(&self.syntax).unwrap()), | ||
712 | PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(&self.syntax).unwrap()), | ||
713 | PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(&self.syntax).unwrap()), | ||
714 | LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(&self.syntax).unwrap()), | ||
715 | IF_EXPR => ExprKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()), | ||
716 | LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(&self.syntax).unwrap()), | ||
717 | FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(&self.syntax).unwrap()), | ||
718 | WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(&self.syntax).unwrap()), | ||
719 | CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(&self.syntax).unwrap()), | ||
720 | BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(&self.syntax).unwrap()), | ||
721 | LABEL => ExprKind::Label(Label::cast(&self.syntax).unwrap()), | ||
722 | BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(&self.syntax).unwrap()), | ||
723 | RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(&self.syntax).unwrap()), | ||
724 | MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(&self.syntax).unwrap()), | ||
725 | STRUCT_LIT => ExprKind::StructLit(StructLit::cast(&self.syntax).unwrap()), | ||
726 | CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(&self.syntax).unwrap()), | ||
727 | INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(&self.syntax).unwrap()), | ||
728 | METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()), | ||
729 | FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()), | ||
730 | TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()), | ||
731 | CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()), | ||
732 | REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()), | ||
733 | PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()), | ||
734 | RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()), | ||
735 | BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()), | ||
736 | LITERAL => ExprKind::Literal(Literal::cast(&self.syntax).unwrap()), | ||
737 | _ => unreachable!(), | ||
738 | } | ||
739 | } | ||
740 | } | ||
741 | |||
742 | impl Expr {} | ||
1011 | 743 | ||
1012 | // ExprStmt | 744 | // ExprStmt |
1013 | #[derive(Debug, Clone, Copy,)] | 745 | #[derive(Debug, PartialEq, Eq, Hash)] |
1014 | pub struct ExprStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 746 | #[repr(transparent)] |
1015 | pub(crate) syntax: SyntaxNode<R>, | 747 | pub struct ExprStmt { |
748 | pub(crate) syntax: SyntaxNode, | ||
1016 | } | 749 | } |
1017 | pub type ExprStmt<'a> = ExprStmtNode<RefRoot<'a>>; | 750 | unsafe impl TransparentNewType for ExprStmt { |
1018 | 751 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1019 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExprStmtNode<R1>> for ExprStmtNode<R2> { | ||
1020 | fn eq(&self, other: &ExprStmtNode<R1>) -> bool { self.syntax == other.syntax } | ||
1021 | } | ||
1022 | impl<R: TreeRoot<RaTypes>> Eq for ExprStmtNode<R> {} | ||
1023 | impl<R: TreeRoot<RaTypes>> Hash for ExprStmtNode<R> { | ||
1024 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1025 | } | 752 | } |
1026 | 753 | ||
1027 | impl<'a> AstNode<'a> for ExprStmt<'a> { | 754 | impl AstNode for ExprStmt { |
1028 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 755 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1029 | match syntax.kind() { | 756 | match syntax.kind() { |
1030 | EXPR_STMT => Some(ExprStmt { syntax }), | 757 | EXPR_STMT => Some(ExprStmt::from_repr(syntax.into_repr())), |
1031 | _ => None, | 758 | _ => None, |
1032 | } | 759 | } |
1033 | } | 760 | } |
1034 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 761 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1035 | } | 762 | fn to_owned(&self) -> TreePtr<ExprStmt> { TreePtr::cast(self.syntax.to_owned()) } |
1036 | |||
1037 | impl<R: TreeRoot<RaTypes>> ExprStmtNode<R> { | ||
1038 | pub fn borrowed(&self) -> ExprStmt { | ||
1039 | ExprStmtNode { syntax: self.syntax.borrowed() } | ||
1040 | } | ||
1041 | pub fn owned(&self) -> ExprStmtNode { | ||
1042 | ExprStmtNode { syntax: self.syntax.owned() } | ||
1043 | } | ||
1044 | } | 763 | } |
1045 | 764 | ||
1046 | 765 | ||
1047 | impl<'a> ExprStmt<'a> { | 766 | impl ExprStmt { |
1048 | pub fn expr(self) -> Option<Expr<'a>> { | 767 | pub fn expr(&self) -> Option<&Expr> { |
1049 | super::child_opt(self) | 768 | super::child_opt(self) |
1050 | } | 769 | } |
1051 | } | 770 | } |
1052 | 771 | ||
1053 | // ExternCrateItem | 772 | // ExternCrateItem |
1054 | #[derive(Debug, Clone, Copy,)] | 773 | #[derive(Debug, PartialEq, Eq, Hash)] |
1055 | pub struct ExternCrateItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 774 | #[repr(transparent)] |
1056 | pub(crate) syntax: SyntaxNode<R>, | 775 | pub struct ExternCrateItem { |
1057 | } | 776 | pub(crate) syntax: SyntaxNode, |
1058 | pub type ExternCrateItem<'a> = ExternCrateItemNode<RefRoot<'a>>; | ||
1059 | |||
1060 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExternCrateItemNode<R1>> for ExternCrateItemNode<R2> { | ||
1061 | fn eq(&self, other: &ExternCrateItemNode<R1>) -> bool { self.syntax == other.syntax } | ||
1062 | } | 777 | } |
1063 | impl<R: TreeRoot<RaTypes>> Eq for ExternCrateItemNode<R> {} | 778 | unsafe impl TransparentNewType for ExternCrateItem { |
1064 | impl<R: TreeRoot<RaTypes>> Hash for ExternCrateItemNode<R> { | 779 | type Repr = rowan::SyntaxNode<RaTypes>; |
1065 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1066 | } | 780 | } |
1067 | 781 | ||
1068 | impl<'a> AstNode<'a> for ExternCrateItem<'a> { | 782 | impl AstNode for ExternCrateItem { |
1069 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 783 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1070 | match syntax.kind() { | 784 | match syntax.kind() { |
1071 | EXTERN_CRATE_ITEM => Some(ExternCrateItem { syntax }), | 785 | EXTERN_CRATE_ITEM => Some(ExternCrateItem::from_repr(syntax.into_repr())), |
1072 | _ => None, | 786 | _ => None, |
1073 | } | 787 | } |
1074 | } | 788 | } |
1075 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 789 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
790 | fn to_owned(&self) -> TreePtr<ExternCrateItem> { TreePtr::cast(self.syntax.to_owned()) } | ||
1076 | } | 791 | } |
1077 | 792 | ||
1078 | impl<R: TreeRoot<RaTypes>> ExternCrateItemNode<R> { | ||
1079 | pub fn borrowed(&self) -> ExternCrateItem { | ||
1080 | ExternCrateItemNode { syntax: self.syntax.borrowed() } | ||
1081 | } | ||
1082 | pub fn owned(&self) -> ExternCrateItemNode { | ||
1083 | ExternCrateItemNode { syntax: self.syntax.owned() } | ||
1084 | } | ||
1085 | } | ||
1086 | 793 | ||
1087 | 794 | impl ExternCrateItem {} | |
1088 | impl<'a> ExternCrateItem<'a> {} | ||
1089 | 795 | ||
1090 | // FieldExpr | 796 | // FieldExpr |
1091 | #[derive(Debug, Clone, Copy,)] | 797 | #[derive(Debug, PartialEq, Eq, Hash)] |
1092 | pub struct FieldExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 798 | #[repr(transparent)] |
1093 | pub(crate) syntax: SyntaxNode<R>, | 799 | pub struct FieldExpr { |
1094 | } | 800 | pub(crate) syntax: SyntaxNode, |
1095 | pub type FieldExpr<'a> = FieldExprNode<RefRoot<'a>>; | ||
1096 | |||
1097 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldExprNode<R1>> for FieldExprNode<R2> { | ||
1098 | fn eq(&self, other: &FieldExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1099 | } | 801 | } |
1100 | impl<R: TreeRoot<RaTypes>> Eq for FieldExprNode<R> {} | 802 | unsafe impl TransparentNewType for FieldExpr { |
1101 | impl<R: TreeRoot<RaTypes>> Hash for FieldExprNode<R> { | 803 | type Repr = rowan::SyntaxNode<RaTypes>; |
1102 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1103 | } | 804 | } |
1104 | 805 | ||
1105 | impl<'a> AstNode<'a> for FieldExpr<'a> { | 806 | impl AstNode for FieldExpr { |
1106 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 807 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1107 | match syntax.kind() { | 808 | match syntax.kind() { |
1108 | FIELD_EXPR => Some(FieldExpr { syntax }), | 809 | FIELD_EXPR => Some(FieldExpr::from_repr(syntax.into_repr())), |
1109 | _ => None, | 810 | _ => None, |
1110 | } | 811 | } |
1111 | } | 812 | } |
1112 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 813 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
814 | fn to_owned(&self) -> TreePtr<FieldExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
1113 | } | 815 | } |
1114 | 816 | ||
1115 | impl<R: TreeRoot<RaTypes>> FieldExprNode<R> { | ||
1116 | pub fn borrowed(&self) -> FieldExpr { | ||
1117 | FieldExprNode { syntax: self.syntax.borrowed() } | ||
1118 | } | ||
1119 | pub fn owned(&self) -> FieldExprNode { | ||
1120 | FieldExprNode { syntax: self.syntax.owned() } | ||
1121 | } | ||
1122 | } | ||
1123 | 817 | ||
1124 | 818 | impl FieldExpr { | |
1125 | impl<'a> FieldExpr<'a> { | 819 | pub fn expr(&self) -> Option<&Expr> { |
1126 | pub fn expr(self) -> Option<Expr<'a>> { | ||
1127 | super::child_opt(self) | 820 | super::child_opt(self) |
1128 | } | 821 | } |
1129 | 822 | ||
1130 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 823 | pub fn name_ref(&self) -> Option<&NameRef> { |
1131 | super::child_opt(self) | 824 | super::child_opt(self) |
1132 | } | 825 | } |
1133 | } | 826 | } |
1134 | 827 | ||
1135 | // FieldPatList | 828 | // FieldPatList |
1136 | #[derive(Debug, Clone, Copy,)] | 829 | #[derive(Debug, PartialEq, Eq, Hash)] |
1137 | pub struct FieldPatListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 830 | #[repr(transparent)] |
1138 | pub(crate) syntax: SyntaxNode<R>, | 831 | pub struct FieldPatList { |
832 | pub(crate) syntax: SyntaxNode, | ||
1139 | } | 833 | } |
1140 | pub type FieldPatList<'a> = FieldPatListNode<RefRoot<'a>>; | 834 | unsafe impl TransparentNewType for FieldPatList { |
1141 | 835 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1142 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldPatListNode<R1>> for FieldPatListNode<R2> { | ||
1143 | fn eq(&self, other: &FieldPatListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1144 | } | ||
1145 | impl<R: TreeRoot<RaTypes>> Eq for FieldPatListNode<R> {} | ||
1146 | impl<R: TreeRoot<RaTypes>> Hash for FieldPatListNode<R> { | ||
1147 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1148 | } | 836 | } |
1149 | 837 | ||
1150 | impl<'a> AstNode<'a> for FieldPatList<'a> { | 838 | impl AstNode for FieldPatList { |
1151 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 839 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1152 | match syntax.kind() { | 840 | match syntax.kind() { |
1153 | FIELD_PAT_LIST => Some(FieldPatList { syntax }), | 841 | FIELD_PAT_LIST => Some(FieldPatList::from_repr(syntax.into_repr())), |
1154 | _ => None, | 842 | _ => None, |
1155 | } | 843 | } |
1156 | } | 844 | } |
1157 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 845 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1158 | } | 846 | fn to_owned(&self) -> TreePtr<FieldPatList> { TreePtr::cast(self.syntax.to_owned()) } |
1159 | |||
1160 | impl<R: TreeRoot<RaTypes>> FieldPatListNode<R> { | ||
1161 | pub fn borrowed(&self) -> FieldPatList { | ||
1162 | FieldPatListNode { syntax: self.syntax.borrowed() } | ||
1163 | } | ||
1164 | pub fn owned(&self) -> FieldPatListNode { | ||
1165 | FieldPatListNode { syntax: self.syntax.owned() } | ||
1166 | } | ||
1167 | } | 847 | } |
1168 | 848 | ||
1169 | 849 | ||
1170 | impl<'a> FieldPatList<'a> {} | 850 | impl FieldPatList {} |
1171 | 851 | ||
1172 | // FnDef | 852 | // FnDef |
1173 | #[derive(Debug, Clone, Copy,)] | 853 | #[derive(Debug, PartialEq, Eq, Hash)] |
1174 | pub struct FnDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 854 | #[repr(transparent)] |
1175 | pub(crate) syntax: SyntaxNode<R>, | 855 | pub struct FnDef { |
856 | pub(crate) syntax: SyntaxNode, | ||
1176 | } | 857 | } |
1177 | pub type FnDef<'a> = FnDefNode<RefRoot<'a>>; | 858 | unsafe impl TransparentNewType for FnDef { |
1178 | 859 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1179 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnDefNode<R1>> for FnDefNode<R2> { | ||
1180 | fn eq(&self, other: &FnDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
1181 | } | ||
1182 | impl<R: TreeRoot<RaTypes>> Eq for FnDefNode<R> {} | ||
1183 | impl<R: TreeRoot<RaTypes>> Hash for FnDefNode<R> { | ||
1184 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1185 | } | 860 | } |
1186 | 861 | ||
1187 | impl<'a> AstNode<'a> for FnDef<'a> { | 862 | impl AstNode for FnDef { |
1188 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 863 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1189 | match syntax.kind() { | 864 | match syntax.kind() { |
1190 | FN_DEF => Some(FnDef { syntax }), | 865 | FN_DEF => Some(FnDef::from_repr(syntax.into_repr())), |
1191 | _ => None, | 866 | _ => None, |
1192 | } | 867 | } |
1193 | } | 868 | } |
1194 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 869 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1195 | } | 870 | fn to_owned(&self) -> TreePtr<FnDef> { TreePtr::cast(self.syntax.to_owned()) } |
1196 | |||
1197 | impl<R: TreeRoot<RaTypes>> FnDefNode<R> { | ||
1198 | pub fn borrowed(&self) -> FnDef { | ||
1199 | FnDefNode { syntax: self.syntax.borrowed() } | ||
1200 | } | ||
1201 | pub fn owned(&self) -> FnDefNode { | ||
1202 | FnDefNode { syntax: self.syntax.owned() } | ||
1203 | } | ||
1204 | } | 871 | } |
1205 | 872 | ||
1206 | 873 | ||
1207 | impl<'a> ast::VisibilityOwner<'a> for FnDef<'a> {} | 874 | impl ast::VisibilityOwner for FnDef {} |
1208 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} | 875 | impl ast::NameOwner for FnDef {} |
1209 | impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} | 876 | impl ast::TypeParamsOwner for FnDef {} |
1210 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} | 877 | impl ast::AttrsOwner for FnDef {} |
1211 | impl<'a> ast::DocCommentsOwner<'a> for FnDef<'a> {} | 878 | impl ast::DocCommentsOwner for FnDef {} |
1212 | impl<'a> FnDef<'a> { | 879 | impl FnDef { |
1213 | pub fn param_list(self) -> Option<ParamList<'a>> { | 880 | pub fn param_list(&self) -> Option<&ParamList> { |
1214 | super::child_opt(self) | 881 | super::child_opt(self) |
1215 | } | 882 | } |
1216 | 883 | ||
1217 | pub fn body(self) -> Option<Block<'a>> { | 884 | pub fn body(&self) -> Option<&Block> { |
1218 | super::child_opt(self) | 885 | super::child_opt(self) |
1219 | } | 886 | } |
1220 | 887 | ||
1221 | pub fn ret_type(self) -> Option<RetType<'a>> { | 888 | pub fn ret_type(&self) -> Option<&RetType> { |
1222 | super::child_opt(self) | 889 | super::child_opt(self) |
1223 | } | 890 | } |
1224 | } | 891 | } |
1225 | 892 | ||
1226 | // FnPointerType | 893 | // FnPointerType |
1227 | #[derive(Debug, Clone, Copy,)] | 894 | #[derive(Debug, PartialEq, Eq, Hash)] |
1228 | pub struct FnPointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 895 | #[repr(transparent)] |
1229 | pub(crate) syntax: SyntaxNode<R>, | 896 | pub struct FnPointerType { |
1230 | } | 897 | pub(crate) syntax: SyntaxNode, |
1231 | pub type FnPointerType<'a> = FnPointerTypeNode<RefRoot<'a>>; | ||
1232 | |||
1233 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnPointerTypeNode<R1>> for FnPointerTypeNode<R2> { | ||
1234 | fn eq(&self, other: &FnPointerTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1235 | } | 898 | } |
1236 | impl<R: TreeRoot<RaTypes>> Eq for FnPointerTypeNode<R> {} | 899 | unsafe impl TransparentNewType for FnPointerType { |
1237 | impl<R: TreeRoot<RaTypes>> Hash for FnPointerTypeNode<R> { | 900 | type Repr = rowan::SyntaxNode<RaTypes>; |
1238 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1239 | } | 901 | } |
1240 | 902 | ||
1241 | impl<'a> AstNode<'a> for FnPointerType<'a> { | 903 | impl AstNode for FnPointerType { |
1242 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 904 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1243 | match syntax.kind() { | 905 | match syntax.kind() { |
1244 | FN_POINTER_TYPE => Some(FnPointerType { syntax }), | 906 | FN_POINTER_TYPE => Some(FnPointerType::from_repr(syntax.into_repr())), |
1245 | _ => None, | 907 | _ => None, |
1246 | } | 908 | } |
1247 | } | 909 | } |
1248 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 910 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
911 | fn to_owned(&self) -> TreePtr<FnPointerType> { TreePtr::cast(self.syntax.to_owned()) } | ||
1249 | } | 912 | } |
1250 | 913 | ||
1251 | impl<R: TreeRoot<RaTypes>> FnPointerTypeNode<R> { | ||
1252 | pub fn borrowed(&self) -> FnPointerType { | ||
1253 | FnPointerTypeNode { syntax: self.syntax.borrowed() } | ||
1254 | } | ||
1255 | pub fn owned(&self) -> FnPointerTypeNode { | ||
1256 | FnPointerTypeNode { syntax: self.syntax.owned() } | ||
1257 | } | ||
1258 | } | ||
1259 | 914 | ||
1260 | 915 | impl FnPointerType { | |
1261 | impl<'a> FnPointerType<'a> { | 916 | pub fn param_list(&self) -> Option<&ParamList> { |
1262 | pub fn param_list(self) -> Option<ParamList<'a>> { | ||
1263 | super::child_opt(self) | 917 | super::child_opt(self) |
1264 | } | 918 | } |
1265 | 919 | ||
1266 | pub fn ret_type(self) -> Option<RetType<'a>> { | 920 | pub fn ret_type(&self) -> Option<&RetType> { |
1267 | super::child_opt(self) | 921 | super::child_opt(self) |
1268 | } | 922 | } |
1269 | } | 923 | } |
1270 | 924 | ||
1271 | // ForExpr | 925 | // ForExpr |
1272 | #[derive(Debug, Clone, Copy,)] | 926 | #[derive(Debug, PartialEq, Eq, Hash)] |
1273 | pub struct ForExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 927 | #[repr(transparent)] |
1274 | pub(crate) syntax: SyntaxNode<R>, | 928 | pub struct ForExpr { |
1275 | } | 929 | pub(crate) syntax: SyntaxNode, |
1276 | pub type ForExpr<'a> = ForExprNode<RefRoot<'a>>; | ||
1277 | |||
1278 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForExprNode<R1>> for ForExprNode<R2> { | ||
1279 | fn eq(&self, other: &ForExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1280 | } | 930 | } |
1281 | impl<R: TreeRoot<RaTypes>> Eq for ForExprNode<R> {} | 931 | unsafe impl TransparentNewType for ForExpr { |
1282 | impl<R: TreeRoot<RaTypes>> Hash for ForExprNode<R> { | 932 | type Repr = rowan::SyntaxNode<RaTypes>; |
1283 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1284 | } | 933 | } |
1285 | 934 | ||
1286 | impl<'a> AstNode<'a> for ForExpr<'a> { | 935 | impl AstNode for ForExpr { |
1287 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 936 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1288 | match syntax.kind() { | 937 | match syntax.kind() { |
1289 | FOR_EXPR => Some(ForExpr { syntax }), | 938 | FOR_EXPR => Some(ForExpr::from_repr(syntax.into_repr())), |
1290 | _ => None, | 939 | _ => None, |
1291 | } | 940 | } |
1292 | } | 941 | } |
1293 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 942 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1294 | } | 943 | fn to_owned(&self) -> TreePtr<ForExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1295 | |||
1296 | impl<R: TreeRoot<RaTypes>> ForExprNode<R> { | ||
1297 | pub fn borrowed(&self) -> ForExpr { | ||
1298 | ForExprNode { syntax: self.syntax.borrowed() } | ||
1299 | } | ||
1300 | pub fn owned(&self) -> ForExprNode { | ||
1301 | ForExprNode { syntax: self.syntax.owned() } | ||
1302 | } | ||
1303 | } | 944 | } |
1304 | 945 | ||
1305 | 946 | ||
1306 | impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} | 947 | impl ast::LoopBodyOwner for ForExpr {} |
1307 | impl<'a> ForExpr<'a> { | 948 | impl ForExpr { |
1308 | pub fn pat(self) -> Option<Pat<'a>> { | 949 | pub fn pat(&self) -> Option<&Pat> { |
1309 | super::child_opt(self) | 950 | super::child_opt(self) |
1310 | } | 951 | } |
1311 | 952 | ||
1312 | pub fn iterable(self) -> Option<Expr<'a>> { | 953 | pub fn iterable(&self) -> Option<&Expr> { |
1313 | super::child_opt(self) | 954 | super::child_opt(self) |
1314 | } | 955 | } |
1315 | } | 956 | } |
1316 | 957 | ||
1317 | // ForType | 958 | // ForType |
1318 | #[derive(Debug, Clone, Copy,)] | 959 | #[derive(Debug, PartialEq, Eq, Hash)] |
1319 | pub struct ForTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 960 | #[repr(transparent)] |
1320 | pub(crate) syntax: SyntaxNode<R>, | 961 | pub struct ForType { |
1321 | } | 962 | pub(crate) syntax: SyntaxNode, |
1322 | pub type ForType<'a> = ForTypeNode<RefRoot<'a>>; | ||
1323 | |||
1324 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForTypeNode<R1>> for ForTypeNode<R2> { | ||
1325 | fn eq(&self, other: &ForTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1326 | } | 963 | } |
1327 | impl<R: TreeRoot<RaTypes>> Eq for ForTypeNode<R> {} | 964 | unsafe impl TransparentNewType for ForType { |
1328 | impl<R: TreeRoot<RaTypes>> Hash for ForTypeNode<R> { | 965 | type Repr = rowan::SyntaxNode<RaTypes>; |
1329 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1330 | } | 966 | } |
1331 | 967 | ||
1332 | impl<'a> AstNode<'a> for ForType<'a> { | 968 | impl AstNode for ForType { |
1333 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 969 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1334 | match syntax.kind() { | 970 | match syntax.kind() { |
1335 | FOR_TYPE => Some(ForType { syntax }), | 971 | FOR_TYPE => Some(ForType::from_repr(syntax.into_repr())), |
1336 | _ => None, | 972 | _ => None, |
1337 | } | 973 | } |
1338 | } | 974 | } |
1339 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 975 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1340 | } | 976 | fn to_owned(&self) -> TreePtr<ForType> { TreePtr::cast(self.syntax.to_owned()) } |
1341 | |||
1342 | impl<R: TreeRoot<RaTypes>> ForTypeNode<R> { | ||
1343 | pub fn borrowed(&self) -> ForType { | ||
1344 | ForTypeNode { syntax: self.syntax.borrowed() } | ||
1345 | } | ||
1346 | pub fn owned(&self) -> ForTypeNode { | ||
1347 | ForTypeNode { syntax: self.syntax.owned() } | ||
1348 | } | ||
1349 | } | 977 | } |
1350 | 978 | ||
1351 | 979 | ||
1352 | impl<'a> ForType<'a> { | 980 | impl ForType { |
1353 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 981 | pub fn type_ref(&self) -> Option<&TypeRef> { |
1354 | super::child_opt(self) | 982 | super::child_opt(self) |
1355 | } | 983 | } |
1356 | } | 984 | } |
1357 | 985 | ||
1358 | // IfExpr | 986 | // IfExpr |
1359 | #[derive(Debug, Clone, Copy,)] | 987 | #[derive(Debug, PartialEq, Eq, Hash)] |
1360 | pub struct IfExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 988 | #[repr(transparent)] |
1361 | pub(crate) syntax: SyntaxNode<R>, | 989 | pub struct IfExpr { |
990 | pub(crate) syntax: SyntaxNode, | ||
1362 | } | 991 | } |
1363 | pub type IfExpr<'a> = IfExprNode<RefRoot<'a>>; | 992 | unsafe impl TransparentNewType for IfExpr { |
1364 | 993 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1365 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IfExprNode<R1>> for IfExprNode<R2> { | ||
1366 | fn eq(&self, other: &IfExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1367 | } | ||
1368 | impl<R: TreeRoot<RaTypes>> Eq for IfExprNode<R> {} | ||
1369 | impl<R: TreeRoot<RaTypes>> Hash for IfExprNode<R> { | ||
1370 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1371 | } | 994 | } |
1372 | 995 | ||
1373 | impl<'a> AstNode<'a> for IfExpr<'a> { | 996 | impl AstNode for IfExpr { |
1374 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 997 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1375 | match syntax.kind() { | 998 | match syntax.kind() { |
1376 | IF_EXPR => Some(IfExpr { syntax }), | 999 | IF_EXPR => Some(IfExpr::from_repr(syntax.into_repr())), |
1377 | _ => None, | 1000 | _ => None, |
1378 | } | 1001 | } |
1379 | } | 1002 | } |
1380 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1003 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1381 | } | 1004 | fn to_owned(&self) -> TreePtr<IfExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1382 | |||
1383 | impl<R: TreeRoot<RaTypes>> IfExprNode<R> { | ||
1384 | pub fn borrowed(&self) -> IfExpr { | ||
1385 | IfExprNode { syntax: self.syntax.borrowed() } | ||
1386 | } | ||
1387 | pub fn owned(&self) -> IfExprNode { | ||
1388 | IfExprNode { syntax: self.syntax.owned() } | ||
1389 | } | ||
1390 | } | 1005 | } |
1391 | 1006 | ||
1392 | 1007 | ||
1393 | impl<'a> IfExpr<'a> { | 1008 | impl IfExpr { |
1394 | pub fn condition(self) -> Option<Condition<'a>> { | 1009 | pub fn condition(&self) -> Option<&Condition> { |
1395 | super::child_opt(self) | 1010 | super::child_opt(self) |
1396 | } | 1011 | } |
1397 | } | 1012 | } |
1398 | 1013 | ||
1399 | // ImplBlock | 1014 | // ImplBlock |
1400 | #[derive(Debug, Clone, Copy,)] | 1015 | #[derive(Debug, PartialEq, Eq, Hash)] |
1401 | pub struct ImplBlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1016 | #[repr(transparent)] |
1402 | pub(crate) syntax: SyntaxNode<R>, | 1017 | pub struct ImplBlock { |
1018 | pub(crate) syntax: SyntaxNode, | ||
1403 | } | 1019 | } |
1404 | pub type ImplBlock<'a> = ImplBlockNode<RefRoot<'a>>; | 1020 | unsafe impl TransparentNewType for ImplBlock { |
1405 | 1021 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1406 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplBlockNode<R1>> for ImplBlockNode<R2> { | ||
1407 | fn eq(&self, other: &ImplBlockNode<R1>) -> bool { self.syntax == other.syntax } | ||
1408 | } | ||
1409 | impl<R: TreeRoot<RaTypes>> Eq for ImplBlockNode<R> {} | ||
1410 | impl<R: TreeRoot<RaTypes>> Hash for ImplBlockNode<R> { | ||
1411 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1412 | } | 1022 | } |
1413 | 1023 | ||
1414 | impl<'a> AstNode<'a> for ImplBlock<'a> { | 1024 | impl AstNode for ImplBlock { |
1415 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1025 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1416 | match syntax.kind() { | 1026 | match syntax.kind() { |
1417 | IMPL_BLOCK => Some(ImplBlock { syntax }), | 1027 | IMPL_BLOCK => Some(ImplBlock::from_repr(syntax.into_repr())), |
1418 | _ => None, | 1028 | _ => None, |
1419 | } | 1029 | } |
1420 | } | 1030 | } |
1421 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1031 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1422 | } | 1032 | fn to_owned(&self) -> TreePtr<ImplBlock> { TreePtr::cast(self.syntax.to_owned()) } |
1423 | |||
1424 | impl<R: TreeRoot<RaTypes>> ImplBlockNode<R> { | ||
1425 | pub fn borrowed(&self) -> ImplBlock { | ||
1426 | ImplBlockNode { syntax: self.syntax.borrowed() } | ||
1427 | } | ||
1428 | pub fn owned(&self) -> ImplBlockNode { | ||
1429 | ImplBlockNode { syntax: self.syntax.owned() } | ||
1430 | } | ||
1431 | } | 1033 | } |
1432 | 1034 | ||
1433 | 1035 | ||
1434 | impl<'a> ImplBlock<'a> { | 1036 | impl ImplBlock { |
1435 | pub fn item_list(self) -> Option<ItemList<'a>> { | 1037 | pub fn item_list(&self) -> Option<&ItemList> { |
1436 | super::child_opt(self) | 1038 | super::child_opt(self) |
1437 | } | 1039 | } |
1438 | } | 1040 | } |
1439 | 1041 | ||
1440 | // ImplItem | 1042 | // ImplItem |
1043 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1044 | #[repr(transparent)] | ||
1045 | pub struct ImplItem { | ||
1046 | pub(crate) syntax: SyntaxNode, | ||
1047 | } | ||
1048 | unsafe impl TransparentNewType for ImplItem { | ||
1049 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1050 | } | ||
1051 | |||
1441 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1052 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1442 | pub enum ImplItem<'a> { | 1053 | pub enum ImplItemKind<'a> { |
1443 | FnDef(FnDef<'a>), | 1054 | FnDef(&'a FnDef), |
1444 | TypeDef(TypeDef<'a>), | 1055 | TypeDef(&'a TypeDef), |
1445 | ConstDef(ConstDef<'a>), | 1056 | ConstDef(&'a ConstDef), |
1446 | } | 1057 | } |
1447 | 1058 | ||
1448 | impl<'a> AstNode<'a> for ImplItem<'a> { | 1059 | impl AstNode for ImplItem { |
1449 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1060 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1450 | match syntax.kind() { | 1061 | match syntax.kind() { |
1451 | FN_DEF => Some(ImplItem::FnDef(FnDef { syntax })), | 1062 | | FN_DEF |
1452 | TYPE_DEF => Some(ImplItem::TypeDef(TypeDef { syntax })), | 1063 | | TYPE_DEF |
1453 | CONST_DEF => Some(ImplItem::ConstDef(ConstDef { syntax })), | 1064 | | CONST_DEF => Some(ImplItem::from_repr(syntax.into_repr())), |
1454 | _ => None, | 1065 | _ => None, |
1455 | } | 1066 | } |
1456 | } | 1067 | } |
1457 | fn syntax(self) -> SyntaxNodeRef<'a> { | 1068 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1458 | match self { | 1069 | fn to_owned(&self) -> TreePtr<ImplItem> { TreePtr::cast(self.syntax.to_owned()) } |
1459 | ImplItem::FnDef(inner) => inner.syntax(), | 1070 | } |
1460 | ImplItem::TypeDef(inner) => inner.syntax(), | 1071 | |
1461 | ImplItem::ConstDef(inner) => inner.syntax(), | 1072 | impl ImplItem { |
1073 | pub fn kind(&self) -> ImplItemKind { | ||
1074 | match self.syntax.kind() { | ||
1075 | FN_DEF => ImplItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), | ||
1076 | TYPE_DEF => ImplItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), | ||
1077 | CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), | ||
1078 | _ => unreachable!(), | ||
1462 | } | 1079 | } |
1463 | } | 1080 | } |
1464 | } | 1081 | } |
1465 | 1082 | ||
1466 | impl<'a> ImplItem<'a> {} | 1083 | impl ImplItem {} |
1467 | 1084 | ||
1468 | // ImplTraitType | 1085 | // ImplTraitType |
1469 | #[derive(Debug, Clone, Copy,)] | 1086 | #[derive(Debug, PartialEq, Eq, Hash)] |
1470 | pub struct ImplTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1087 | #[repr(transparent)] |
1471 | pub(crate) syntax: SyntaxNode<R>, | 1088 | pub struct ImplTraitType { |
1472 | } | 1089 | pub(crate) syntax: SyntaxNode, |
1473 | pub type ImplTraitType<'a> = ImplTraitTypeNode<RefRoot<'a>>; | ||
1474 | |||
1475 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplTraitTypeNode<R1>> for ImplTraitTypeNode<R2> { | ||
1476 | fn eq(&self, other: &ImplTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1477 | } | 1090 | } |
1478 | impl<R: TreeRoot<RaTypes>> Eq for ImplTraitTypeNode<R> {} | 1091 | unsafe impl TransparentNewType for ImplTraitType { |
1479 | impl<R: TreeRoot<RaTypes>> Hash for ImplTraitTypeNode<R> { | 1092 | type Repr = rowan::SyntaxNode<RaTypes>; |
1480 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1481 | } | 1093 | } |
1482 | 1094 | ||
1483 | impl<'a> AstNode<'a> for ImplTraitType<'a> { | 1095 | impl AstNode for ImplTraitType { |
1484 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1096 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1485 | match syntax.kind() { | 1097 | match syntax.kind() { |
1486 | IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), | 1098 | IMPL_TRAIT_TYPE => Some(ImplTraitType::from_repr(syntax.into_repr())), |
1487 | _ => None, | 1099 | _ => None, |
1488 | } | 1100 | } |
1489 | } | 1101 | } |
1490 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1102 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1103 | fn to_owned(&self) -> TreePtr<ImplTraitType> { TreePtr::cast(self.syntax.to_owned()) } | ||
1491 | } | 1104 | } |
1492 | 1105 | ||
1493 | impl<R: TreeRoot<RaTypes>> ImplTraitTypeNode<R> { | ||
1494 | pub fn borrowed(&self) -> ImplTraitType { | ||
1495 | ImplTraitTypeNode { syntax: self.syntax.borrowed() } | ||
1496 | } | ||
1497 | pub fn owned(&self) -> ImplTraitTypeNode { | ||
1498 | ImplTraitTypeNode { syntax: self.syntax.owned() } | ||
1499 | } | ||
1500 | } | ||
1501 | 1106 | ||
1502 | 1107 | impl ImplTraitType {} | |
1503 | impl<'a> ImplTraitType<'a> {} | ||
1504 | 1108 | ||
1505 | // IndexExpr | 1109 | // IndexExpr |
1506 | #[derive(Debug, Clone, Copy,)] | 1110 | #[derive(Debug, PartialEq, Eq, Hash)] |
1507 | pub struct IndexExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1111 | #[repr(transparent)] |
1508 | pub(crate) syntax: SyntaxNode<R>, | 1112 | pub struct IndexExpr { |
1113 | pub(crate) syntax: SyntaxNode, | ||
1509 | } | 1114 | } |
1510 | pub type IndexExpr<'a> = IndexExprNode<RefRoot<'a>>; | 1115 | unsafe impl TransparentNewType for IndexExpr { |
1511 | 1116 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1512 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IndexExprNode<R1>> for IndexExprNode<R2> { | ||
1513 | fn eq(&self, other: &IndexExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1514 | } | ||
1515 | impl<R: TreeRoot<RaTypes>> Eq for IndexExprNode<R> {} | ||
1516 | impl<R: TreeRoot<RaTypes>> Hash for IndexExprNode<R> { | ||
1517 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1518 | } | 1117 | } |
1519 | 1118 | ||
1520 | impl<'a> AstNode<'a> for IndexExpr<'a> { | 1119 | impl AstNode for IndexExpr { |
1521 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1120 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1522 | match syntax.kind() { | 1121 | match syntax.kind() { |
1523 | INDEX_EXPR => Some(IndexExpr { syntax }), | 1122 | INDEX_EXPR => Some(IndexExpr::from_repr(syntax.into_repr())), |
1524 | _ => None, | 1123 | _ => None, |
1525 | } | 1124 | } |
1526 | } | 1125 | } |
1527 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1126 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1528 | } | 1127 | fn to_owned(&self) -> TreePtr<IndexExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1529 | |||
1530 | impl<R: TreeRoot<RaTypes>> IndexExprNode<R> { | ||
1531 | pub fn borrowed(&self) -> IndexExpr { | ||
1532 | IndexExprNode { syntax: self.syntax.borrowed() } | ||
1533 | } | ||
1534 | pub fn owned(&self) -> IndexExprNode { | ||
1535 | IndexExprNode { syntax: self.syntax.owned() } | ||
1536 | } | ||
1537 | } | 1128 | } |
1538 | 1129 | ||
1539 | 1130 | ||
1540 | impl<'a> IndexExpr<'a> {} | 1131 | impl IndexExpr {} |
1541 | 1132 | ||
1542 | // ItemList | 1133 | // ItemList |
1543 | #[derive(Debug, Clone, Copy,)] | 1134 | #[derive(Debug, PartialEq, Eq, Hash)] |
1544 | pub struct ItemListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1135 | #[repr(transparent)] |
1545 | pub(crate) syntax: SyntaxNode<R>, | 1136 | pub struct ItemList { |
1137 | pub(crate) syntax: SyntaxNode, | ||
1546 | } | 1138 | } |
1547 | pub type ItemList<'a> = ItemListNode<RefRoot<'a>>; | 1139 | unsafe impl TransparentNewType for ItemList { |
1548 | 1140 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1549 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ItemListNode<R1>> for ItemListNode<R2> { | ||
1550 | fn eq(&self, other: &ItemListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1551 | } | ||
1552 | impl<R: TreeRoot<RaTypes>> Eq for ItemListNode<R> {} | ||
1553 | impl<R: TreeRoot<RaTypes>> Hash for ItemListNode<R> { | ||
1554 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1555 | } | 1141 | } |
1556 | 1142 | ||
1557 | impl<'a> AstNode<'a> for ItemList<'a> { | 1143 | impl AstNode for ItemList { |
1558 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1144 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1559 | match syntax.kind() { | 1145 | match syntax.kind() { |
1560 | ITEM_LIST => Some(ItemList { syntax }), | 1146 | ITEM_LIST => Some(ItemList::from_repr(syntax.into_repr())), |
1561 | _ => None, | 1147 | _ => None, |
1562 | } | 1148 | } |
1563 | } | 1149 | } |
1564 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1150 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1565 | } | 1151 | fn to_owned(&self) -> TreePtr<ItemList> { TreePtr::cast(self.syntax.to_owned()) } |
1566 | |||
1567 | impl<R: TreeRoot<RaTypes>> ItemListNode<R> { | ||
1568 | pub fn borrowed(&self) -> ItemList { | ||
1569 | ItemListNode { syntax: self.syntax.borrowed() } | ||
1570 | } | ||
1571 | pub fn owned(&self) -> ItemListNode { | ||
1572 | ItemListNode { syntax: self.syntax.owned() } | ||
1573 | } | ||
1574 | } | 1152 | } |
1575 | 1153 | ||
1576 | 1154 | ||
1577 | impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} | 1155 | impl ast::FnDefOwner for ItemList {} |
1578 | impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} | 1156 | impl ast::ModuleItemOwner for ItemList {} |
1579 | impl<'a> ItemList<'a> { | 1157 | impl ItemList { |
1580 | pub fn impl_items(self) -> impl Iterator<Item = ImplItem<'a>> + 'a { | 1158 | pub fn impl_items(&self) -> impl Iterator<Item = &ImplItem> { |
1581 | super::children(self) | 1159 | super::children(self) |
1582 | } | 1160 | } |
1583 | } | 1161 | } |
1584 | 1162 | ||
1585 | // Label | 1163 | // Label |
1586 | #[derive(Debug, Clone, Copy,)] | 1164 | #[derive(Debug, PartialEq, Eq, Hash)] |
1587 | pub struct LabelNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1165 | #[repr(transparent)] |
1588 | pub(crate) syntax: SyntaxNode<R>, | 1166 | pub struct Label { |
1167 | pub(crate) syntax: SyntaxNode, | ||
1589 | } | 1168 | } |
1590 | pub type Label<'a> = LabelNode<RefRoot<'a>>; | 1169 | unsafe impl TransparentNewType for Label { |
1591 | 1170 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1592 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LabelNode<R1>> for LabelNode<R2> { | ||
1593 | fn eq(&self, other: &LabelNode<R1>) -> bool { self.syntax == other.syntax } | ||
1594 | } | ||
1595 | impl<R: TreeRoot<RaTypes>> Eq for LabelNode<R> {} | ||
1596 | impl<R: TreeRoot<RaTypes>> Hash for LabelNode<R> { | ||
1597 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1598 | } | 1171 | } |
1599 | 1172 | ||
1600 | impl<'a> AstNode<'a> for Label<'a> { | 1173 | impl AstNode for Label { |
1601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1174 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1602 | match syntax.kind() { | 1175 | match syntax.kind() { |
1603 | LABEL => Some(Label { syntax }), | 1176 | LABEL => Some(Label::from_repr(syntax.into_repr())), |
1604 | _ => None, | 1177 | _ => None, |
1605 | } | 1178 | } |
1606 | } | 1179 | } |
1607 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1180 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1608 | } | 1181 | fn to_owned(&self) -> TreePtr<Label> { TreePtr::cast(self.syntax.to_owned()) } |
1609 | |||
1610 | impl<R: TreeRoot<RaTypes>> LabelNode<R> { | ||
1611 | pub fn borrowed(&self) -> Label { | ||
1612 | LabelNode { syntax: self.syntax.borrowed() } | ||
1613 | } | ||
1614 | pub fn owned(&self) -> LabelNode { | ||
1615 | LabelNode { syntax: self.syntax.owned() } | ||
1616 | } | ||
1617 | } | 1182 | } |
1618 | 1183 | ||
1619 | 1184 | ||
1620 | impl<'a> Label<'a> {} | 1185 | impl Label {} |
1621 | 1186 | ||
1622 | // LambdaExpr | 1187 | // LambdaExpr |
1623 | #[derive(Debug, Clone, Copy,)] | 1188 | #[derive(Debug, PartialEq, Eq, Hash)] |
1624 | pub struct LambdaExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1189 | #[repr(transparent)] |
1625 | pub(crate) syntax: SyntaxNode<R>, | 1190 | pub struct LambdaExpr { |
1626 | } | 1191 | pub(crate) syntax: SyntaxNode, |
1627 | pub type LambdaExpr<'a> = LambdaExprNode<RefRoot<'a>>; | ||
1628 | |||
1629 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LambdaExprNode<R1>> for LambdaExprNode<R2> { | ||
1630 | fn eq(&self, other: &LambdaExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1631 | } | 1192 | } |
1632 | impl<R: TreeRoot<RaTypes>> Eq for LambdaExprNode<R> {} | 1193 | unsafe impl TransparentNewType for LambdaExpr { |
1633 | impl<R: TreeRoot<RaTypes>> Hash for LambdaExprNode<R> { | 1194 | type Repr = rowan::SyntaxNode<RaTypes>; |
1634 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1635 | } | 1195 | } |
1636 | 1196 | ||
1637 | impl<'a> AstNode<'a> for LambdaExpr<'a> { | 1197 | impl AstNode for LambdaExpr { |
1638 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1198 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1639 | match syntax.kind() { | 1199 | match syntax.kind() { |
1640 | LAMBDA_EXPR => Some(LambdaExpr { syntax }), | 1200 | LAMBDA_EXPR => Some(LambdaExpr::from_repr(syntax.into_repr())), |
1641 | _ => None, | 1201 | _ => None, |
1642 | } | 1202 | } |
1643 | } | 1203 | } |
1644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1204 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1645 | } | 1205 | fn to_owned(&self) -> TreePtr<LambdaExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1646 | |||
1647 | impl<R: TreeRoot<RaTypes>> LambdaExprNode<R> { | ||
1648 | pub fn borrowed(&self) -> LambdaExpr { | ||
1649 | LambdaExprNode { syntax: self.syntax.borrowed() } | ||
1650 | } | ||
1651 | pub fn owned(&self) -> LambdaExprNode { | ||
1652 | LambdaExprNode { syntax: self.syntax.owned() } | ||
1653 | } | ||
1654 | } | 1206 | } |
1655 | 1207 | ||
1656 | 1208 | ||
1657 | impl<'a> LambdaExpr<'a> { | 1209 | impl LambdaExpr { |
1658 | pub fn param_list(self) -> Option<ParamList<'a>> { | 1210 | pub fn param_list(&self) -> Option<&ParamList> { |
1659 | super::child_opt(self) | 1211 | super::child_opt(self) |
1660 | } | 1212 | } |
1661 | 1213 | ||
1662 | pub fn body(self) -> Option<Expr<'a>> { | 1214 | pub fn body(&self) -> Option<&Expr> { |
1663 | super::child_opt(self) | 1215 | super::child_opt(self) |
1664 | } | 1216 | } |
1665 | } | 1217 | } |
1666 | 1218 | ||
1667 | // LetStmt | 1219 | // LetStmt |
1668 | #[derive(Debug, Clone, Copy,)] | 1220 | #[derive(Debug, PartialEq, Eq, Hash)] |
1669 | pub struct LetStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1221 | #[repr(transparent)] |
1670 | pub(crate) syntax: SyntaxNode<R>, | 1222 | pub struct LetStmt { |
1671 | } | 1223 | pub(crate) syntax: SyntaxNode, |
1672 | pub type LetStmt<'a> = LetStmtNode<RefRoot<'a>>; | ||
1673 | |||
1674 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LetStmtNode<R1>> for LetStmtNode<R2> { | ||
1675 | fn eq(&self, other: &LetStmtNode<R1>) -> bool { self.syntax == other.syntax } | ||
1676 | } | 1224 | } |
1677 | impl<R: TreeRoot<RaTypes>> Eq for LetStmtNode<R> {} | 1225 | unsafe impl TransparentNewType for LetStmt { |
1678 | impl<R: TreeRoot<RaTypes>> Hash for LetStmtNode<R> { | 1226 | type Repr = rowan::SyntaxNode<RaTypes>; |
1679 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1680 | } | 1227 | } |
1681 | 1228 | ||
1682 | impl<'a> AstNode<'a> for LetStmt<'a> { | 1229 | impl AstNode for LetStmt { |
1683 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1230 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1684 | match syntax.kind() { | 1231 | match syntax.kind() { |
1685 | LET_STMT => Some(LetStmt { syntax }), | 1232 | LET_STMT => Some(LetStmt::from_repr(syntax.into_repr())), |
1686 | _ => None, | 1233 | _ => None, |
1687 | } | 1234 | } |
1688 | } | 1235 | } |
1689 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1236 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1690 | } | 1237 | fn to_owned(&self) -> TreePtr<LetStmt> { TreePtr::cast(self.syntax.to_owned()) } |
1691 | |||
1692 | impl<R: TreeRoot<RaTypes>> LetStmtNode<R> { | ||
1693 | pub fn borrowed(&self) -> LetStmt { | ||
1694 | LetStmtNode { syntax: self.syntax.borrowed() } | ||
1695 | } | ||
1696 | pub fn owned(&self) -> LetStmtNode { | ||
1697 | LetStmtNode { syntax: self.syntax.owned() } | ||
1698 | } | ||
1699 | } | 1238 | } |
1700 | 1239 | ||
1701 | 1240 | ||
1702 | impl<'a> LetStmt<'a> { | 1241 | impl LetStmt { |
1703 | pub fn pat(self) -> Option<Pat<'a>> { | 1242 | pub fn pat(&self) -> Option<&Pat> { |
1704 | super::child_opt(self) | 1243 | super::child_opt(self) |
1705 | } | 1244 | } |
1706 | 1245 | ||
1707 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1246 | pub fn type_ref(&self) -> Option<&TypeRef> { |
1708 | super::child_opt(self) | 1247 | super::child_opt(self) |
1709 | } | 1248 | } |
1710 | 1249 | ||
1711 | pub fn initializer(self) -> Option<Expr<'a>> { | 1250 | pub fn initializer(&self) -> Option<&Expr> { |
1712 | super::child_opt(self) | 1251 | super::child_opt(self) |
1713 | } | 1252 | } |
1714 | } | 1253 | } |
1715 | 1254 | ||
1716 | // Lifetime | 1255 | // Lifetime |
1717 | #[derive(Debug, Clone, Copy,)] | 1256 | #[derive(Debug, PartialEq, Eq, Hash)] |
1718 | pub struct LifetimeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1257 | #[repr(transparent)] |
1719 | pub(crate) syntax: SyntaxNode<R>, | 1258 | pub struct Lifetime { |
1259 | pub(crate) syntax: SyntaxNode, | ||
1720 | } | 1260 | } |
1721 | pub type Lifetime<'a> = LifetimeNode<RefRoot<'a>>; | 1261 | unsafe impl TransparentNewType for Lifetime { |
1722 | 1262 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1723 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeNode<R1>> for LifetimeNode<R2> { | ||
1724 | fn eq(&self, other: &LifetimeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1725 | } | ||
1726 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeNode<R> {} | ||
1727 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeNode<R> { | ||
1728 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1729 | } | 1263 | } |
1730 | 1264 | ||
1731 | impl<'a> AstNode<'a> for Lifetime<'a> { | 1265 | impl AstNode for Lifetime { |
1732 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1266 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1733 | match syntax.kind() { | 1267 | match syntax.kind() { |
1734 | LIFETIME => Some(Lifetime { syntax }), | 1268 | LIFETIME => Some(Lifetime::from_repr(syntax.into_repr())), |
1735 | _ => None, | 1269 | _ => None, |
1736 | } | 1270 | } |
1737 | } | 1271 | } |
1738 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1272 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1739 | } | 1273 | fn to_owned(&self) -> TreePtr<Lifetime> { TreePtr::cast(self.syntax.to_owned()) } |
1740 | |||
1741 | impl<R: TreeRoot<RaTypes>> LifetimeNode<R> { | ||
1742 | pub fn borrowed(&self) -> Lifetime { | ||
1743 | LifetimeNode { syntax: self.syntax.borrowed() } | ||
1744 | } | ||
1745 | pub fn owned(&self) -> LifetimeNode { | ||
1746 | LifetimeNode { syntax: self.syntax.owned() } | ||
1747 | } | ||
1748 | } | 1274 | } |
1749 | 1275 | ||
1750 | 1276 | ||
1751 | impl<'a> Lifetime<'a> {} | 1277 | impl ast::AstToken for Lifetime {} |
1278 | impl Lifetime {} | ||
1752 | 1279 | ||
1753 | // LifetimeParam | 1280 | // LifetimeParam |
1754 | #[derive(Debug, Clone, Copy,)] | 1281 | #[derive(Debug, PartialEq, Eq, Hash)] |
1755 | pub struct LifetimeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1282 | #[repr(transparent)] |
1756 | pub(crate) syntax: SyntaxNode<R>, | 1283 | pub struct LifetimeParam { |
1757 | } | 1284 | pub(crate) syntax: SyntaxNode, |
1758 | pub type LifetimeParam<'a> = LifetimeParamNode<RefRoot<'a>>; | ||
1759 | |||
1760 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeParamNode<R1>> for LifetimeParamNode<R2> { | ||
1761 | fn eq(&self, other: &LifetimeParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
1762 | } | 1285 | } |
1763 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeParamNode<R> {} | 1286 | unsafe impl TransparentNewType for LifetimeParam { |
1764 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeParamNode<R> { | 1287 | type Repr = rowan::SyntaxNode<RaTypes>; |
1765 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1766 | } | 1288 | } |
1767 | 1289 | ||
1768 | impl<'a> AstNode<'a> for LifetimeParam<'a> { | 1290 | impl AstNode for LifetimeParam { |
1769 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1291 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1770 | match syntax.kind() { | 1292 | match syntax.kind() { |
1771 | LIFETIME_PARAM => Some(LifetimeParam { syntax }), | 1293 | LIFETIME_PARAM => Some(LifetimeParam::from_repr(syntax.into_repr())), |
1772 | _ => None, | 1294 | _ => None, |
1773 | } | 1295 | } |
1774 | } | 1296 | } |
1775 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1297 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1298 | fn to_owned(&self) -> TreePtr<LifetimeParam> { TreePtr::cast(self.syntax.to_owned()) } | ||
1776 | } | 1299 | } |
1777 | 1300 | ||
1778 | impl<R: TreeRoot<RaTypes>> LifetimeParamNode<R> { | ||
1779 | pub fn borrowed(&self) -> LifetimeParam { | ||
1780 | LifetimeParamNode { syntax: self.syntax.borrowed() } | ||
1781 | } | ||
1782 | pub fn owned(&self) -> LifetimeParamNode { | ||
1783 | LifetimeParamNode { syntax: self.syntax.owned() } | ||
1784 | } | ||
1785 | } | ||
1786 | 1301 | ||
1787 | 1302 | impl LifetimeParam { | |
1788 | impl<'a> LifetimeParam<'a> { | 1303 | pub fn lifetime(&self) -> Option<&Lifetime> { |
1789 | pub fn lifetime(self) -> Option<Lifetime<'a>> { | ||
1790 | super::child_opt(self) | 1304 | super::child_opt(self) |
1791 | } | 1305 | } |
1792 | } | 1306 | } |
1793 | 1307 | ||
1794 | // Literal | 1308 | // Literal |
1795 | #[derive(Debug, Clone, Copy,)] | 1309 | #[derive(Debug, PartialEq, Eq, Hash)] |
1796 | pub struct LiteralNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1310 | #[repr(transparent)] |
1797 | pub(crate) syntax: SyntaxNode<R>, | 1311 | pub struct Literal { |
1798 | } | 1312 | pub(crate) syntax: SyntaxNode, |
1799 | pub type Literal<'a> = LiteralNode<RefRoot<'a>>; | ||
1800 | |||
1801 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LiteralNode<R1>> for LiteralNode<R2> { | ||
1802 | fn eq(&self, other: &LiteralNode<R1>) -> bool { self.syntax == other.syntax } | ||
1803 | } | 1313 | } |
1804 | impl<R: TreeRoot<RaTypes>> Eq for LiteralNode<R> {} | 1314 | unsafe impl TransparentNewType for Literal { |
1805 | impl<R: TreeRoot<RaTypes>> Hash for LiteralNode<R> { | 1315 | type Repr = rowan::SyntaxNode<RaTypes>; |
1806 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1807 | } | 1316 | } |
1808 | 1317 | ||
1809 | impl<'a> AstNode<'a> for Literal<'a> { | 1318 | impl AstNode for Literal { |
1810 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1319 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1811 | match syntax.kind() { | 1320 | match syntax.kind() { |
1812 | LITERAL => Some(Literal { syntax }), | 1321 | LITERAL => Some(Literal::from_repr(syntax.into_repr())), |
1813 | _ => None, | 1322 | _ => None, |
1814 | } | 1323 | } |
1815 | } | 1324 | } |
1816 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1325 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1817 | } | 1326 | fn to_owned(&self) -> TreePtr<Literal> { TreePtr::cast(self.syntax.to_owned()) } |
1818 | |||
1819 | impl<R: TreeRoot<RaTypes>> LiteralNode<R> { | ||
1820 | pub fn borrowed(&self) -> Literal { | ||
1821 | LiteralNode { syntax: self.syntax.borrowed() } | ||
1822 | } | ||
1823 | pub fn owned(&self) -> LiteralNode { | ||
1824 | LiteralNode { syntax: self.syntax.owned() } | ||
1825 | } | ||
1826 | } | 1327 | } |
1827 | 1328 | ||
1828 | 1329 | ||
1829 | impl<'a> Literal<'a> {} | 1330 | impl Literal {} |
1830 | 1331 | ||
1831 | // LoopExpr | 1332 | // LoopExpr |
1832 | #[derive(Debug, Clone, Copy,)] | 1333 | #[derive(Debug, PartialEq, Eq, Hash)] |
1833 | pub struct LoopExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1334 | #[repr(transparent)] |
1834 | pub(crate) syntax: SyntaxNode<R>, | 1335 | pub struct LoopExpr { |
1336 | pub(crate) syntax: SyntaxNode, | ||
1835 | } | 1337 | } |
1836 | pub type LoopExpr<'a> = LoopExprNode<RefRoot<'a>>; | 1338 | unsafe impl TransparentNewType for LoopExpr { |
1837 | 1339 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1838 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LoopExprNode<R1>> for LoopExprNode<R2> { | ||
1839 | fn eq(&self, other: &LoopExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1840 | } | ||
1841 | impl<R: TreeRoot<RaTypes>> Eq for LoopExprNode<R> {} | ||
1842 | impl<R: TreeRoot<RaTypes>> Hash for LoopExprNode<R> { | ||
1843 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1844 | } | 1340 | } |
1845 | 1341 | ||
1846 | impl<'a> AstNode<'a> for LoopExpr<'a> { | 1342 | impl AstNode for LoopExpr { |
1847 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1343 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1848 | match syntax.kind() { | 1344 | match syntax.kind() { |
1849 | LOOP_EXPR => Some(LoopExpr { syntax }), | 1345 | LOOP_EXPR => Some(LoopExpr::from_repr(syntax.into_repr())), |
1850 | _ => None, | 1346 | _ => None, |
1851 | } | 1347 | } |
1852 | } | 1348 | } |
1853 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1349 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1854 | } | 1350 | fn to_owned(&self) -> TreePtr<LoopExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1855 | |||
1856 | impl<R: TreeRoot<RaTypes>> LoopExprNode<R> { | ||
1857 | pub fn borrowed(&self) -> LoopExpr { | ||
1858 | LoopExprNode { syntax: self.syntax.borrowed() } | ||
1859 | } | ||
1860 | pub fn owned(&self) -> LoopExprNode { | ||
1861 | LoopExprNode { syntax: self.syntax.owned() } | ||
1862 | } | ||
1863 | } | 1351 | } |
1864 | 1352 | ||
1865 | 1353 | ||
1866 | impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} | 1354 | impl ast::LoopBodyOwner for LoopExpr {} |
1867 | impl<'a> LoopExpr<'a> {} | 1355 | impl LoopExpr {} |
1868 | 1356 | ||
1869 | // MacroCall | 1357 | // MacroCall |
1870 | #[derive(Debug, Clone, Copy,)] | 1358 | #[derive(Debug, PartialEq, Eq, Hash)] |
1871 | pub struct MacroCallNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1359 | #[repr(transparent)] |
1872 | pub(crate) syntax: SyntaxNode<R>, | 1360 | pub struct MacroCall { |
1361 | pub(crate) syntax: SyntaxNode, | ||
1873 | } | 1362 | } |
1874 | pub type MacroCall<'a> = MacroCallNode<RefRoot<'a>>; | 1363 | unsafe impl TransparentNewType for MacroCall { |
1875 | 1364 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1876 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MacroCallNode<R1>> for MacroCallNode<R2> { | ||
1877 | fn eq(&self, other: &MacroCallNode<R1>) -> bool { self.syntax == other.syntax } | ||
1878 | } | ||
1879 | impl<R: TreeRoot<RaTypes>> Eq for MacroCallNode<R> {} | ||
1880 | impl<R: TreeRoot<RaTypes>> Hash for MacroCallNode<R> { | ||
1881 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1882 | } | 1365 | } |
1883 | 1366 | ||
1884 | impl<'a> AstNode<'a> for MacroCall<'a> { | 1367 | impl AstNode for MacroCall { |
1885 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1368 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1886 | match syntax.kind() { | 1369 | match syntax.kind() { |
1887 | MACRO_CALL => Some(MacroCall { syntax }), | 1370 | MACRO_CALL => Some(MacroCall::from_repr(syntax.into_repr())), |
1888 | _ => None, | 1371 | _ => None, |
1889 | } | 1372 | } |
1890 | } | 1373 | } |
1891 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1374 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1892 | } | 1375 | fn to_owned(&self) -> TreePtr<MacroCall> { TreePtr::cast(self.syntax.to_owned()) } |
1893 | |||
1894 | impl<R: TreeRoot<RaTypes>> MacroCallNode<R> { | ||
1895 | pub fn borrowed(&self) -> MacroCall { | ||
1896 | MacroCallNode { syntax: self.syntax.borrowed() } | ||
1897 | } | ||
1898 | pub fn owned(&self) -> MacroCallNode { | ||
1899 | MacroCallNode { syntax: self.syntax.owned() } | ||
1900 | } | ||
1901 | } | 1376 | } |
1902 | 1377 | ||
1903 | 1378 | ||
1904 | impl<'a> MacroCall<'a> { | 1379 | impl MacroCall { |
1905 | pub fn token_tree(self) -> Option<TokenTree<'a>> { | 1380 | pub fn token_tree(&self) -> Option<&TokenTree> { |
1906 | super::child_opt(self) | 1381 | super::child_opt(self) |
1907 | } | 1382 | } |
1908 | 1383 | ||
1909 | pub fn path(self) -> Option<Path<'a>> { | 1384 | pub fn path(&self) -> Option<&Path> { |
1910 | super::child_opt(self) | 1385 | super::child_opt(self) |
1911 | } | 1386 | } |
1912 | } | 1387 | } |
1913 | 1388 | ||
1914 | // MatchArm | 1389 | // MatchArm |
1915 | #[derive(Debug, Clone, Copy,)] | 1390 | #[derive(Debug, PartialEq, Eq, Hash)] |
1916 | pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1391 | #[repr(transparent)] |
1917 | pub(crate) syntax: SyntaxNode<R>, | 1392 | pub struct MatchArm { |
1393 | pub(crate) syntax: SyntaxNode, | ||
1918 | } | 1394 | } |
1919 | pub type MatchArm<'a> = MatchArmNode<RefRoot<'a>>; | 1395 | unsafe impl TransparentNewType for MatchArm { |
1920 | 1396 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1921 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmNode<R1>> for MatchArmNode<R2> { | ||
1922 | fn eq(&self, other: &MatchArmNode<R1>) -> bool { self.syntax == other.syntax } | ||
1923 | } | ||
1924 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmNode<R> {} | ||
1925 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmNode<R> { | ||
1926 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1927 | } | 1397 | } |
1928 | 1398 | ||
1929 | impl<'a> AstNode<'a> for MatchArm<'a> { | 1399 | impl AstNode for MatchArm { |
1930 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1400 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1931 | match syntax.kind() { | 1401 | match syntax.kind() { |
1932 | MATCH_ARM => Some(MatchArm { syntax }), | 1402 | MATCH_ARM => Some(MatchArm::from_repr(syntax.into_repr())), |
1933 | _ => None, | 1403 | _ => None, |
1934 | } | 1404 | } |
1935 | } | 1405 | } |
1936 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1406 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1407 | fn to_owned(&self) -> TreePtr<MatchArm> { TreePtr::cast(self.syntax.to_owned()) } | ||
1937 | } | 1408 | } |
1938 | 1409 | ||
1939 | impl<R: TreeRoot<RaTypes>> MatchArmNode<R> { | ||
1940 | pub fn borrowed(&self) -> MatchArm { | ||
1941 | MatchArmNode { syntax: self.syntax.borrowed() } | ||
1942 | } | ||
1943 | pub fn owned(&self) -> MatchArmNode { | ||
1944 | MatchArmNode { syntax: self.syntax.owned() } | ||
1945 | } | ||
1946 | } | ||
1947 | 1410 | ||
1948 | 1411 | impl MatchArm { | |
1949 | impl<'a> MatchArm<'a> { | 1412 | pub fn pats(&self) -> impl Iterator<Item = &Pat> { |
1950 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { | ||
1951 | super::children(self) | 1413 | super::children(self) |
1952 | } | 1414 | } |
1953 | 1415 | ||
1954 | pub fn guard(self) -> Option<MatchGuard<'a>> { | 1416 | pub fn guard(&self) -> Option<&MatchGuard> { |
1955 | super::child_opt(self) | 1417 | super::child_opt(self) |
1956 | } | 1418 | } |
1957 | 1419 | ||
1958 | pub fn expr(self) -> Option<Expr<'a>> { | 1420 | pub fn expr(&self) -> Option<&Expr> { |
1959 | super::child_opt(self) | 1421 | super::child_opt(self) |
1960 | } | 1422 | } |
1961 | } | 1423 | } |
1962 | 1424 | ||
1963 | // MatchArmList | 1425 | // MatchArmList |
1964 | #[derive(Debug, Clone, Copy,)] | 1426 | #[derive(Debug, PartialEq, Eq, Hash)] |
1965 | pub struct MatchArmListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1427 | #[repr(transparent)] |
1966 | pub(crate) syntax: SyntaxNode<R>, | 1428 | pub struct MatchArmList { |
1967 | } | 1429 | pub(crate) syntax: SyntaxNode, |
1968 | pub type MatchArmList<'a> = MatchArmListNode<RefRoot<'a>>; | ||
1969 | |||
1970 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmListNode<R1>> for MatchArmListNode<R2> { | ||
1971 | fn eq(&self, other: &MatchArmListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1972 | } | 1430 | } |
1973 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmListNode<R> {} | 1431 | unsafe impl TransparentNewType for MatchArmList { |
1974 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmListNode<R> { | 1432 | type Repr = rowan::SyntaxNode<RaTypes>; |
1975 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1976 | } | 1433 | } |
1977 | 1434 | ||
1978 | impl<'a> AstNode<'a> for MatchArmList<'a> { | 1435 | impl AstNode for MatchArmList { |
1979 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1436 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1980 | match syntax.kind() { | 1437 | match syntax.kind() { |
1981 | MATCH_ARM_LIST => Some(MatchArmList { syntax }), | 1438 | MATCH_ARM_LIST => Some(MatchArmList::from_repr(syntax.into_repr())), |
1982 | _ => None, | 1439 | _ => None, |
1983 | } | 1440 | } |
1984 | } | 1441 | } |
1985 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1442 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1443 | fn to_owned(&self) -> TreePtr<MatchArmList> { TreePtr::cast(self.syntax.to_owned()) } | ||
1986 | } | 1444 | } |
1987 | 1445 | ||
1988 | impl<R: TreeRoot<RaTypes>> MatchArmListNode<R> { | ||
1989 | pub fn borrowed(&self) -> MatchArmList { | ||
1990 | MatchArmListNode { syntax: self.syntax.borrowed() } | ||
1991 | } | ||
1992 | pub fn owned(&self) -> MatchArmListNode { | ||
1993 | MatchArmListNode { syntax: self.syntax.owned() } | ||
1994 | } | ||
1995 | } | ||
1996 | 1446 | ||
1997 | 1447 | impl MatchArmList { | |
1998 | impl<'a> MatchArmList<'a> { | 1448 | pub fn arms(&self) -> impl Iterator<Item = &MatchArm> { |
1999 | pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a { | ||
2000 | super::children(self) | 1449 | super::children(self) |
2001 | } | 1450 | } |
2002 | } | 1451 | } |
2003 | 1452 | ||
2004 | // MatchExpr | 1453 | // MatchExpr |
2005 | #[derive(Debug, Clone, Copy,)] | 1454 | #[derive(Debug, PartialEq, Eq, Hash)] |
2006 | pub struct MatchExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1455 | #[repr(transparent)] |
2007 | pub(crate) syntax: SyntaxNode<R>, | 1456 | pub struct MatchExpr { |
2008 | } | 1457 | pub(crate) syntax: SyntaxNode, |
2009 | pub type MatchExpr<'a> = MatchExprNode<RefRoot<'a>>; | ||
2010 | |||
2011 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchExprNode<R1>> for MatchExprNode<R2> { | ||
2012 | fn eq(&self, other: &MatchExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2013 | } | 1458 | } |
2014 | impl<R: TreeRoot<RaTypes>> Eq for MatchExprNode<R> {} | 1459 | unsafe impl TransparentNewType for MatchExpr { |
2015 | impl<R: TreeRoot<RaTypes>> Hash for MatchExprNode<R> { | 1460 | type Repr = rowan::SyntaxNode<RaTypes>; |
2016 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2017 | } | 1461 | } |
2018 | 1462 | ||
2019 | impl<'a> AstNode<'a> for MatchExpr<'a> { | 1463 | impl AstNode for MatchExpr { |
2020 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1464 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2021 | match syntax.kind() { | 1465 | match syntax.kind() { |
2022 | MATCH_EXPR => Some(MatchExpr { syntax }), | 1466 | MATCH_EXPR => Some(MatchExpr::from_repr(syntax.into_repr())), |
2023 | _ => None, | 1467 | _ => None, |
2024 | } | 1468 | } |
2025 | } | 1469 | } |
2026 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1470 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2027 | } | 1471 | fn to_owned(&self) -> TreePtr<MatchExpr> { TreePtr::cast(self.syntax.to_owned()) } |
2028 | |||
2029 | impl<R: TreeRoot<RaTypes>> MatchExprNode<R> { | ||
2030 | pub fn borrowed(&self) -> MatchExpr { | ||
2031 | MatchExprNode { syntax: self.syntax.borrowed() } | ||
2032 | } | ||
2033 | pub fn owned(&self) -> MatchExprNode { | ||
2034 | MatchExprNode { syntax: self.syntax.owned() } | ||
2035 | } | ||
2036 | } | 1472 | } |
2037 | 1473 | ||
2038 | 1474 | ||
2039 | impl<'a> MatchExpr<'a> { | 1475 | impl MatchExpr { |
2040 | pub fn expr(self) -> Option<Expr<'a>> { | 1476 | pub fn expr(&self) -> Option<&Expr> { |
2041 | super::child_opt(self) | 1477 | super::child_opt(self) |
2042 | } | 1478 | } |
2043 | 1479 | ||
2044 | pub fn match_arm_list(self) -> Option<MatchArmList<'a>> { | 1480 | pub fn match_arm_list(&self) -> Option<&MatchArmList> { |
2045 | super::child_opt(self) | 1481 | super::child_opt(self) |
2046 | } | 1482 | } |
2047 | } | 1483 | } |
2048 | 1484 | ||
2049 | // MatchGuard | 1485 | // MatchGuard |
2050 | #[derive(Debug, Clone, Copy,)] | 1486 | #[derive(Debug, PartialEq, Eq, Hash)] |
2051 | pub struct MatchGuardNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1487 | #[repr(transparent)] |
2052 | pub(crate) syntax: SyntaxNode<R>, | 1488 | pub struct MatchGuard { |
1489 | pub(crate) syntax: SyntaxNode, | ||
2053 | } | 1490 | } |
2054 | pub type MatchGuard<'a> = MatchGuardNode<RefRoot<'a>>; | 1491 | unsafe impl TransparentNewType for MatchGuard { |
2055 | 1492 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2056 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchGuardNode<R1>> for MatchGuardNode<R2> { | ||
2057 | fn eq(&self, other: &MatchGuardNode<R1>) -> bool { self.syntax == other.syntax } | ||
2058 | } | ||
2059 | impl<R: TreeRoot<RaTypes>> Eq for MatchGuardNode<R> {} | ||
2060 | impl<R: TreeRoot<RaTypes>> Hash for MatchGuardNode<R> { | ||
2061 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2062 | } | 1493 | } |
2063 | 1494 | ||
2064 | impl<'a> AstNode<'a> for MatchGuard<'a> { | 1495 | impl AstNode for MatchGuard { |
2065 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1496 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2066 | match syntax.kind() { | 1497 | match syntax.kind() { |
2067 | MATCH_GUARD => Some(MatchGuard { syntax }), | 1498 | MATCH_GUARD => Some(MatchGuard::from_repr(syntax.into_repr())), |
2068 | _ => None, | 1499 | _ => None, |
2069 | } | 1500 | } |
2070 | } | 1501 | } |
2071 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1502 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2072 | } | 1503 | fn to_owned(&self) -> TreePtr<MatchGuard> { TreePtr::cast(self.syntax.to_owned()) } |
2073 | |||
2074 | impl<R: TreeRoot<RaTypes>> MatchGuardNode<R> { | ||
2075 | pub fn borrowed(&self) -> MatchGuard { | ||
2076 | MatchGuardNode { syntax: self.syntax.borrowed() } | ||
2077 | } | ||
2078 | pub fn owned(&self) -> MatchGuardNode { | ||
2079 | MatchGuardNode { syntax: self.syntax.owned() } | ||
2080 | } | ||
2081 | } | 1504 | } |
2082 | 1505 | ||
2083 | 1506 | ||
2084 | impl<'a> MatchGuard<'a> {} | 1507 | impl MatchGuard {} |
2085 | 1508 | ||
2086 | // MethodCallExpr | 1509 | // MethodCallExpr |
2087 | #[derive(Debug, Clone, Copy,)] | 1510 | #[derive(Debug, PartialEq, Eq, Hash)] |
2088 | pub struct MethodCallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1511 | #[repr(transparent)] |
2089 | pub(crate) syntax: SyntaxNode<R>, | 1512 | pub struct MethodCallExpr { |
2090 | } | 1513 | pub(crate) syntax: SyntaxNode, |
2091 | pub type MethodCallExpr<'a> = MethodCallExprNode<RefRoot<'a>>; | ||
2092 | |||
2093 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MethodCallExprNode<R1>> for MethodCallExprNode<R2> { | ||
2094 | fn eq(&self, other: &MethodCallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2095 | } | 1514 | } |
2096 | impl<R: TreeRoot<RaTypes>> Eq for MethodCallExprNode<R> {} | 1515 | unsafe impl TransparentNewType for MethodCallExpr { |
2097 | impl<R: TreeRoot<RaTypes>> Hash for MethodCallExprNode<R> { | 1516 | type Repr = rowan::SyntaxNode<RaTypes>; |
2098 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2099 | } | 1517 | } |
2100 | 1518 | ||
2101 | impl<'a> AstNode<'a> for MethodCallExpr<'a> { | 1519 | impl AstNode for MethodCallExpr { |
2102 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1520 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2103 | match syntax.kind() { | 1521 | match syntax.kind() { |
2104 | METHOD_CALL_EXPR => Some(MethodCallExpr { syntax }), | 1522 | METHOD_CALL_EXPR => Some(MethodCallExpr::from_repr(syntax.into_repr())), |
2105 | _ => None, | 1523 | _ => None, |
2106 | } | 1524 | } |
2107 | } | 1525 | } |
2108 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1526 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1527 | fn to_owned(&self) -> TreePtr<MethodCallExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
2109 | } | 1528 | } |
2110 | 1529 | ||
2111 | impl<R: TreeRoot<RaTypes>> MethodCallExprNode<R> { | ||
2112 | pub fn borrowed(&self) -> MethodCallExpr { | ||
2113 | MethodCallExprNode { syntax: self.syntax.borrowed() } | ||
2114 | } | ||
2115 | pub fn owned(&self) -> MethodCallExprNode { | ||
2116 | MethodCallExprNode { syntax: self.syntax.owned() } | ||
2117 | } | ||
2118 | } | ||
2119 | 1530 | ||
2120 | 1531 | impl ast::ArgListOwner for MethodCallExpr {} | |
2121 | impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} | 1532 | impl MethodCallExpr { |
2122 | impl<'a> MethodCallExpr<'a> { | 1533 | pub fn expr(&self) -> Option<&Expr> { |
2123 | pub fn expr(self) -> Option<Expr<'a>> { | ||
2124 | super::child_opt(self) | 1534 | super::child_opt(self) |
2125 | } | 1535 | } |
2126 | 1536 | ||
2127 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 1537 | pub fn name_ref(&self) -> Option<&NameRef> { |
2128 | super::child_opt(self) | 1538 | super::child_opt(self) |
2129 | } | 1539 | } |
2130 | } | 1540 | } |
2131 | 1541 | ||
2132 | // Module | 1542 | // Module |
2133 | #[derive(Debug, Clone, Copy,)] | 1543 | #[derive(Debug, PartialEq, Eq, Hash)] |
2134 | pub struct ModuleNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1544 | #[repr(transparent)] |
2135 | pub(crate) syntax: SyntaxNode<R>, | 1545 | pub struct Module { |
2136 | } | 1546 | pub(crate) syntax: SyntaxNode, |
2137 | pub type Module<'a> = ModuleNode<RefRoot<'a>>; | ||
2138 | |||
2139 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ModuleNode<R1>> for ModuleNode<R2> { | ||
2140 | fn eq(&self, other: &ModuleNode<R1>) -> bool { self.syntax == other.syntax } | ||
2141 | } | 1547 | } |
2142 | impl<R: TreeRoot<RaTypes>> Eq for ModuleNode<R> {} | 1548 | unsafe impl TransparentNewType for Module { |
2143 | impl<R: TreeRoot<RaTypes>> Hash for ModuleNode<R> { | 1549 | type Repr = rowan::SyntaxNode<RaTypes>; |
2144 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2145 | } | 1550 | } |
2146 | 1551 | ||
2147 | impl<'a> AstNode<'a> for Module<'a> { | 1552 | impl AstNode for Module { |
2148 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1553 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2149 | match syntax.kind() { | 1554 | match syntax.kind() { |
2150 | MODULE => Some(Module { syntax }), | 1555 | MODULE => Some(Module::from_repr(syntax.into_repr())), |
2151 | _ => None, | 1556 | _ => None, |
2152 | } | 1557 | } |
2153 | } | 1558 | } |
2154 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1559 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1560 | fn to_owned(&self) -> TreePtr<Module> { TreePtr::cast(self.syntax.to_owned()) } | ||
2155 | } | 1561 | } |
2156 | 1562 | ||
2157 | impl<R: TreeRoot<RaTypes>> ModuleNode<R> { | ||
2158 | pub fn borrowed(&self) -> Module { | ||
2159 | ModuleNode { syntax: self.syntax.borrowed() } | ||
2160 | } | ||
2161 | pub fn owned(&self) -> ModuleNode { | ||
2162 | ModuleNode { syntax: self.syntax.owned() } | ||
2163 | } | ||
2164 | } | ||
2165 | 1563 | ||
2166 | 1564 | impl ast::VisibilityOwner for Module {} | |
2167 | impl<'a> ast::VisibilityOwner<'a> for Module<'a> {} | 1565 | impl ast::NameOwner for Module {} |
2168 | impl<'a> ast::NameOwner<'a> for Module<'a> {} | 1566 | impl ast::AttrsOwner for Module {} |
2169 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} | 1567 | impl ast::DocCommentsOwner for Module {} |
2170 | impl<'a> ast::DocCommentsOwner<'a> for Module<'a> {} | 1568 | impl Module { |
2171 | impl<'a> Module<'a> { | 1569 | pub fn item_list(&self) -> Option<&ItemList> { |
2172 | pub fn item_list(self) -> Option<ItemList<'a>> { | ||
2173 | super::child_opt(self) | 1570 | super::child_opt(self) |
2174 | } | 1571 | } |
2175 | } | 1572 | } |
2176 | 1573 | ||
2177 | // ModuleItem | 1574 | // ModuleItem |
2178 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1575 | #[derive(Debug, PartialEq, Eq, Hash)] |
2179 | pub enum ModuleItem<'a> { | 1576 | #[repr(transparent)] |
2180 | StructDef(StructDef<'a>), | 1577 | pub struct ModuleItem { |
2181 | EnumDef(EnumDef<'a>), | 1578 | pub(crate) syntax: SyntaxNode, |
2182 | FnDef(FnDef<'a>), | 1579 | } |
2183 | TraitDef(TraitDef<'a>), | 1580 | unsafe impl TransparentNewType for ModuleItem { |
2184 | TypeDef(TypeDef<'a>), | 1581 | type Repr = rowan::SyntaxNode<RaTypes>; |
2185 | ImplBlock(ImplBlock<'a>), | ||
2186 | UseItem(UseItem<'a>), | ||
2187 | ExternCrateItem(ExternCrateItem<'a>), | ||
2188 | ConstDef(ConstDef<'a>), | ||
2189 | StaticDef(StaticDef<'a>), | ||
2190 | Module(Module<'a>), | ||
2191 | } | ||
2192 | |||
2193 | impl<'a> AstNode<'a> for ModuleItem<'a> { | ||
2194 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
2195 | match syntax.kind() { | ||
2196 | STRUCT_DEF => Some(ModuleItem::StructDef(StructDef { syntax })), | ||
2197 | ENUM_DEF => Some(ModuleItem::EnumDef(EnumDef { syntax })), | ||
2198 | FN_DEF => Some(ModuleItem::FnDef(FnDef { syntax })), | ||
2199 | TRAIT_DEF => Some(ModuleItem::TraitDef(TraitDef { syntax })), | ||
2200 | TYPE_DEF => Some(ModuleItem::TypeDef(TypeDef { syntax })), | ||
2201 | IMPL_BLOCK => Some(ModuleItem::ImplBlock(ImplBlock { syntax })), | ||
2202 | USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })), | ||
2203 | EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })), | ||
2204 | CONST_DEF => Some(ModuleItem::ConstDef(ConstDef { syntax })), | ||
2205 | STATIC_DEF => Some(ModuleItem::StaticDef(StaticDef { syntax })), | ||
2206 | MODULE => Some(ModuleItem::Module(Module { syntax })), | ||
2207 | _ => None, | ||
2208 | } | ||
2209 | } | ||
2210 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
2211 | match self { | ||
2212 | ModuleItem::StructDef(inner) => inner.syntax(), | ||
2213 | ModuleItem::EnumDef(inner) => inner.syntax(), | ||
2214 | ModuleItem::FnDef(inner) => inner.syntax(), | ||
2215 | ModuleItem::TraitDef(inner) => inner.syntax(), | ||
2216 | ModuleItem::TypeDef(inner) => inner.syntax(), | ||
2217 | ModuleItem::ImplBlock(inner) => inner.syntax(), | ||
2218 | ModuleItem::UseItem(inner) => inner.syntax(), | ||
2219 | ModuleItem::ExternCrateItem(inner) => inner.syntax(), | ||
2220 | ModuleItem::ConstDef(inner) => inner.syntax(), | ||
2221 | ModuleItem::StaticDef(inner) => inner.syntax(), | ||
2222 | ModuleItem::Module(inner) => inner.syntax(), | ||
2223 | } | ||
2224 | } | ||
2225 | } | 1582 | } |
2226 | 1583 | ||
2227 | impl<'a> ModuleItem<'a> {} | 1584 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1585 | pub enum ModuleItemKind<'a> { | ||
1586 | StructDef(&'a StructDef), | ||
1587 | EnumDef(&'a EnumDef), | ||
1588 | FnDef(&'a FnDef), | ||
1589 | TraitDef(&'a TraitDef), | ||
1590 | TypeDef(&'a TypeDef), | ||
1591 | ImplBlock(&'a ImplBlock), | ||
1592 | UseItem(&'a UseItem), | ||
1593 | ExternCrateItem(&'a ExternCrateItem), | ||
1594 | ConstDef(&'a ConstDef), | ||
1595 | StaticDef(&'a StaticDef), | ||
1596 | Module(&'a Module), | ||
1597 | } | ||
1598 | |||
1599 | impl AstNode for ModuleItem { | ||
1600 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
1601 | match syntax.kind() { | ||
1602 | | STRUCT_DEF | ||
1603 | | ENUM_DEF | ||
1604 | | FN_DEF | ||
1605 | | TRAIT_DEF | ||
1606 | | TYPE_DEF | ||
1607 | | IMPL_BLOCK | ||
1608 | | USE_ITEM | ||
1609 | | EXTERN_CRATE_ITEM | ||
1610 | | CONST_DEF | ||
1611 | | STATIC_DEF | ||
1612 | | MODULE => Some(ModuleItem::from_repr(syntax.into_repr())), | ||
1613 | _ => None, | ||
1614 | } | ||
1615 | } | ||
1616 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1617 | fn to_owned(&self) -> TreePtr<ModuleItem> { TreePtr::cast(self.syntax.to_owned()) } | ||
1618 | } | ||
1619 | |||
1620 | impl ModuleItem { | ||
1621 | pub fn kind(&self) -> ModuleItemKind { | ||
1622 | match self.syntax.kind() { | ||
1623 | STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(&self.syntax).unwrap()), | ||
1624 | ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()), | ||
1625 | FN_DEF => ModuleItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), | ||
1626 | TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(&self.syntax).unwrap()), | ||
1627 | TYPE_DEF => ModuleItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), | ||
1628 | IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(&self.syntax).unwrap()), | ||
1629 | USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(&self.syntax).unwrap()), | ||
1630 | EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(&self.syntax).unwrap()), | ||
1631 | CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), | ||
1632 | STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(&self.syntax).unwrap()), | ||
1633 | MODULE => ModuleItemKind::Module(Module::cast(&self.syntax).unwrap()), | ||
1634 | _ => unreachable!(), | ||
1635 | } | ||
1636 | } | ||
1637 | } | ||
1638 | |||
1639 | impl ModuleItem {} | ||
2228 | 1640 | ||
2229 | // Name | 1641 | // Name |
2230 | #[derive(Debug, Clone, Copy,)] | 1642 | #[derive(Debug, PartialEq, Eq, Hash)] |
2231 | pub struct NameNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1643 | #[repr(transparent)] |
2232 | pub(crate) syntax: SyntaxNode<R>, | 1644 | pub struct Name { |
2233 | } | 1645 | pub(crate) syntax: SyntaxNode, |
2234 | pub type Name<'a> = NameNode<RefRoot<'a>>; | ||
2235 | |||
2236 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameNode<R1>> for NameNode<R2> { | ||
2237 | fn eq(&self, other: &NameNode<R1>) -> bool { self.syntax == other.syntax } | ||
2238 | } | 1646 | } |
2239 | impl<R: TreeRoot<RaTypes>> Eq for NameNode<R> {} | 1647 | unsafe impl TransparentNewType for Name { |
2240 | impl<R: TreeRoot<RaTypes>> Hash for NameNode<R> { | 1648 | type Repr = rowan::SyntaxNode<RaTypes>; |
2241 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2242 | } | 1649 | } |
2243 | 1650 | ||
2244 | impl<'a> AstNode<'a> for Name<'a> { | 1651 | impl AstNode for Name { |
2245 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1652 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2246 | match syntax.kind() { | 1653 | match syntax.kind() { |
2247 | NAME => Some(Name { syntax }), | 1654 | NAME => Some(Name::from_repr(syntax.into_repr())), |
2248 | _ => None, | 1655 | _ => None, |
2249 | } | 1656 | } |
2250 | } | 1657 | } |
2251 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1658 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1659 | fn to_owned(&self) -> TreePtr<Name> { TreePtr::cast(self.syntax.to_owned()) } | ||
2252 | } | 1660 | } |
2253 | 1661 | ||
2254 | impl<R: TreeRoot<RaTypes>> NameNode<R> { | ||
2255 | pub fn borrowed(&self) -> Name { | ||
2256 | NameNode { syntax: self.syntax.borrowed() } | ||
2257 | } | ||
2258 | pub fn owned(&self) -> NameNode { | ||
2259 | NameNode { syntax: self.syntax.owned() } | ||
2260 | } | ||
2261 | } | ||
2262 | 1662 | ||
2263 | 1663 | impl Name {} | |
2264 | impl<'a> Name<'a> {} | ||
2265 | 1664 | ||
2266 | // NameRef | 1665 | // NameRef |
2267 | #[derive(Debug, Clone, Copy,)] | 1666 | #[derive(Debug, PartialEq, Eq, Hash)] |
2268 | pub struct NameRefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1667 | #[repr(transparent)] |
2269 | pub(crate) syntax: SyntaxNode<R>, | 1668 | pub struct NameRef { |
2270 | } | 1669 | pub(crate) syntax: SyntaxNode, |
2271 | pub type NameRef<'a> = NameRefNode<RefRoot<'a>>; | ||
2272 | |||
2273 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameRefNode<R1>> for NameRefNode<R2> { | ||
2274 | fn eq(&self, other: &NameRefNode<R1>) -> bool { self.syntax == other.syntax } | ||
2275 | } | 1670 | } |
2276 | impl<R: TreeRoot<RaTypes>> Eq for NameRefNode<R> {} | 1671 | unsafe impl TransparentNewType for NameRef { |
2277 | impl<R: TreeRoot<RaTypes>> Hash for NameRefNode<R> { | 1672 | type Repr = rowan::SyntaxNode<RaTypes>; |
2278 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2279 | } | 1673 | } |
2280 | 1674 | ||
2281 | impl<'a> AstNode<'a> for NameRef<'a> { | 1675 | impl AstNode for NameRef { |
2282 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1676 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2283 | match syntax.kind() { | 1677 | match syntax.kind() { |
2284 | NAME_REF => Some(NameRef { syntax }), | 1678 | NAME_REF => Some(NameRef::from_repr(syntax.into_repr())), |
2285 | _ => None, | 1679 | _ => None, |
2286 | } | 1680 | } |
2287 | } | 1681 | } |
2288 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1682 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1683 | fn to_owned(&self) -> TreePtr<NameRef> { TreePtr::cast(self.syntax.to_owned()) } | ||
2289 | } | 1684 | } |
2290 | 1685 | ||
2291 | impl<R: TreeRoot<RaTypes>> NameRefNode<R> { | ||
2292 | pub fn borrowed(&self) -> NameRef { | ||
2293 | NameRefNode { syntax: self.syntax.borrowed() } | ||
2294 | } | ||
2295 | pub fn owned(&self) -> NameRefNode { | ||
2296 | NameRefNode { syntax: self.syntax.owned() } | ||
2297 | } | ||
2298 | } | ||
2299 | 1686 | ||
2300 | 1687 | impl NameRef {} | |
2301 | impl<'a> NameRef<'a> {} | ||
2302 | 1688 | ||
2303 | // NamedField | 1689 | // NamedField |
2304 | #[derive(Debug, Clone, Copy,)] | 1690 | #[derive(Debug, PartialEq, Eq, Hash)] |
2305 | pub struct NamedFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1691 | #[repr(transparent)] |
2306 | pub(crate) syntax: SyntaxNode<R>, | 1692 | pub struct NamedField { |
1693 | pub(crate) syntax: SyntaxNode, | ||
2307 | } | 1694 | } |
2308 | pub type NamedField<'a> = NamedFieldNode<RefRoot<'a>>; | 1695 | unsafe impl TransparentNewType for NamedField { |
2309 | 1696 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2310 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldNode<R1>> for NamedFieldNode<R2> { | ||
2311 | fn eq(&self, other: &NamedFieldNode<R1>) -> bool { self.syntax == other.syntax } | ||
2312 | } | ||
2313 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldNode<R> {} | ||
2314 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldNode<R> { | ||
2315 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2316 | } | 1697 | } |
2317 | 1698 | ||
2318 | impl<'a> AstNode<'a> for NamedField<'a> { | 1699 | impl AstNode for NamedField { |
2319 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1700 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2320 | match syntax.kind() { | 1701 | match syntax.kind() { |
2321 | NAMED_FIELD => Some(NamedField { syntax }), | 1702 | NAMED_FIELD => Some(NamedField::from_repr(syntax.into_repr())), |
2322 | _ => None, | 1703 | _ => None, |
2323 | } | 1704 | } |
2324 | } | 1705 | } |
2325 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1706 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2326 | } | 1707 | fn to_owned(&self) -> TreePtr<NamedField> { TreePtr::cast(self.syntax.to_owned()) } |
2327 | |||
2328 | impl<R: TreeRoot<RaTypes>> NamedFieldNode<R> { | ||
2329 | pub fn borrowed(&self) -> NamedField { | ||
2330 | NamedFieldNode { syntax: self.syntax.borrowed() } | ||
2331 | } | ||
2332 | pub fn owned(&self) -> NamedFieldNode { | ||
2333 | NamedFieldNode { syntax: self.syntax.owned() } | ||
2334 | } | ||
2335 | } | 1708 | } |
2336 | 1709 | ||
2337 | 1710 | ||
2338 | impl<'a> NamedField<'a> { | 1711 | impl NamedField { |
2339 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 1712 | pub fn name_ref(&self) -> Option<&NameRef> { |
2340 | super::child_opt(self) | 1713 | super::child_opt(self) |
2341 | } | 1714 | } |
2342 | 1715 | ||
2343 | pub fn expr(self) -> Option<Expr<'a>> { | 1716 | pub fn expr(&self) -> Option<&Expr> { |
2344 | super::child_opt(self) | 1717 | super::child_opt(self) |
2345 | } | 1718 | } |
2346 | } | 1719 | } |
2347 | 1720 | ||
2348 | // NamedFieldDef | 1721 | // NamedFieldDef |
2349 | #[derive(Debug, Clone, Copy,)] | 1722 | #[derive(Debug, PartialEq, Eq, Hash)] |
2350 | pub struct NamedFieldDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1723 | #[repr(transparent)] |
2351 | pub(crate) syntax: SyntaxNode<R>, | 1724 | pub struct NamedFieldDef { |
1725 | pub(crate) syntax: SyntaxNode, | ||
2352 | } | 1726 | } |
2353 | pub type NamedFieldDef<'a> = NamedFieldDefNode<RefRoot<'a>>; | 1727 | unsafe impl TransparentNewType for NamedFieldDef { |
2354 | 1728 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2355 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefNode<R1>> for NamedFieldDefNode<R2> { | ||
2356 | fn eq(&self, other: &NamedFieldDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
2357 | } | ||
2358 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefNode<R> {} | ||
2359 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefNode<R> { | ||
2360 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2361 | } | 1729 | } |
2362 | 1730 | ||
2363 | impl<'a> AstNode<'a> for NamedFieldDef<'a> { | 1731 | impl AstNode for NamedFieldDef { |
2364 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1732 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2365 | match syntax.kind() { | 1733 | match syntax.kind() { |
2366 | NAMED_FIELD_DEF => Some(NamedFieldDef { syntax }), | 1734 | NAMED_FIELD_DEF => Some(NamedFieldDef::from_repr(syntax.into_repr())), |
2367 | _ => None, | 1735 | _ => None, |
2368 | } | 1736 | } |
2369 | } | 1737 | } |
2370 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1738 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1739 | fn to_owned(&self) -> TreePtr<NamedFieldDef> { TreePtr::cast(self.syntax.to_owned()) } | ||
2371 | } | 1740 | } |
2372 | 1741 | ||
2373 | impl<R: TreeRoot<RaTypes>> NamedFieldDefNode<R> { | ||
2374 | pub fn borrowed(&self) -> NamedFieldDef { | ||
2375 | NamedFieldDefNode { syntax: self.syntax.borrowed() } | ||
2376 | } | ||
2377 | pub fn owned(&self) -> NamedFieldDefNode { | ||
2378 | NamedFieldDefNode { syntax: self.syntax.owned() } | ||
2379 | } | ||
2380 | } | ||
2381 | 1742 | ||
2382 | 1743 | impl ast::VisibilityOwner for NamedFieldDef {} | |
2383 | impl<'a> ast::VisibilityOwner<'a> for NamedFieldDef<'a> {} | 1744 | impl ast::NameOwner for NamedFieldDef {} |
2384 | impl<'a> ast::NameOwner<'a> for NamedFieldDef<'a> {} | 1745 | impl ast::AttrsOwner for NamedFieldDef {} |
2385 | impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {} | 1746 | impl NamedFieldDef { |
2386 | impl<'a> NamedFieldDef<'a> { | 1747 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2387 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
2388 | super::child_opt(self) | 1748 | super::child_opt(self) |
2389 | } | 1749 | } |
2390 | } | 1750 | } |
2391 | 1751 | ||
2392 | // NamedFieldDefList | 1752 | // NamedFieldDefList |
2393 | #[derive(Debug, Clone, Copy,)] | 1753 | #[derive(Debug, PartialEq, Eq, Hash)] |
2394 | pub struct NamedFieldDefListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1754 | #[repr(transparent)] |
2395 | pub(crate) syntax: SyntaxNode<R>, | 1755 | pub struct NamedFieldDefList { |
2396 | } | 1756 | pub(crate) syntax: SyntaxNode, |
2397 | pub type NamedFieldDefList<'a> = NamedFieldDefListNode<RefRoot<'a>>; | ||
2398 | |||
2399 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefListNode<R1>> for NamedFieldDefListNode<R2> { | ||
2400 | fn eq(&self, other: &NamedFieldDefListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2401 | } | 1757 | } |
2402 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefListNode<R> {} | 1758 | unsafe impl TransparentNewType for NamedFieldDefList { |
2403 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefListNode<R> { | 1759 | type Repr = rowan::SyntaxNode<RaTypes>; |
2404 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2405 | } | 1760 | } |
2406 | 1761 | ||
2407 | impl<'a> AstNode<'a> for NamedFieldDefList<'a> { | 1762 | impl AstNode for NamedFieldDefList { |
2408 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1763 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2409 | match syntax.kind() { | 1764 | match syntax.kind() { |
2410 | NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList { syntax }), | 1765 | NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList::from_repr(syntax.into_repr())), |
2411 | _ => None, | 1766 | _ => None, |
2412 | } | 1767 | } |
2413 | } | 1768 | } |
2414 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1769 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1770 | fn to_owned(&self) -> TreePtr<NamedFieldDefList> { TreePtr::cast(self.syntax.to_owned()) } | ||
2415 | } | 1771 | } |
2416 | 1772 | ||
2417 | impl<R: TreeRoot<RaTypes>> NamedFieldDefListNode<R> { | ||
2418 | pub fn borrowed(&self) -> NamedFieldDefList { | ||
2419 | NamedFieldDefListNode { syntax: self.syntax.borrowed() } | ||
2420 | } | ||
2421 | pub fn owned(&self) -> NamedFieldDefListNode { | ||
2422 | NamedFieldDefListNode { syntax: self.syntax.owned() } | ||
2423 | } | ||
2424 | } | ||
2425 | 1773 | ||
2426 | 1774 | impl NamedFieldDefList { | |
2427 | impl<'a> NamedFieldDefList<'a> { | 1775 | pub fn fields(&self) -> impl Iterator<Item = &NamedFieldDef> { |
2428 | pub fn fields(self) -> impl Iterator<Item = NamedFieldDef<'a>> + 'a { | ||
2429 | super::children(self) | 1776 | super::children(self) |
2430 | } | 1777 | } |
2431 | } | 1778 | } |
2432 | 1779 | ||
2433 | // NamedFieldList | 1780 | // NamedFieldList |
2434 | #[derive(Debug, Clone, Copy,)] | 1781 | #[derive(Debug, PartialEq, Eq, Hash)] |
2435 | pub struct NamedFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1782 | #[repr(transparent)] |
2436 | pub(crate) syntax: SyntaxNode<R>, | 1783 | pub struct NamedFieldList { |
2437 | } | 1784 | pub(crate) syntax: SyntaxNode, |
2438 | pub type NamedFieldList<'a> = NamedFieldListNode<RefRoot<'a>>; | ||
2439 | |||
2440 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldListNode<R1>> for NamedFieldListNode<R2> { | ||
2441 | fn eq(&self, other: &NamedFieldListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2442 | } | 1785 | } |
2443 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldListNode<R> {} | 1786 | unsafe impl TransparentNewType for NamedFieldList { |
2444 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldListNode<R> { | 1787 | type Repr = rowan::SyntaxNode<RaTypes>; |
2445 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2446 | } | 1788 | } |
2447 | 1789 | ||
2448 | impl<'a> AstNode<'a> for NamedFieldList<'a> { | 1790 | impl AstNode for NamedFieldList { |
2449 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1791 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2450 | match syntax.kind() { | 1792 | match syntax.kind() { |
2451 | NAMED_FIELD_LIST => Some(NamedFieldList { syntax }), | 1793 | NAMED_FIELD_LIST => Some(NamedFieldList::from_repr(syntax.into_repr())), |
2452 | _ => None, | 1794 | _ => None, |
2453 | } | 1795 | } |
2454 | } | 1796 | } |
2455 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1797 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2456 | } | 1798 | fn to_owned(&self) -> TreePtr<NamedFieldList> { TreePtr::cast(self.syntax.to_owned()) } |
2457 | |||
2458 | impl<R: TreeRoot<RaTypes>> NamedFieldListNode<R> { | ||
2459 | pub fn borrowed(&self) -> NamedFieldList { | ||
2460 | NamedFieldListNode { syntax: self.syntax.borrowed() } | ||
2461 | } | ||
2462 | pub fn owned(&self) -> NamedFieldListNode { | ||
2463 | NamedFieldListNode { syntax: self.syntax.owned() } | ||
2464 | } | ||
2465 | } | 1799 | } |
2466 | 1800 | ||
2467 | 1801 | ||
2468 | impl<'a> NamedFieldList<'a> { | 1802 | impl NamedFieldList { |
2469 | pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a { | 1803 | pub fn fields(&self) -> impl Iterator<Item = &NamedField> { |
2470 | super::children(self) | 1804 | super::children(self) |
2471 | } | 1805 | } |
2472 | } | 1806 | } |
2473 | 1807 | ||
2474 | // NeverType | 1808 | // NeverType |
2475 | #[derive(Debug, Clone, Copy,)] | 1809 | #[derive(Debug, PartialEq, Eq, Hash)] |
2476 | pub struct NeverTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1810 | #[repr(transparent)] |
2477 | pub(crate) syntax: SyntaxNode<R>, | 1811 | pub struct NeverType { |
2478 | } | 1812 | pub(crate) syntax: SyntaxNode, |
2479 | pub type NeverType<'a> = NeverTypeNode<RefRoot<'a>>; | ||
2480 | |||
2481 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NeverTypeNode<R1>> for NeverTypeNode<R2> { | ||
2482 | fn eq(&self, other: &NeverTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2483 | } | 1813 | } |
2484 | impl<R: TreeRoot<RaTypes>> Eq for NeverTypeNode<R> {} | 1814 | unsafe impl TransparentNewType for NeverType { |
2485 | impl<R: TreeRoot<RaTypes>> Hash for NeverTypeNode<R> { | 1815 | type Repr = rowan::SyntaxNode<RaTypes>; |
2486 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2487 | } | 1816 | } |
2488 | 1817 | ||
2489 | impl<'a> AstNode<'a> for NeverType<'a> { | 1818 | impl AstNode for NeverType { |
2490 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1819 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2491 | match syntax.kind() { | 1820 | match syntax.kind() { |
2492 | NEVER_TYPE => Some(NeverType { syntax }), | 1821 | NEVER_TYPE => Some(NeverType::from_repr(syntax.into_repr())), |
2493 | _ => None, | 1822 | _ => None, |
2494 | } | 1823 | } |
2495 | } | 1824 | } |
2496 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1825 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2497 | } | 1826 | fn to_owned(&self) -> TreePtr<NeverType> { TreePtr::cast(self.syntax.to_owned()) } |
2498 | |||
2499 | impl<R: TreeRoot<RaTypes>> NeverTypeNode<R> { | ||
2500 | pub fn borrowed(&self) -> NeverType { | ||
2501 | NeverTypeNode { syntax: self.syntax.borrowed() } | ||
2502 | } | ||
2503 | pub fn owned(&self) -> NeverTypeNode { | ||
2504 | NeverTypeNode { syntax: self.syntax.owned() } | ||
2505 | } | ||
2506 | } | 1827 | } |
2507 | 1828 | ||
2508 | 1829 | ||
2509 | impl<'a> NeverType<'a> {} | 1830 | impl NeverType {} |
2510 | 1831 | ||
2511 | // NominalDef | 1832 | // NominalDef |
1833 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1834 | #[repr(transparent)] | ||
1835 | pub struct NominalDef { | ||
1836 | pub(crate) syntax: SyntaxNode, | ||
1837 | } | ||
1838 | unsafe impl TransparentNewType for NominalDef { | ||
1839 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1840 | } | ||
1841 | |||
2512 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1842 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2513 | pub enum NominalDef<'a> { | 1843 | pub enum NominalDefKind<'a> { |
2514 | StructDef(StructDef<'a>), | 1844 | StructDef(&'a StructDef), |
2515 | EnumDef(EnumDef<'a>), | 1845 | EnumDef(&'a EnumDef), |
2516 | } | 1846 | } |
2517 | 1847 | ||
2518 | impl<'a> AstNode<'a> for NominalDef<'a> { | 1848 | impl AstNode for NominalDef { |
2519 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1849 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2520 | match syntax.kind() { | 1850 | match syntax.kind() { |
2521 | STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })), | 1851 | | STRUCT_DEF |
2522 | ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })), | 1852 | | ENUM_DEF => Some(NominalDef::from_repr(syntax.into_repr())), |
2523 | _ => None, | 1853 | _ => None, |
2524 | } | 1854 | } |
2525 | } | 1855 | } |
2526 | fn syntax(self) -> SyntaxNodeRef<'a> { | 1856 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2527 | match self { | 1857 | fn to_owned(&self) -> TreePtr<NominalDef> { TreePtr::cast(self.syntax.to_owned()) } |
2528 | NominalDef::StructDef(inner) => inner.syntax(), | 1858 | } |
2529 | NominalDef::EnumDef(inner) => inner.syntax(), | 1859 | |
1860 | impl NominalDef { | ||
1861 | pub fn kind(&self) -> NominalDefKind { | ||
1862 | match self.syntax.kind() { | ||
1863 | STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(&self.syntax).unwrap()), | ||
1864 | ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()), | ||
1865 | _ => unreachable!(), | ||
2530 | } | 1866 | } |
2531 | } | 1867 | } |
2532 | } | 1868 | } |
2533 | 1869 | ||
2534 | impl<'a> ast::NameOwner<'a> for NominalDef<'a> {} | 1870 | impl ast::NameOwner for NominalDef {} |
2535 | impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {} | 1871 | impl ast::TypeParamsOwner for NominalDef {} |
2536 | impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} | 1872 | impl ast::AttrsOwner for NominalDef {} |
2537 | impl<'a> NominalDef<'a> {} | 1873 | impl NominalDef {} |
2538 | 1874 | ||
2539 | // Param | 1875 | // Param |
2540 | #[derive(Debug, Clone, Copy,)] | 1876 | #[derive(Debug, PartialEq, Eq, Hash)] |
2541 | pub struct ParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1877 | #[repr(transparent)] |
2542 | pub(crate) syntax: SyntaxNode<R>, | 1878 | pub struct Param { |
2543 | } | 1879 | pub(crate) syntax: SyntaxNode, |
2544 | pub type Param<'a> = ParamNode<RefRoot<'a>>; | ||
2545 | |||
2546 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamNode<R1>> for ParamNode<R2> { | ||
2547 | fn eq(&self, other: &ParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
2548 | } | 1880 | } |
2549 | impl<R: TreeRoot<RaTypes>> Eq for ParamNode<R> {} | 1881 | unsafe impl TransparentNewType for Param { |
2550 | impl<R: TreeRoot<RaTypes>> Hash for ParamNode<R> { | 1882 | type Repr = rowan::SyntaxNode<RaTypes>; |
2551 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2552 | } | 1883 | } |
2553 | 1884 | ||
2554 | impl<'a> AstNode<'a> for Param<'a> { | 1885 | impl AstNode for Param { |
2555 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1886 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2556 | match syntax.kind() { | 1887 | match syntax.kind() { |
2557 | PARAM => Some(Param { syntax }), | 1888 | PARAM => Some(Param::from_repr(syntax.into_repr())), |
2558 | _ => None, | 1889 | _ => None, |
2559 | } | 1890 | } |
2560 | } | 1891 | } |
2561 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1892 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2562 | } | 1893 | fn to_owned(&self) -> TreePtr<Param> { TreePtr::cast(self.syntax.to_owned()) } |
2563 | |||
2564 | impl<R: TreeRoot<RaTypes>> ParamNode<R> { | ||
2565 | pub fn borrowed(&self) -> Param { | ||
2566 | ParamNode { syntax: self.syntax.borrowed() } | ||
2567 | } | ||
2568 | pub fn owned(&self) -> ParamNode { | ||
2569 | ParamNode { syntax: self.syntax.owned() } | ||
2570 | } | ||
2571 | } | 1894 | } |
2572 | 1895 | ||
2573 | 1896 | ||
2574 | impl<'a> Param<'a> { | 1897 | impl Param { |
2575 | pub fn pat(self) -> Option<Pat<'a>> { | 1898 | pub fn pat(&self) -> Option<&Pat> { |
2576 | super::child_opt(self) | 1899 | super::child_opt(self) |
2577 | } | 1900 | } |
2578 | 1901 | ||
2579 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1902 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2580 | super::child_opt(self) | 1903 | super::child_opt(self) |
2581 | } | 1904 | } |
2582 | } | 1905 | } |
2583 | 1906 | ||
2584 | // ParamList | 1907 | // ParamList |
2585 | #[derive(Debug, Clone, Copy,)] | 1908 | #[derive(Debug, PartialEq, Eq, Hash)] |
2586 | pub struct ParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1909 | #[repr(transparent)] |
2587 | pub(crate) syntax: SyntaxNode<R>, | 1910 | pub struct ParamList { |
1911 | pub(crate) syntax: SyntaxNode, | ||
2588 | } | 1912 | } |
2589 | pub type ParamList<'a> = ParamListNode<RefRoot<'a>>; | 1913 | unsafe impl TransparentNewType for ParamList { |
2590 | 1914 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2591 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamListNode<R1>> for ParamListNode<R2> { | ||
2592 | fn eq(&self, other: &ParamListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2593 | } | ||
2594 | impl<R: TreeRoot<RaTypes>> Eq for ParamListNode<R> {} | ||
2595 | impl<R: TreeRoot<RaTypes>> Hash for ParamListNode<R> { | ||
2596 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2597 | } | 1915 | } |
2598 | 1916 | ||
2599 | impl<'a> AstNode<'a> for ParamList<'a> { | 1917 | impl AstNode for ParamList { |
2600 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1918 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2601 | match syntax.kind() { | 1919 | match syntax.kind() { |
2602 | PARAM_LIST => Some(ParamList { syntax }), | 1920 | PARAM_LIST => Some(ParamList::from_repr(syntax.into_repr())), |
2603 | _ => None, | 1921 | _ => None, |
2604 | } | 1922 | } |
2605 | } | 1923 | } |
2606 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1924 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2607 | } | 1925 | fn to_owned(&self) -> TreePtr<ParamList> { TreePtr::cast(self.syntax.to_owned()) } |
2608 | |||
2609 | impl<R: TreeRoot<RaTypes>> ParamListNode<R> { | ||
2610 | pub fn borrowed(&self) -> ParamList { | ||
2611 | ParamListNode { syntax: self.syntax.borrowed() } | ||
2612 | } | ||
2613 | pub fn owned(&self) -> ParamListNode { | ||
2614 | ParamListNode { syntax: self.syntax.owned() } | ||
2615 | } | ||
2616 | } | 1926 | } |
2617 | 1927 | ||
2618 | 1928 | ||
2619 | impl<'a> ParamList<'a> { | 1929 | impl ParamList { |
2620 | pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { | 1930 | pub fn params(&self) -> impl Iterator<Item = &Param> { |
2621 | super::children(self) | 1931 | super::children(self) |
2622 | } | 1932 | } |
2623 | 1933 | ||
2624 | pub fn self_param(self) -> Option<SelfParam<'a>> { | 1934 | pub fn self_param(&self) -> Option<&SelfParam> { |
2625 | super::child_opt(self) | 1935 | super::child_opt(self) |
2626 | } | 1936 | } |
2627 | } | 1937 | } |
2628 | 1938 | ||
2629 | // ParenExpr | 1939 | // ParenExpr |
2630 | #[derive(Debug, Clone, Copy,)] | 1940 | #[derive(Debug, PartialEq, Eq, Hash)] |
2631 | pub struct ParenExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1941 | #[repr(transparent)] |
2632 | pub(crate) syntax: SyntaxNode<R>, | 1942 | pub struct ParenExpr { |
2633 | } | 1943 | pub(crate) syntax: SyntaxNode, |
2634 | pub type ParenExpr<'a> = ParenExprNode<RefRoot<'a>>; | ||
2635 | |||
2636 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenExprNode<R1>> for ParenExprNode<R2> { | ||
2637 | fn eq(&self, other: &ParenExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2638 | } | 1944 | } |
2639 | impl<R: TreeRoot<RaTypes>> Eq for ParenExprNode<R> {} | 1945 | unsafe impl TransparentNewType for ParenExpr { |
2640 | impl<R: TreeRoot<RaTypes>> Hash for ParenExprNode<R> { | 1946 | type Repr = rowan::SyntaxNode<RaTypes>; |
2641 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2642 | } | 1947 | } |
2643 | 1948 | ||
2644 | impl<'a> AstNode<'a> for ParenExpr<'a> { | 1949 | impl AstNode for ParenExpr { |
2645 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1950 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2646 | match syntax.kind() { | 1951 | match syntax.kind() { |
2647 | PAREN_EXPR => Some(ParenExpr { syntax }), | 1952 | PAREN_EXPR => Some(ParenExpr::from_repr(syntax.into_repr())), |
2648 | _ => None, | 1953 | _ => None, |
2649 | } | 1954 | } |
2650 | } | 1955 | } |
2651 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1956 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1957 | fn to_owned(&self) -> TreePtr<ParenExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
2652 | } | 1958 | } |
2653 | 1959 | ||
2654 | impl<R: TreeRoot<RaTypes>> ParenExprNode<R> { | ||
2655 | pub fn borrowed(&self) -> ParenExpr { | ||
2656 | ParenExprNode { syntax: self.syntax.borrowed() } | ||
2657 | } | ||
2658 | pub fn owned(&self) -> ParenExprNode { | ||
2659 | ParenExprNode { syntax: self.syntax.owned() } | ||
2660 | } | ||
2661 | } | ||
2662 | 1960 | ||
2663 | 1961 | impl ParenExpr { | |
2664 | impl<'a> ParenExpr<'a> { | 1962 | pub fn expr(&self) -> Option<&Expr> { |
2665 | pub fn expr(self) -> Option<Expr<'a>> { | ||
2666 | super::child_opt(self) | 1963 | super::child_opt(self) |
2667 | } | 1964 | } |
2668 | } | 1965 | } |
2669 | 1966 | ||
2670 | // ParenType | 1967 | // ParenType |
2671 | #[derive(Debug, Clone, Copy,)] | 1968 | #[derive(Debug, PartialEq, Eq, Hash)] |
2672 | pub struct ParenTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1969 | #[repr(transparent)] |
2673 | pub(crate) syntax: SyntaxNode<R>, | 1970 | pub struct ParenType { |
1971 | pub(crate) syntax: SyntaxNode, | ||
2674 | } | 1972 | } |
2675 | pub type ParenType<'a> = ParenTypeNode<RefRoot<'a>>; | 1973 | unsafe impl TransparentNewType for ParenType { |
2676 | 1974 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2677 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenTypeNode<R1>> for ParenTypeNode<R2> { | ||
2678 | fn eq(&self, other: &ParenTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2679 | } | ||
2680 | impl<R: TreeRoot<RaTypes>> Eq for ParenTypeNode<R> {} | ||
2681 | impl<R: TreeRoot<RaTypes>> Hash for ParenTypeNode<R> { | ||
2682 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2683 | } | 1975 | } |
2684 | 1976 | ||
2685 | impl<'a> AstNode<'a> for ParenType<'a> { | 1977 | impl AstNode for ParenType { |
2686 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1978 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2687 | match syntax.kind() { | 1979 | match syntax.kind() { |
2688 | PAREN_TYPE => Some(ParenType { syntax }), | 1980 | PAREN_TYPE => Some(ParenType::from_repr(syntax.into_repr())), |
2689 | _ => None, | 1981 | _ => None, |
2690 | } | 1982 | } |
2691 | } | 1983 | } |
2692 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1984 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2693 | } | 1985 | fn to_owned(&self) -> TreePtr<ParenType> { TreePtr::cast(self.syntax.to_owned()) } |
2694 | |||
2695 | impl<R: TreeRoot<RaTypes>> ParenTypeNode<R> { | ||
2696 | pub fn borrowed(&self) -> ParenType { | ||
2697 | ParenTypeNode { syntax: self.syntax.borrowed() } | ||
2698 | } | ||
2699 | pub fn owned(&self) -> ParenTypeNode { | ||
2700 | ParenTypeNode { syntax: self.syntax.owned() } | ||
2701 | } | ||
2702 | } | 1986 | } |
2703 | 1987 | ||
2704 | 1988 | ||
2705 | impl<'a> ParenType<'a> { | 1989 | impl ParenType { |
2706 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1990 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2707 | super::child_opt(self) | 1991 | super::child_opt(self) |
2708 | } | 1992 | } |
2709 | } | 1993 | } |
2710 | 1994 | ||
2711 | // Pat | 1995 | // Pat |
1996 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1997 | #[repr(transparent)] | ||
1998 | pub struct Pat { | ||
1999 | pub(crate) syntax: SyntaxNode, | ||
2000 | } | ||
2001 | unsafe impl TransparentNewType for Pat { | ||
2002 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
2003 | } | ||
2004 | |||
2712 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 2005 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2713 | pub enum Pat<'a> { | 2006 | pub enum PatKind<'a> { |
2714 | RefPat(RefPat<'a>), | 2007 | RefPat(&'a RefPat), |
2715 | BindPat(BindPat<'a>), | 2008 | BindPat(&'a BindPat), |
2716 | PlaceholderPat(PlaceholderPat<'a>), | 2009 | PlaceholderPat(&'a PlaceholderPat), |
2717 | PathPat(PathPat<'a>), | 2010 | PathPat(&'a PathPat), |
2718 | StructPat(StructPat<'a>), | 2011 | StructPat(&'a StructPat), |
2719 | FieldPatList(FieldPatList<'a>), | 2012 | FieldPatList(&'a FieldPatList), |
2720 | TupleStructPat(TupleStructPat<'a>), | 2013 | TupleStructPat(&'a TupleStructPat), |
2721 | TuplePat(TuplePat<'a>), | 2014 | TuplePat(&'a TuplePat), |
2722 | SlicePat(SlicePat<'a>), | 2015 | SlicePat(&'a SlicePat), |
2723 | RangePat(RangePat<'a>), | 2016 | RangePat(&'a RangePat), |
2724 | } | 2017 | } |
2725 | 2018 | ||
2726 | impl<'a> AstNode<'a> for Pat<'a> { | 2019 | impl AstNode for Pat { |
2727 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2020 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2728 | match syntax.kind() { | 2021 | match syntax.kind() { |
2729 | REF_PAT => Some(Pat::RefPat(RefPat { syntax })), | 2022 | | REF_PAT |
2730 | BIND_PAT => Some(Pat::BindPat(BindPat { syntax })), | 2023 | | BIND_PAT |
2731 | PLACEHOLDER_PAT => Some(Pat::PlaceholderPat(PlaceholderPat { syntax })), | 2024 | | PLACEHOLDER_PAT |
2732 | PATH_PAT => Some(Pat::PathPat(PathPat { syntax })), | 2025 | | PATH_PAT |
2733 | STRUCT_PAT => Some(Pat::StructPat(StructPat { syntax })), | 2026 | | STRUCT_PAT |
2734 | FIELD_PAT_LIST => Some(Pat::FieldPatList(FieldPatList { syntax })), | 2027 | | FIELD_PAT_LIST |
2735 | TUPLE_STRUCT_PAT => Some(Pat::TupleStructPat(TupleStructPat { syntax })), | 2028 | | TUPLE_STRUCT_PAT |
2736 | TUPLE_PAT => Some(Pat::TuplePat(TuplePat { syntax })), | 2029 | | TUPLE_PAT |
2737 | SLICE_PAT => Some(Pat::SlicePat(SlicePat { syntax })), | 2030 | | SLICE_PAT |
2738 | RANGE_PAT => Some(Pat::RangePat(RangePat { syntax })), | 2031 | | RANGE_PAT => Some(Pat::from_repr(syntax.into_repr())), |
2739 | _ => None, | 2032 | _ => None, |
2740 | } | 2033 | } |
2741 | } | 2034 | } |
2742 | fn syntax(self) -> SyntaxNodeRef<'a> { | 2035 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2743 | match self { | 2036 | fn to_owned(&self) -> TreePtr<Pat> { TreePtr::cast(self.syntax.to_owned()) } |
2744 | Pat::RefPat(inner) => inner.syntax(), | 2037 | } |
2745 | Pat::BindPat(inner) => inner.syntax(), | 2038 | |
2746 | Pat::PlaceholderPat(inner) => inner.syntax(), | 2039 | impl Pat { |
2747 | Pat::PathPat(inner) => inner.syntax(), | 2040 | pub fn kind(&self) -> PatKind { |
2748 | Pat::StructPat(inner) => inner.syntax(), | 2041 | match self.syntax.kind() { |
2749 | Pat::FieldPatList(inner) => inner.syntax(), | 2042 | REF_PAT => PatKind::RefPat(RefPat::cast(&self.syntax).unwrap()), |
2750 | Pat::TupleStructPat(inner) => inner.syntax(), | 2043 | BIND_PAT => PatKind::BindPat(BindPat::cast(&self.syntax).unwrap()), |
2751 | Pat::TuplePat(inner) => inner.syntax(), | 2044 | PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(&self.syntax).unwrap()), |
2752 | Pat::SlicePat(inner) => inner.syntax(), | 2045 | PATH_PAT => PatKind::PathPat(PathPat::cast(&self.syntax).unwrap()), |
2753 | Pat::RangePat(inner) => inner.syntax(), | 2046 | STRUCT_PAT => PatKind::StructPat(StructPat::cast(&self.syntax).unwrap()), |
2047 | FIELD_PAT_LIST => PatKind::FieldPatList(FieldPatList::cast(&self.syntax).unwrap()), | ||
2048 | TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(&self.syntax).unwrap()), | ||
2049 | TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(&self.syntax).unwrap()), | ||
2050 | SLICE_PAT => PatKind::SlicePat(SlicePat::cast(&self.syntax).unwrap()), | ||
2051 | RANGE_PAT => PatKind::RangePat(RangePat::cast(&self.syntax).unwrap()), | ||
2052 | _ => unreachable!(), | ||
2754 | } | 2053 | } |
2755 | } | 2054 | } |
2756 | } | 2055 | } |
2757 | 2056 | ||
2758 | impl<'a> Pat<'a> {} | 2057 | impl Pat {} |
2759 | 2058 | ||
2760 | // Path | 2059 | // Path |
2761 | #[derive(Debug, Clone, Copy,)] | 2060 | #[derive(Debug, PartialEq, Eq, Hash)] |
2762 | pub struct PathNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2061 | #[repr(transparent)] |
2763 | pub(crate) syntax: SyntaxNode<R>, | 2062 | pub struct Path { |
2764 | } | 2063 | pub(crate) syntax: SyntaxNode, |
2765 | pub type Path<'a> = PathNode<RefRoot<'a>>; | ||
2766 | |||
2767 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathNode<R1>> for PathNode<R2> { | ||
2768 | fn eq(&self, other: &PathNode<R1>) -> bool { self.syntax == other.syntax } | ||
2769 | } | 2064 | } |
2770 | impl<R: TreeRoot<RaTypes>> Eq for PathNode<R> {} | 2065 | unsafe impl TransparentNewType for Path { |
2771 | impl<R: TreeRoot<RaTypes>> Hash for PathNode<R> { | 2066 | type Repr = rowan::SyntaxNode<RaTypes>; |
2772 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2773 | } | 2067 | } |
2774 | 2068 | ||
2775 | impl<'a> AstNode<'a> for Path<'a> { | 2069 | impl AstNode for Path { |
2776 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2070 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2777 | match syntax.kind() { | 2071 | match syntax.kind() { |
2778 | PATH => Some(Path { syntax }), | 2072 | PATH => Some(Path::from_repr(syntax.into_repr())), |
2779 | _ => None, | 2073 | _ => None, |
2780 | } | 2074 | } |
2781 | } | 2075 | } |
2782 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2076 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2783 | } | 2077 | fn to_owned(&self) -> TreePtr<Path> { TreePtr::cast(self.syntax.to_owned()) } |
2784 | |||
2785 | impl<R: TreeRoot<RaTypes>> PathNode<R> { | ||
2786 | pub fn borrowed(&self) -> Path { | ||
2787 | PathNode { syntax: self.syntax.borrowed() } | ||
2788 | } | ||
2789 | pub fn owned(&self) -> PathNode { | ||
2790 | PathNode { syntax: self.syntax.owned() } | ||
2791 | } | ||
2792 | } | 2078 | } |
2793 | 2079 | ||
2794 | 2080 | ||
2795 | impl<'a> Path<'a> { | 2081 | impl Path { |
2796 | pub fn segment(self) -> Option<PathSegment<'a>> { | 2082 | pub fn segment(&self) -> Option<&PathSegment> { |
2797 | super::child_opt(self) | 2083 | super::child_opt(self) |
2798 | } | 2084 | } |
2799 | 2085 | ||
2800 | pub fn qualifier(self) -> Option<Path<'a>> { | 2086 | pub fn qualifier(&self) -> Option<&Path> { |
2801 | super::child_opt(self) | 2087 | super::child_opt(self) |
2802 | } | 2088 | } |
2803 | } | 2089 | } |
2804 | 2090 | ||
2805 | // PathExpr | 2091 | // PathExpr |
2806 | #[derive(Debug, Clone, Copy,)] | 2092 | #[derive(Debug, PartialEq, Eq, Hash)] |
2807 | pub struct PathExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2093 | #[repr(transparent)] |
2808 | pub(crate) syntax: SyntaxNode<R>, | 2094 | pub struct PathExpr { |
2095 | pub(crate) syntax: SyntaxNode, | ||
2809 | } | 2096 | } |
2810 | pub type PathExpr<'a> = PathExprNode<RefRoot<'a>>; | 2097 | unsafe impl TransparentNewType for PathExpr { |
2811 | 2098 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2812 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathExprNode<R1>> for PathExprNode<R2> { | ||
2813 | fn eq(&self, other: &PathExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2814 | } | ||
2815 | impl<R: TreeRoot<RaTypes>> Eq for PathExprNode<R> {} | ||
2816 | impl<R: TreeRoot<RaTypes>> Hash for PathExprNode<R> { | ||
2817 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2818 | } | 2099 | } |
2819 | 2100 | ||
2820 | impl<'a> AstNode<'a> for PathExpr<'a> { | 2101 | impl AstNode for PathExpr { |
2821 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2102 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2822 | match syntax.kind() { | 2103 | match syntax.kind() { |
2823 | PATH_EXPR => Some(PathExpr { syntax }), | 2104 | PATH_EXPR => Some(PathExpr::from_repr(syntax.into_repr())), |
2824 | _ => None, | 2105 | _ => None, |
2825 | } | 2106 | } |
2826 | } | 2107 | } |
2827 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2108 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2828 | } | 2109 | fn to_owned(&self) -> TreePtr<PathExpr> { TreePtr::cast(self.syntax.to_owned()) } |
2829 | |||
2830 | impl<R: TreeRoot<RaTypes>> PathExprNode<R> { | ||
2831 | pub fn borrowed(&self) -> PathExpr { | ||
2832 | PathExprNode { syntax: self.syntax.borrowed() } | ||
2833 | } | ||
2834 | pub fn owned(&self) -> PathExprNode { | ||
2835 | PathExprNode { syntax: self.syntax.owned() } | ||
2836 | } | ||
2837 | } | 2110 | } |
2838 | 2111 | ||
2839 | 2112 | ||
2840 | impl<'a> PathExpr<'a> { | 2113 | impl PathExpr { |
2841 | pub fn path(self) -> Option<Path<'a>> { | 2114 | pub fn path(&self) -> Option<&Path> { |
2842 | super::child_opt(self) | 2115 | super::child_opt(self) |
2843 | } | 2116 | } |
2844 | } | 2117 | } |
2845 | 2118 | ||
2846 | // PathPat | 2119 | // PathPat |
2847 | #[derive(Debug, Clone, Copy,)] | 2120 | #[derive(Debug, PartialEq, Eq, Hash)] |
2848 | pub struct PathPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2121 | #[repr(transparent)] |
2849 | pub(crate) syntax: SyntaxNode<R>, | 2122 | pub struct PathPat { |
2123 | pub(crate) syntax: SyntaxNode, | ||
2850 | } | 2124 | } |
2851 | pub type PathPat<'a> = PathPatNode<RefRoot<'a>>; | 2125 | unsafe impl TransparentNewType for PathPat { |
2852 | 2126 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2853 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathPatNode<R1>> for PathPatNode<R2> { | ||
2854 | fn eq(&self, other: &PathPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2855 | } | ||
2856 | impl<R: TreeRoot<RaTypes>> Eq for PathPatNode<R> {} | ||
2857 | impl<R: TreeRoot<RaTypes>> Hash for PathPatNode<R> { | ||
2858 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2859 | } | 2127 | } |
2860 | 2128 | ||
2861 | impl<'a> AstNode<'a> for PathPat<'a> { | 2129 | impl AstNode for PathPat { |
2862 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2130 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2863 | match syntax.kind() { | 2131 | match syntax.kind() { |
2864 | PATH_PAT => Some(PathPat { syntax }), | 2132 | PATH_PAT => Some(PathPat::from_repr(syntax.into_repr())), |
2865 | _ => None, | 2133 | _ => None, |
2866 | } | 2134 | } |
2867 | } | 2135 | } |
2868 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2136 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2869 | } | 2137 | fn to_owned(&self) -> TreePtr<PathPat> { TreePtr::cast(self.syntax.to_owned()) } |
2870 | |||
2871 | impl<R: TreeRoot<RaTypes>> PathPatNode<R> { | ||
2872 | pub fn borrowed(&self) -> PathPat { | ||
2873 | PathPatNode { syntax: self.syntax.borrowed() } | ||
2874 | } | ||
2875 | pub fn owned(&self) -> PathPatNode { | ||
2876 | PathPatNode { syntax: self.syntax.owned() } | ||
2877 | } | ||
2878 | } | 2138 | } |
2879 | 2139 | ||
2880 | 2140 | ||
2881 | impl<'a> PathPat<'a> {} | 2141 | impl PathPat {} |
2882 | 2142 | ||
2883 | // PathSegment | 2143 | // PathSegment |
2884 | #[derive(Debug, Clone, Copy,)] | 2144 | #[derive(Debug, PartialEq, Eq, Hash)] |
2885 | pub struct PathSegmentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2145 | #[repr(transparent)] |
2886 | pub(crate) syntax: SyntaxNode<R>, | 2146 | pub struct PathSegment { |
2887 | } | 2147 | pub(crate) syntax: SyntaxNode, |
2888 | pub type PathSegment<'a> = PathSegmentNode<RefRoot<'a>>; | ||
2889 | |||
2890 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathSegmentNode<R1>> for PathSegmentNode<R2> { | ||
2891 | fn eq(&self, other: &PathSegmentNode<R1>) -> bool { self.syntax == other.syntax } | ||
2892 | } | 2148 | } |
2893 | impl<R: TreeRoot<RaTypes>> Eq for PathSegmentNode<R> {} | 2149 | unsafe impl TransparentNewType for PathSegment { |
2894 | impl<R: TreeRoot<RaTypes>> Hash for PathSegmentNode<R> { | 2150 | type Repr = rowan::SyntaxNode<RaTypes>; |
2895 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2896 | } | 2151 | } |
2897 | 2152 | ||
2898 | impl<'a> AstNode<'a> for PathSegment<'a> { | 2153 | impl AstNode for PathSegment { |
2899 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2154 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2900 | match syntax.kind() { | 2155 | match syntax.kind() { |
2901 | PATH_SEGMENT => Some(PathSegment { syntax }), | 2156 | PATH_SEGMENT => Some(PathSegment::from_repr(syntax.into_repr())), |
2902 | _ => None, | 2157 | _ => None, |
2903 | } | 2158 | } |
2904 | } | 2159 | } |
2905 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2160 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2161 | fn to_owned(&self) -> TreePtr<PathSegment> { TreePtr::cast(self.syntax.to_owned()) } | ||
2906 | } | 2162 | } |
2907 | 2163 | ||
2908 | impl<R: TreeRoot<RaTypes>> PathSegmentNode<R> { | ||
2909 | pub fn borrowed(&self) -> PathSegment { | ||
2910 | PathSegmentNode { syntax: self.syntax.borrowed() } | ||
2911 | } | ||
2912 | pub fn owned(&self) -> PathSegmentNode { | ||
2913 | PathSegmentNode { syntax: self.syntax.owned() } | ||
2914 | } | ||
2915 | } | ||
2916 | 2164 | ||
2917 | 2165 | impl PathSegment { | |
2918 | impl<'a> PathSegment<'a> { | 2166 | pub fn name_ref(&self) -> Option<&NameRef> { |
2919 | pub fn name_ref(self) -> Option<NameRef<'a>> { | ||
2920 | super::child_opt(self) | 2167 | super::child_opt(self) |
2921 | } | 2168 | } |
2922 | } | 2169 | } |
2923 | 2170 | ||
2924 | // PathType | 2171 | // PathType |
2925 | #[derive(Debug, Clone, Copy,)] | 2172 | #[derive(Debug, PartialEq, Eq, Hash)] |
2926 | pub struct PathTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2173 | #[repr(transparent)] |
2927 | pub(crate) syntax: SyntaxNode<R>, | 2174 | pub struct PathType { |
2928 | } | 2175 | pub(crate) syntax: SyntaxNode, |
2929 | pub type PathType<'a> = PathTypeNode<RefRoot<'a>>; | ||
2930 | |||
2931 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathTypeNode<R1>> for PathTypeNode<R2> { | ||
2932 | fn eq(&self, other: &PathTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2933 | } | 2176 | } |
2934 | impl<R: TreeRoot<RaTypes>> Eq for PathTypeNode<R> {} | 2177 | unsafe impl TransparentNewType for PathType { |
2935 | impl<R: TreeRoot<RaTypes>> Hash for PathTypeNode<R> { | 2178 | type Repr = rowan::SyntaxNode<RaTypes>; |
2936 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2937 | } | 2179 | } |
2938 | 2180 | ||
2939 | impl<'a> AstNode<'a> for PathType<'a> { | 2181 | impl AstNode for PathType { |
2940 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2182 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2941 | match syntax.kind() { | 2183 | match syntax.kind() { |
2942 | PATH_TYPE => Some(PathType { syntax }), | 2184 | PATH_TYPE => Some(PathType::from_repr(syntax.into_repr())), |
2943 | _ => None, | 2185 | _ => None, |
2944 | } | 2186 | } |
2945 | } | 2187 | } |
2946 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2188 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2947 | } | 2189 | fn to_owned(&self) -> TreePtr<PathType> { TreePtr::cast(self.syntax.to_owned()) } |
2948 | |||
2949 | impl<R: TreeRoot<RaTypes>> PathTypeNode<R> { | ||
2950 | pub fn borrowed(&self) -> PathType { | ||
2951 | PathTypeNode { syntax: self.syntax.borrowed() } | ||
2952 | } | ||
2953 | pub fn owned(&self) -> PathTypeNode { | ||
2954 | PathTypeNode { syntax: self.syntax.owned() } | ||
2955 | } | ||
2956 | } | 2190 | } |
2957 | 2191 | ||
2958 | 2192 | ||
2959 | impl<'a> PathType<'a> { | 2193 | impl PathType { |
2960 | pub fn path(self) -> Option<Path<'a>> { | 2194 | pub fn path(&self) -> Option<&Path> { |
2961 | super::child_opt(self) | 2195 | super::child_opt(self) |
2962 | } | 2196 | } |
2963 | } | 2197 | } |
2964 | 2198 | ||
2965 | // PlaceholderPat | 2199 | // PlaceholderPat |
2966 | #[derive(Debug, Clone, Copy,)] | 2200 | #[derive(Debug, PartialEq, Eq, Hash)] |
2967 | pub struct PlaceholderPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2201 | #[repr(transparent)] |
2968 | pub(crate) syntax: SyntaxNode<R>, | 2202 | pub struct PlaceholderPat { |
2203 | pub(crate) syntax: SyntaxNode, | ||
2969 | } | 2204 | } |
2970 | pub type PlaceholderPat<'a> = PlaceholderPatNode<RefRoot<'a>>; | 2205 | unsafe impl TransparentNewType for PlaceholderPat { |
2971 | 2206 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2972 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderPatNode<R1>> for PlaceholderPatNode<R2> { | ||
2973 | fn eq(&self, other: &PlaceholderPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2974 | } | ||
2975 | impl<R: TreeRoot<RaTypes>> Eq for PlaceholderPatNode<R> {} | ||
2976 | impl<R: TreeRoot<RaTypes>> Hash for PlaceholderPatNode<R> { | ||
2977 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2978 | } | 2207 | } |
2979 | 2208 | ||
2980 | impl<'a> AstNode<'a> for PlaceholderPat<'a> { | 2209 | impl AstNode for PlaceholderPat { |
2981 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2210 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2982 | match syntax.kind() { | 2211 | match syntax.kind() { |
2983 | PLACEHOLDER_PAT => Some(PlaceholderPat { syntax }), | 2212 | PLACEHOLDER_PAT => Some(PlaceholderPat::from_repr(syntax.into_repr())), |
2984 | _ => None, | 2213 | _ => None, |
2985 | } | 2214 | } |
2986 | } | 2215 | } |
2987 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2216 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2988 | } | 2217 | fn to_owned(&self) -> TreePtr<PlaceholderPat> { TreePtr::cast(self.syntax.to_owned()) } |
2989 | |||
2990 | impl<R: TreeRoot<RaTypes>> PlaceholderPatNode<R> { | ||
2991 | pub fn borrowed(&self) -> PlaceholderPat { | ||
2992 | PlaceholderPatNode { syntax: self.syntax.borrowed() } | ||
2993 | } | ||
2994 | pub fn owned(&self) -> PlaceholderPatNode { | ||
2995 | PlaceholderPatNode { syntax: self.syntax.owned() } | ||
2996 | } | ||
2997 | } | 2218 | } |
2998 | 2219 | ||
2999 | 2220 | ||
3000 | impl<'a> PlaceholderPat<'a> {} | 2221 | impl PlaceholderPat {} |
3001 | 2222 | ||
3002 | // PlaceholderType | 2223 | // PlaceholderType |
3003 | #[derive(Debug, Clone, Copy,)] | 2224 | #[derive(Debug, PartialEq, Eq, Hash)] |
3004 | pub struct PlaceholderTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2225 | #[repr(transparent)] |
3005 | pub(crate) syntax: SyntaxNode<R>, | 2226 | pub struct PlaceholderType { |
2227 | pub(crate) syntax: SyntaxNode, | ||
3006 | } | 2228 | } |
3007 | pub type PlaceholderType<'a> = PlaceholderTypeNode<RefRoot<'a>>; | 2229 | unsafe impl TransparentNewType for PlaceholderType { |
3008 | 2230 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3009 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderTypeNode<R1>> for PlaceholderTypeNode<R2> { | ||
3010 | fn eq(&self, other: &PlaceholderTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3011 | } | ||
3012 | impl<R: TreeRoot<RaTypes>> Eq for PlaceholderTypeNode<R> {} | ||
3013 | impl<R: TreeRoot<RaTypes>> Hash for PlaceholderTypeNode<R> { | ||
3014 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3015 | } | 2231 | } |
3016 | 2232 | ||
3017 | impl<'a> AstNode<'a> for PlaceholderType<'a> { | 2233 | impl AstNode for PlaceholderType { |
3018 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2234 | fn cast(syntax: &Synta |