aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 09:05:55 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 09:05:55 +0000
commit3f4be819125ce4a22edd86721fa56b5caba99c2e (patch)
treebe93895ddc08c911585d9f7bc64623a3741f32c6 /crates/ra_syntax/src
parent4e444d2bc24d16284401444fd2154f63e0f96070 (diff)
parent122410d7aa34a32d468a3173858cbc8a2bbc68f5 (diff)
Merge #449
449: switch to new rowan API r=matklad a=matklad closes https://github.com/rust-analyzer/rust-analyzer/issues/448 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/algo.rs16
-rw-r--r--crates/ra_syntax/src/algo/visit.rs30
-rw-r--r--crates/ra_syntax/src/ast.rs210
-rw-r--r--crates/ra_syntax/src/ast/generated.rs4843
-rw-r--r--crates/ra_syntax/src/ast/generated.rs.tera93
-rw-r--r--crates/ra_syntax/src/lib.rs38
-rw-r--r--crates/ra_syntax/src/reparsing.rs35
-rw-r--r--crates/ra_syntax/src/utils.rs17
-rw-r--r--crates/ra_syntax/src/validation.rs15
-rw-r--r--crates/ra_syntax/src/validation/byte.rs8
-rw-r--r--crates/ra_syntax/src/validation/byte_string.rs8
-rw-r--r--crates/ra_syntax/src/validation/char.rs8
-rw-r--r--crates/ra_syntax/src/validation/string.rs8
-rw-r--r--crates/ra_syntax/src/yellow.rs148
-rw-r--r--crates/ra_syntax/src/yellow/syntax_text.rs6
15 files changed, 2123 insertions, 3360 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 @@
1pub mod visit; 1pub mod visit;
2 2
3use crate::{SyntaxNode, SyntaxNodeRef, TextRange, TextUnit}; 3use rowan::TransparentNewType;
4
5use crate::{SyntaxNode, TextRange, TextUnit};
4 6
5pub use rowan::LeafAtOffset; 7pub use rowan::LeafAtOffset;
6 8
7pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset<SyntaxNodeRef> { 9pub 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
15pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { 19pub 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
19pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { 23pub 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 @@
1use crate::{AstNode, SyntaxNodeRef}; 1use crate::{AstNode, SyntaxNode};
2 2
3use std::marker::PhantomData; 3use 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
16pub trait Visitor<'a>: Sized { 16pub 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 {
32pub trait VisitorCtx<'a>: Sized { 32pub 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> {
54impl<'a, T> Visitor<'a> for EmptyVisitor<T> { 54impl<'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> {
84impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> 84impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F>
85where 85where
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> {
105impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> 105impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F>
106where 106where
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 9ab59738f..0e303ee98 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -1,119 +1,115 @@
1mod generated; 1mod generated;
2 2
3use std::marker::PhantomData; 3use std::marker::PhantomData;
4use std::string::String as RustString;
5 4
6use itertools::Itertools; 5use itertools::Itertools;
7 6
8pub use self::generated::*; 7pub use self::generated::*;
9use crate::{ 8use 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.
20pub trait AstNode<'a>: Clone + Copy + 'a { 18pub 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
27pub trait NameOwner<'a>: AstNode<'a> { 26pub trait NameOwner: AstNode {
28 fn name(self) -> Option<Name<'a>> { 27 fn name(&self) -> Option<&Name> {
29 child_opt(self) 28 child_opt(self)
30 } 29 }
31} 30}
32 31
33pub trait VisibilityOwner<'a>: AstNode<'a> { 32pub trait VisibilityOwner: AstNode {
34 fn visibility(self) -> Option<Visibility<'a>> { 33 fn visibility(&self) -> Option<&Visibility> {
35 child_opt(self) 34 child_opt(self)
36 } 35 }
37} 36}
38 37
39pub trait LoopBodyOwner<'a>: AstNode<'a> { 38pub trait LoopBodyOwner: AstNode {
40 fn loop_body(self) -> Option<Block<'a>> { 39 fn loop_body(&self) -> Option<&Block> {
41 child_opt(self) 40 child_opt(self)
42 } 41 }
43} 42}
44 43
45pub trait ArgListOwner<'a>: AstNode<'a> { 44pub trait ArgListOwner: AstNode {
46 fn arg_list(self) -> Option<ArgList<'a>> { 45 fn arg_list(&self) -> Option<&ArgList> {
47 child_opt(self) 46 child_opt(self)
48 } 47 }
49} 48}
50 49
51pub trait FnDefOwner<'a>: AstNode<'a> { 50pub trait FnDefOwner: AstNode {
52 fn functions(self) -> AstChildren<'a, FnDef<'a>> { 51 fn functions(&self) -> AstChildren<FnDef> {
53 children(self) 52 children(self)
54 } 53 }
55} 54}
56 55
57// ModuleItem
58#[derive(Debug, Clone, Copy, PartialEq, Eq)] 56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub enum ItemOrMacro<'a> { 57pub enum ItemOrMacro<'a> {
60 Item(ModuleItem<'a>), 58 Item(&'a ModuleItem),
61 Macro(MacroCall<'a>), 59 Macro(&'a MacroCall),
62} 60}
63 61
64impl<'a> AstNode<'a> for ItemOrMacro<'a> { 62pub trait ModuleItemOwner: AstNode {
65 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 63 fn items(&self) -> AstChildren<ModuleItem> {
66 let res = if let Some(item) = ModuleItem::cast(syntax) { 64 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 } 65 }
75 fn syntax(self) -> SyntaxNodeRef<'a> { 66 fn items_with_macros(&self) -> ItemOrMacroIter {
76 match self { 67 ItemOrMacroIter(self.syntax().children())
77 ItemOrMacro::Item(it) => it.syntax(),
78 ItemOrMacro::Macro(it) => it.syntax(),
79 }
80 } 68 }
81} 69}
82 70
83pub trait ModuleItemOwner<'a>: AstNode<'a> { 71#[derive(Debug)]
84 fn items(self) -> AstChildren<'a, ModuleItem<'a>> { 72pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>);
85 children(self)
86 }
87 73
88 fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> { 74impl<'a> Iterator for ItemOrMacroIter<'a> {
89 children(self) 75 type Item = ItemOrMacro<'a>;
76 fn next(&mut self) -> Option<ItemOrMacro<'a>> {
77 loop {
78 let n = self.0.next()?;
79 if let Some(item) = ModuleItem::cast(n) {
80 return Some(ItemOrMacro::Item(item));
81 }
82 if let Some(call) = MacroCall::cast(n) {
83 return Some(ItemOrMacro::Macro(call));
84 }
85 }
90 } 86 }
91} 87}
92 88
93pub trait TypeParamsOwner<'a>: AstNode<'a> { 89pub trait TypeParamsOwner: AstNode {
94 fn type_param_list(self) -> Option<TypeParamList<'a>> { 90 fn type_param_list(&self) -> Option<&TypeParamList> {
95 child_opt(self) 91 child_opt(self)
96 } 92 }
97 93
98 fn where_clause(self) -> Option<WhereClause<'a>> { 94 fn where_clause(&self) -> Option<&WhereClause> {
99 child_opt(self) 95 child_opt(self)
100 } 96 }
101} 97}
102 98
103pub trait AttrsOwner<'a>: AstNode<'a> { 99pub trait AttrsOwner: AstNode {
104 fn attrs(self) -> AstChildren<'a, Attr<'a>> { 100 fn attrs(&self) -> AstChildren<Attr> {
105 children(self) 101 children(self)
106 } 102 }
107} 103}
108 104
109pub trait DocCommentsOwner<'a>: AstNode<'a> { 105pub trait DocCommentsOwner: AstNode {
110 fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { 106 fn doc_comments(&self) -> AstChildren<Comment> {
111 children(self) 107 children(self)
112 } 108 }
113 109
114 /// Returns the textual content of a doc comment block as a single string. 110 /// Returns the textual content of a doc comment block as a single string.
115 /// That is, strips leading `///` and joins lines 111 /// That is, strips leading `///` and joins lines
116 fn doc_comment_text(self) -> RustString { 112 fn doc_comment_text(&self) -> std::string::String {
117 self.doc_comments() 113 self.doc_comments()
118 .filter(|comment| comment.is_doc_comment()) 114 .filter(|comment| comment.is_doc_comment())
119 .map(|comment| { 115 .map(|comment| {
@@ -130,13 +126,13 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> {
130 } 126 }
131} 127}
132 128
133impl<'a> FnDef<'a> { 129impl FnDef {
134 pub fn has_atom_attr(&self, atom: &str) -> bool { 130 pub fn has_atom_attr(&self, atom: &str) -> bool {
135 self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) 131 self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom)
136 } 132 }
137} 133}
138 134
139impl<'a> Attr<'a> { 135impl Attr {
140 pub fn as_atom(&self) -> Option<SmolStr> { 136 pub fn as_atom(&self) -> Option<SmolStr> {
141 let tt = self.value()?; 137 let tt = self.value()?;
142 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; 138 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?;
@@ -147,7 +143,7 @@ impl<'a> Attr<'a> {
147 } 143 }
148 } 144 }
149 145
150 pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> { 146 pub fn as_call(&self) -> Option<(SmolStr, &TokenTree)> {
151 let tt = self.value()?; 147 let tt = self.value()?;
152 let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; 148 let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?;
153 let args = TokenTree::cast(args)?; 149 let args = TokenTree::cast(args)?;
@@ -159,37 +155,37 @@ impl<'a> Attr<'a> {
159 } 155 }
160} 156}
161 157
162impl<'a> Lifetime<'a> { 158impl Lifetime {
163 pub fn text(&self) -> SmolStr { 159 pub fn text(&self) -> SmolStr {
164 self.syntax().leaf_text().unwrap().clone() 160 self.syntax().leaf_text().unwrap().clone()
165 } 161 }
166} 162}
167 163
168impl<'a> Char<'a> { 164impl Char {
169 pub fn text(&self) -> &SmolStr { 165 pub fn text(&self) -> &SmolStr {
170 &self.syntax().leaf_text().unwrap() 166 &self.syntax().leaf_text().unwrap()
171 } 167 }
172} 168}
173 169
174impl<'a> Byte<'a> { 170impl Byte {
175 pub fn text(&self) -> &SmolStr { 171 pub fn text(&self) -> &SmolStr {
176 &self.syntax().leaf_text().unwrap() 172 &self.syntax().leaf_text().unwrap()
177 } 173 }
178} 174}
179 175
180impl<'a> ByteString<'a> { 176impl ByteString {
181 pub fn text(&self) -> &SmolStr { 177 pub fn text(&self) -> &SmolStr {
182 &self.syntax().leaf_text().unwrap() 178 &self.syntax().leaf_text().unwrap()
183 } 179 }
184} 180}
185 181
186impl<'a> String<'a> { 182impl String {
187 pub fn text(&self) -> &SmolStr { 183 pub fn text(&self) -> &SmolStr {
188 &self.syntax().leaf_text().unwrap() 184 &self.syntax().leaf_text().unwrap()
189 } 185 }
190} 186}
191 187
192impl<'a> Comment<'a> { 188impl Comment {
193 pub fn text(&self) -> &SmolStr { 189 pub fn text(&self) -> &SmolStr {
194 self.syntax().leaf_text().unwrap() 190 self.syntax().leaf_text().unwrap()
195 } 191 }
@@ -251,7 +247,7 @@ impl CommentFlavor {
251 } 247 }
252} 248}
253 249
254impl<'a> Whitespace<'a> { 250impl Whitespace {
255 pub fn text(&self) -> &SmolStr { 251 pub fn text(&self) -> &SmolStr {
256 &self.syntax().leaf_text().unwrap() 252 &self.syntax().leaf_text().unwrap()
257 } 253 }
@@ -265,36 +261,36 @@ impl<'a> Whitespace<'a> {
265 } 261 }
266} 262}
267 263
268impl<'a> Name<'a> { 264impl Name {
269 pub fn text(&self) -> SmolStr { 265 pub fn text(&self) -> SmolStr {
270 let ident = self.syntax().first_child().unwrap(); 266 let ident = self.syntax().first_child().unwrap();
271 ident.leaf_text().unwrap().clone() 267 ident.leaf_text().unwrap().clone()
272 } 268 }
273} 269}
274 270
275impl<'a> NameRef<'a> { 271impl NameRef {
276 pub fn text(&self) -> SmolStr { 272 pub fn text(&self) -> SmolStr {
277 let ident = self.syntax().first_child().unwrap(); 273 let ident = self.syntax().first_child().unwrap();
278 ident.leaf_text().unwrap().clone() 274 ident.leaf_text().unwrap().clone()
279 } 275 }
280} 276}
281 277
282impl<'a> ImplBlock<'a> { 278impl ImplBlock {
283 pub fn target_type(self) -> Option<TypeRef<'a>> { 279 pub fn target_type(&self) -> Option<&TypeRef> {
284 match self.target() { 280 match self.target() {
285 (Some(t), None) | (_, Some(t)) => Some(t), 281 (Some(t), None) | (_, Some(t)) => Some(t),
286 _ => None, 282 _ => None,
287 } 283 }
288 } 284 }
289 285
290 pub fn target_trait(self) -> Option<TypeRef<'a>> { 286 pub fn target_trait(&self) -> Option<&TypeRef> {
291 match self.target() { 287 match self.target() {
292 (Some(t), Some(_)) => Some(t), 288 (Some(t), Some(_)) => Some(t),
293 _ => None, 289 _ => None,
294 } 290 }
295 } 291 }
296 292
297 fn target(self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) { 293 fn target(&self) -> (Option<&TypeRef>, Option<&TypeRef>) {
298 let mut types = children(self); 294 let mut types = children(self);
299 let first = types.next(); 295 let first = types.next();
300 let second = types.next(); 296 let second = types.next();
@@ -302,8 +298,8 @@ impl<'a> ImplBlock<'a> {
302 } 298 }
303} 299}
304 300
305impl<'a> Module<'a> { 301impl Module {
306 pub fn has_semi(self) -> bool { 302 pub fn has_semi(&self) -> bool {
307 match self.syntax().last_child() { 303 match self.syntax().last_child() {
308 None => false, 304 None => false,
309 Some(node) => node.kind() == SEMI, 305 Some(node) => node.kind() == SEMI,
@@ -311,8 +307,8 @@ impl<'a> Module<'a> {
311 } 307 }
312} 308}
313 309
314impl<'a> LetStmt<'a> { 310impl LetStmt {
315 pub fn has_semi(self) -> bool { 311 pub fn has_semi(&self) -> bool {
316 match self.syntax().last_child() { 312 match self.syntax().last_child() {
317 None => false, 313 None => false,
318 Some(node) => node.kind() == SEMI, 314 Some(node) => node.kind() == SEMI,
@@ -320,35 +316,35 @@ impl<'a> LetStmt<'a> {
320 } 316 }
321} 317}
322 318
323impl<'a> IfExpr<'a> { 319impl IfExpr {
324 pub fn then_branch(self) -> Option<Block<'a>> { 320 pub fn then_branch(&self) -> Option<&Block> {
325 self.blocks().nth(0) 321 self.blocks().nth(0)
326 } 322 }
327 pub fn else_branch(self) -> Option<Block<'a>> { 323 pub fn else_branch(&self) -> Option<&Block> {
328 self.blocks().nth(1) 324 self.blocks().nth(1)
329 } 325 }
330 fn blocks(self) -> AstChildren<'a, Block<'a>> { 326 fn blocks(&self) -> AstChildren<Block> {
331 children(self) 327 children(self)
332 } 328 }
333} 329}
334 330
335#[derive(Debug, Clone, Copy, PartialEq, Eq)] 331#[derive(Debug, Clone, Copy, PartialEq, Eq)]
336pub enum PathSegmentKind<'a> { 332pub enum PathSegmentKind<'a> {
337 Name(NameRef<'a>), 333 Name(&'a NameRef),
338 SelfKw, 334 SelfKw,
339 SuperKw, 335 SuperKw,
340 CrateKw, 336 CrateKw,
341} 337}
342 338
343impl<'a> PathSegment<'a> { 339impl PathSegment {
344 pub fn parent_path(self) -> Path<'a> { 340 pub fn parent_path(&self) -> &Path {
345 self.syntax() 341 self.syntax()
346 .parent() 342 .parent()
347 .and_then(Path::cast) 343 .and_then(Path::cast)
348 .expect("segments are always nested in paths") 344 .expect("segments are always nested in paths")
349 } 345 }
350 346
351 pub fn kind(self) -> Option<PathSegmentKind<'a>> { 347 pub fn kind(&self) -> Option<PathSegmentKind> {
352 let res = if let Some(name_ref) = self.name_ref() { 348 let res = if let Some(name_ref) = self.name_ref() {
353 PathSegmentKind::Name(name_ref) 349 PathSegmentKind::Name(name_ref)
354 } else { 350 } else {
@@ -363,20 +359,20 @@ impl<'a> PathSegment<'a> {
363 } 359 }
364} 360}
365 361
366impl<'a> Path<'a> { 362impl Path {
367 pub fn parent_path(self) -> Option<Path<'a>> { 363 pub fn parent_path(&self) -> Option<&Path> {
368 self.syntax().parent().and_then(Path::cast) 364 self.syntax().parent().and_then(Path::cast)
369 } 365 }
370} 366}
371 367
372impl<'a> UseTree<'a> { 368impl UseTree {
373 pub fn has_star(self) -> bool { 369 pub fn has_star(&self) -> bool {
374 self.syntax().children().any(|it| it.kind() == STAR) 370 self.syntax().children().any(|it| it.kind() == STAR)
375 } 371 }
376} 372}
377 373
378impl<'a> UseTreeList<'a> { 374impl UseTreeList {
379 pub fn parent_use_tree(self) -> UseTree<'a> { 375 pub fn parent_use_tree(&self) -> &UseTree {
380 self.syntax() 376 self.syntax()
381 .parent() 377 .parent()
382 .and_then(UseTree::cast) 378 .and_then(UseTree::cast)
@@ -384,22 +380,22 @@ impl<'a> UseTreeList<'a> {
384 } 380 }
385} 381}
386 382
387fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { 383fn child_opt<P: AstNode, C: AstNode>(parent: &P) -> Option<&C> {
388 children(parent).next() 384 children(parent).next()
389} 385}
390 386
391fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> { 387fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> {
392 AstChildren::new(parent.syntax()) 388 AstChildren::new(parent.syntax())
393} 389}
394 390
395#[derive(Debug)] 391#[derive(Debug)]
396pub struct AstChildren<'a, N> { 392pub struct AstChildren<'a, N> {
397 inner: SyntaxNodeChildren<RefRoot<'a>>, 393 inner: SyntaxNodeChildren<'a>,
398 ph: PhantomData<N>, 394 ph: PhantomData<N>,
399} 395}
400 396
401impl<'a, N> AstChildren<'a, N> { 397impl<'a, N> AstChildren<'a, N> {
402 fn new(parent: SyntaxNodeRef<'a>) -> Self { 398 fn new(parent: &'a SyntaxNode) -> Self {
403 AstChildren { 399 AstChildren {
404 inner: parent.children(), 400 inner: parent.children(),
405 ph: PhantomData, 401 ph: PhantomData,
@@ -407,9 +403,9 @@ impl<'a, N> AstChildren<'a, N> {
407 } 403 }
408} 404}
409 405
410impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { 406impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> {
411 type Item = N; 407 type Item = &'a N;
412 fn next(&mut self) -> Option<N> { 408 fn next(&mut self) -> Option<&'a N> {
413 loop { 409 loop {
414 if let Some(n) = N::cast(self.inner.next()?) { 410 if let Some(n) = N::cast(self.inner.next()?) {
415 return Some(n); 411 return Some(n);
@@ -420,13 +416,13 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> {
420 416
421#[derive(Debug, Clone, PartialEq, Eq)] 417#[derive(Debug, Clone, PartialEq, Eq)]
422pub enum StructFlavor<'a> { 418pub enum StructFlavor<'a> {
423 Tuple(PosFieldList<'a>), 419 Tuple(&'a PosFieldList),
424 Named(NamedFieldDefList<'a>), 420 Named(&'a NamedFieldDefList),
425 Unit, 421 Unit,
426} 422}
427 423
428impl<'a> StructFlavor<'a> { 424impl StructFlavor<'_> {
429 fn from_node<N: AstNode<'a>>(node: N) -> StructFlavor<'a> { 425 fn from_node<N: AstNode>(node: &N) -> StructFlavor {
430 if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { 426 if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) {
431 StructFlavor::Named(nfdl) 427 StructFlavor::Named(nfdl)
432 } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { 428 } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) {
@@ -437,31 +433,31 @@ impl<'a> StructFlavor<'a> {
437 } 433 }
438} 434}
439 435
440impl<'a> StructDef<'a> { 436impl StructDef {
441 pub fn flavor(self) -> StructFlavor<'a> { 437 pub fn flavor(&self) -> StructFlavor {
442 StructFlavor::from_node(self) 438 StructFlavor::from_node(self)
443 } 439 }
444} 440}
445 441
446impl<'a> EnumVariant<'a> { 442impl EnumVariant {
447 pub fn flavor(self) -> StructFlavor<'a> { 443 pub fn flavor(&self) -> StructFlavor {
448 StructFlavor::from_node(self) 444 StructFlavor::from_node(self)
449 } 445 }
450} 446}
451 447
452impl<'a> PointerType<'a> { 448impl PointerType {
453 pub fn is_mut(&self) -> bool { 449 pub fn is_mut(&self) -> bool {
454 self.syntax().children().any(|n| n.kind() == MUT_KW) 450 self.syntax().children().any(|n| n.kind() == MUT_KW)
455 } 451 }
456} 452}
457 453
458impl<'a> ReferenceType<'a> { 454impl ReferenceType {
459 pub fn is_mut(&self) -> bool { 455 pub fn is_mut(&self) -> bool {
460 self.syntax().children().any(|n| n.kind() == MUT_KW) 456 self.syntax().children().any(|n| n.kind() == MUT_KW)
461 } 457 }
462} 458}
463 459
464impl<'a> RefExpr<'a> { 460impl RefExpr {
465 pub fn is_mut(&self) -> bool { 461 pub fn is_mut(&self) -> bool {
466 self.syntax().children().any(|n| n.kind() == MUT_KW) 462 self.syntax().children().any(|n| n.kind() == MUT_KW)
467 } 463 }
@@ -477,7 +473,7 @@ pub enum PrefixOp {
477 Neg, 473 Neg,
478} 474}
479 475
480impl<'a> PrefixExpr<'a> { 476impl PrefixExpr {
481 pub fn op(&self) -> Option<PrefixOp> { 477 pub fn op(&self) -> Option<PrefixOp> {
482 match self.syntax().first_child()?.kind() { 478 match self.syntax().first_child()?.kind() {
483 STAR => Some(PrefixOp::Deref), 479 STAR => Some(PrefixOp::Deref),
@@ -552,7 +548,7 @@ pub enum BinOp {
552 BitXorAssign, 548 BitXorAssign,
553} 549}
554 550
555impl<'a> BinExpr<'a> { 551impl BinExpr {
556 pub fn op(&self) -> Option<BinOp> { 552 pub fn op(&self) -> Option<BinOp> {
557 self.syntax() 553 self.syntax()
558 .children() 554 .children()
@@ -592,15 +588,15 @@ impl<'a> BinExpr<'a> {
592 .next() 588 .next()
593 } 589 }
594 590
595 pub fn lhs(self) -> Option<Expr<'a>> { 591 pub fn lhs(&self) -> Option<&Expr> {
596 children(self).nth(0) 592 children(self).nth(0)
597 } 593 }
598 594
599 pub fn rhs(self) -> Option<Expr<'a>> { 595 pub fn rhs(&self) -> Option<&Expr> {
600 children(self).nth(1) 596 children(self).nth(1)
601 } 597 }
602 598
603 pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) { 599 pub fn sub_exprs(&self) -> (Option<&Expr>, Option<&Expr>) {
604 let mut children = children(self); 600 let mut children = children(self);
605 let first = children.next(); 601 let first = children.next();
606 let second = children.next(); 602 let second = children.next();
@@ -618,7 +614,7 @@ pub enum SelfParamFlavor {
618 MutRef, 614 MutRef,
619} 615}
620 616
621impl<'a> SelfParam<'a> { 617impl SelfParam {
622 pub fn flavor(&self) -> SelfParamFlavor { 618 pub fn flavor(&self) -> SelfParamFlavor {
623 let borrowed = self.syntax().children().any(|n| n.kind() == AMP); 619 let borrowed = self.syntax().children().any(|n| n.kind() == AMP);
624 if borrowed { 620 if borrowed {
@@ -641,7 +637,7 @@ impl<'a> SelfParam<'a> {
641 637
642#[test] 638#[test]
643fn test_doc_comment_of_items() { 639fn test_doc_comment_of_items() {
644 let file = SourceFileNode::parse( 640 let file = SourceFile::parse(
645 r#" 641 r#"
646 //! doc 642 //! doc
647 // non-doc 643 // non-doc
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 24f72393a..5e96ab142 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -9,4648 +9,3387 @@
9 9
10#![cfg_attr(rustfmt, rustfmt_skip)] 10#![cfg_attr(rustfmt, rustfmt_skip)]
11 11
12use std::hash::{Hash, Hasher}; 12use rowan::TransparentNewType;
13 13
14use crate::{ 14use 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)]
23pub struct ArgListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 22#[repr(transparent)]
24 pub(crate) syntax: SyntaxNode<R>, 23pub struct ArgList {
24 pub(crate) syntax: SyntaxNode,
25} 25}
26pub type ArgList<'a> = ArgListNode<RefRoot<'a>>; 26unsafe impl TransparentNewType for ArgList {
27 27 type Repr = rowan::SyntaxNode<RaTypes>;
28impl<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}
31impl<R: TreeRoot<RaTypes>> Eq for ArgListNode<R> {}
32impl<R: TreeRoot<RaTypes>> Hash for ArgListNode<R> {
33 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
34} 28}
35 29
36impl<'a> AstNode<'a> for ArgList<'a> { 30impl 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
46impl<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
56impl<'a> ArgList<'a> { 42impl 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)]
64pub struct ArrayExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 50#[repr(transparent)]
65 pub(crate) syntax: SyntaxNode<R>, 51pub struct ArrayExpr {
52 pub(crate) syntax: SyntaxNode,
66} 53}
67pub type ArrayExpr<'a> = ArrayExprNode<RefRoot<'a>>; 54unsafe impl TransparentNewType for ArrayExpr {
68 55 type Repr = rowan::SyntaxNode<RaTypes>;
69impl<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}
72impl<R: TreeRoot<RaTypes>> Eq for ArrayExprNode<R> {}
73impl<R: TreeRoot<RaTypes>> Hash for ArrayExprNode<R> {
74 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
75} 56}
76 57
77impl<'a> AstNode<'a> for ArrayExpr<'a> { 58impl 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
87impl<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
97impl<'a> ArrayExpr<'a> {} 70impl ArrayExpr {}
98 71
99// ArrayType 72// ArrayType
100#[derive(Debug, Clone, Copy,)] 73#[derive(Debug, PartialEq, Eq, Hash)]
101pub struct ArrayTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 74#[repr(transparent)]
102 pub(crate) syntax: SyntaxNode<R>, 75pub struct ArrayType {
103} 76 pub(crate) syntax: SyntaxNode,
104pub type ArrayType<'a> = ArrayTypeNode<RefRoot<'a>>;
105
106impl<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}
109impl<R: TreeRoot<RaTypes>> Eq for ArrayTypeNode<R> {} 78unsafe impl TransparentNewType for ArrayType {
110impl<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
114impl<'a> AstNode<'a> for ArrayType<'a> { 82impl 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
124impl<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 94impl ArrayType {
134impl<'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)]
146pub struct AttrNode<R: TreeRoot<RaTypes> = OwnedRoot> { 106#[repr(transparent)]
147 pub(crate) syntax: SyntaxNode<R>, 107pub struct Attr {
148} 108 pub(crate) syntax: SyntaxNode,
149pub type Attr<'a> = AttrNode<RefRoot<'a>>;
150
151impl<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}
154impl<R: TreeRoot<RaTypes>> Eq for AttrNode<R> {} 110unsafe impl TransparentNewType for Attr {
155impl<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
159impl<'a> AstNode<'a> for Attr<'a> { 114impl 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
169impl<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
179impl<'a> Attr<'a> { 126impl 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)]
187pub struct BinExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 134#[repr(transparent)]
188 pub(crate) syntax: SyntaxNode<R>, 135pub struct BinExpr {
189} 136 pub(crate) syntax: SyntaxNode,
190pub type BinExpr<'a> = BinExprNode<RefRoot<'a>>;
191
192impl<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}
195impl<R: TreeRoot<RaTypes>> Eq for BinExprNode<R> {} 138unsafe impl TransparentNewType for BinExpr {
196impl<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
200impl<'a> AstNode<'a> for BinExpr<'a> { 142impl 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
210impl<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
220impl<'a> BinExpr<'a> {} 154impl BinExpr {}
221 155
222// BindPat 156// BindPat
223#[derive(Debug, Clone, Copy,)] 157#[derive(Debug, PartialEq, Eq, Hash)]
224pub struct BindPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 158#[repr(transparent)]
225 pub(crate) syntax: SyntaxNode<R>, 159pub struct BindPat {
160 pub(crate) syntax: SyntaxNode,
226} 161}
227pub type BindPat<'a> = BindPatNode<RefRoot<'a>>; 162unsafe impl TransparentNewType for BindPat {
228 163 type Repr = rowan::SyntaxNode<RaTypes>;
229impl<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}
232impl<R: TreeRoot<RaTypes>> Eq for BindPatNode<R> {}
233impl<R: TreeRoot<RaTypes>> Hash for BindPatNode<R> {
234 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
235} 164}
236 165
237impl<'a> AstNode<'a> for BindPat<'a> { 166impl 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
247impl<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
257impl<'a> ast::NameOwner<'a> for BindPat<'a> {} 178impl ast::NameOwner for BindPat {}
258impl<'a> BindPat<'a> {} 179impl BindPat {}
259 180
260// Block 181// Block
261#[derive(Debug, Clone, Copy,)] 182#[derive(Debug, PartialEq, Eq, Hash)]
262pub struct BlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { 183#[repr(transparent)]
263 pub(crate) syntax: SyntaxNode<R>, 184pub struct Block {
264} 185 pub(crate) syntax: SyntaxNode,
265pub type Block<'a> = BlockNode<RefRoot<'a>>;
266
267impl<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}
270impl<R: TreeRoot<RaTypes>> Eq for BlockNode<R> {} 187unsafe impl TransparentNewType for Block {
271impl<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
275impl<'a> AstNode<'a> for Block<'a> { 191impl 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
285impl<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 203impl Block {
295impl<'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)]
307pub struct BlockExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 215#[repr(transparent)]
308 pub(crate) syntax: SyntaxNode<R>, 216pub struct BlockExpr {
217 pub(crate) syntax: SyntaxNode,
309} 218}
310pub type BlockExpr<'a> = BlockExprNode<RefRoot<'a>>; 219unsafe impl TransparentNewType for BlockExpr {
311 220 type Repr = rowan::SyntaxNode<RaTypes>;
312impl<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}
315impl<R: TreeRoot<RaTypes>> Eq for BlockExprNode<R> {}
316impl<R: TreeRoot<RaTypes>> Hash for BlockExprNode<R> {
317 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
318} 221}
319 222
320impl<'a> AstNode<'a> for BlockExpr<'a> { 223impl 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
330impl<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
340impl<'a> BlockExpr<'a> { 235impl 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)]
348pub struct BreakExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 243#[repr(transparent)]
349 pub(crate) syntax: SyntaxNode<R>, 244pub struct BreakExpr {
245 pub(crate) syntax: SyntaxNode,
350} 246}
351pub type BreakExpr<'a> = BreakExprNode<RefRoot<'a>>; 247unsafe impl TransparentNewType for BreakExpr {
352 248 type Repr = rowan::SyntaxNode<RaTypes>;
353impl<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}
356impl<R: TreeRoot<RaTypes>> Eq for BreakExprNode<R> {}
357impl<R: TreeRoot<RaTypes>> Hash for BreakExprNode<R> {
358 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
359} 249}
360 250
361impl<'a> AstNode<'a> for BreakExpr<'a> { 251impl 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
371impl<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
381impl<'a> BreakExpr<'a> { 263impl 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)]
389pub struct ByteNode<R: TreeRoot<RaTypes> = OwnedRoot> { 271#[repr(transparent)]
390 pub(crate) syntax: SyntaxNode<R>, 272pub struct Byte {
273 pub(crate) syntax: SyntaxNode,
391} 274}
392pub type Byte<'a> = ByteNode<RefRoot<'a>>; 275unsafe impl TransparentNewType for Byte {
393 276 type Repr = rowan::SyntaxNode<RaTypes>;
394impl<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}
397impl<R: TreeRoot<RaTypes>> Eq for ByteNode<R> {}
398impl<R: TreeRoot<RaTypes>> Hash for ByteNode<R> {
399 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
400} 277}
401 278
402impl<'a> AstNode<'a> for Byte<'a> { 279impl 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
412impl<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
422impl<'a> Byte<'a> {} 291impl Byte {}
423 292
424// ByteString 293// ByteString
425#[derive(Debug, Clone, Copy,)] 294#[derive(Debug, PartialEq, Eq, Hash)]
426pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> { 295#[repr(transparent)]
427 pub(crate) syntax: SyntaxNode<R>, 296pub struct ByteString {
428} 297 pub(crate) syntax: SyntaxNode,
429pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>;
430
431impl<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} 298}
434impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {} 299unsafe impl TransparentNewType for ByteString {
435impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> { 300 type Repr = rowan::SyntaxNode<RaTypes>;
436 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
437} 301}
438 302
439impl<'a> AstNode<'a> for ByteString<'a> { 303impl AstNode for ByteString {
440 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 304 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
441 match syntax.kind() { 305 match syntax.kind() {
442 BYTE_STRING => Some(ByteString { syntax }), 306 BYTE_STRING => Some(ByteString::from_repr(syntax.into_repr())),
443 _ => None, 307 _ => None,
444 } 308 }
445 } 309 }
446 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 310 fn syntax(&self) -> &SyntaxNode { &self.syntax }
447} 311 fn to_owned(&self) -> TreePtr<ByteString> { TreePtr::cast(self.syntax.to_owned()) }
448
449impl<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} 312}
457 313
458 314
459impl<'a> ByteString<'a> {} 315impl ByteString {}
460 316
461// CallExpr 317// CallExpr
462#[derive(Debug, Clone, Copy,)] 318#[derive(Debug, PartialEq, Eq, Hash)]
463pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 319#[repr(transparent)]
464 pub(crate) syntax: SyntaxNode<R>, 320pub struct CallExpr {
465} 321 pub(crate) syntax: SyntaxNode,
466pub type CallExpr<'a> = CallExprNode<RefRoot<'a>>;
467
468impl<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} 322}
471impl<R: TreeRoot<RaTypes>> Eq for CallExprNode<R> {} 323unsafe impl TransparentNewType for CallExpr {
472impl<R: TreeRoot<RaTypes>> Hash for CallExprNode<R> { 324 type Repr = rowan::SyntaxNode<RaTypes>;
473 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
474} 325}
475 326
476impl<'a> AstNode<'a> for CallExpr<'a> { 327impl AstNode for CallExpr {
477 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 328 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
478 match syntax.kind() { 329 match syntax.kind() {
479 CALL_EXPR => Some(CallExpr { syntax }), 330 CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())),
480 _ => None, 331 _ => None,
481 } 332 }
482 } 333 }
483 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 334 fn syntax(&self) -> &SyntaxNode { &self.syntax }
484} 335 fn to_owned(&self) -> TreePtr<CallExpr> { TreePtr::cast(self.syntax.to_owned()) }
485
486impl<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} 336}
494 337
495 338
496impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} 339impl ast::ArgListOwner for CallExpr {}
497impl<'a> CallExpr<'a> { 340impl CallExpr {
498 pub fn expr(self) -> Option<Expr<'a>> { 341 pub fn expr(&self) -> Option<&Expr> {
499 super::child_opt(self) 342 super::child_opt(self)
500 } 343 }
501} 344}
502 345
503// CastExpr 346// CastExpr
504#[derive(Debug, Clone, Copy,)] 347#[derive(Debug, PartialEq, Eq, Hash)]
505pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 348#[repr(transparent)]
506 pub(crate) syntax: SyntaxNode<R>, 349pub struct CastExpr {
350 pub(crate) syntax: SyntaxNode,
507} 351}
508pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; 352unsafe impl TransparentNewType for CastExpr {
509 353 type Repr = rowan::SyntaxNode<RaTypes>;
510impl<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}
513impl<R: TreeRoot<RaTypes>> Eq for CastExprNode<R> {}
514impl<R: TreeRoot<RaTypes>> Hash for CastExprNode<R> {
515 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
516} 354}
517 355
518impl<'a> AstNode<'a> for CastExpr<'a> { 356impl AstNode for CastExpr {
519 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 357 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
520 match syntax.kind() { 358 match syntax.kind() {
521 CAST_EXPR => Some(CastExpr { syntax }), 359 CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())),
522 _ => None, 360 _ => None,
523 } 361 }
524 } 362 }
525 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 363 fn syntax(&self) -> &SyntaxNode { &self.syntax }
526} 364 fn to_owned(&self) -> TreePtr<CastExpr> { TreePtr::cast(self.syntax.to_owned()) }
527
528impl<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} 365}
536 366
537 367
538impl<'a> CastExpr<'a> { 368impl CastExpr {
539 pub fn expr(self) -> Option<Expr<'a>> { 369 pub fn expr(&self) -> Option<&Expr> {
540 super::child_opt(self) 370 super::child_opt(self)
541 } 371 }
542 372
543 pub fn type_ref(self) -> Option<TypeRef<'a>> { 373 pub fn type_ref(&self) -> Option<&TypeRef> {
544 super::child_opt(self) 374 super::child_opt(self)
545 } 375 }
546} 376}
547 377
548// Char 378// Char
549#[derive(Debug, Clone, Copy,)] 379#[derive(Debug, PartialEq, Eq, Hash)]
550pub struct CharNode<R: TreeRoot<RaTypes> = OwnedRoot> { 380#[repr(transparent)]
551 pub(crate) syntax: SyntaxNode<R>, 381pub struct Char {
552} 382 pub(crate) syntax: SyntaxNode,
553pub type Char<'a> = CharNode<RefRoot<'a>>;
554
555impl<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} 383}
558impl<R: TreeRoot<RaTypes>> Eq for CharNode<R> {} 384unsafe impl TransparentNewType for Char {
559impl<R: TreeRoot<RaTypes>> Hash for CharNode<R> { 385 type Repr = rowan::SyntaxNode<RaTypes>;
560 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
561} 386}
562 387
563impl<'a> AstNode<'a> for Char<'a> { 388impl AstNode for Char {
564 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 389 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
565 match syntax.kind() { 390 match syntax.kind() {
566 CHAR => Some(Char { syntax }), 391 CHAR => Some(Char::from_repr(syntax.into_repr())),
567 _ => None, 392 _ => None,
568 } 393 }
569 } 394 }
570 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 395 fn syntax(&self) -> &SyntaxNode { &self.syntax }
396 fn to_owned(&self) -> TreePtr<Char> { TreePtr::cast(self.syntax.to_owned()) }
571} 397}
572 398
573impl<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 399
582 400impl Char {}
583impl<'a> Char<'a> {}
584 401
585// Comment 402// Comment
586#[derive(Debug, Clone, Copy,)] 403#[derive(Debug, PartialEq, Eq, Hash)]
587pub struct CommentNode<R: TreeRoot<RaTypes> = OwnedRoot> { 404#[repr(transparent)]
588 pub(crate) syntax: SyntaxNode<R>, 405pub struct Comment {
589} 406 pub(crate) syntax: SyntaxNode,
590pub type Comment<'a> = CommentNode<RefRoot<'a>>;
591
592impl<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} 407}
595impl<R: TreeRoot<RaTypes>> Eq for CommentNode<R> {} 408unsafe impl TransparentNewType for Comment {
596impl<R: TreeRoot<RaTypes>> Hash for CommentNode<R> { 409 type Repr = rowan::SyntaxNode<RaTypes>;
597 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
598} 410}
599 411
600impl<'a> AstNode<'a> for Comment<'a> { 412impl AstNode for Comment {
601 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 413 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
602 match syntax.kind() { 414 match syntax.kind() {
603 COMMENT => Some(Comment { syntax }), 415 COMMENT => Some(Comment::from_repr(syntax.into_repr())),
604 _ => None, 416 _ => None,
605 } 417 }
606 } 418 }
607 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 419 fn syntax(&self) -> &SyntaxNode { &self.syntax }
608} 420 fn to_owned(&self) -> TreePtr<Comment> { TreePtr::cast(self.syntax.to_owned()) }
609
610impl<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} 421}
618 422
619 423
620impl<'a> Comment<'a> {} 424impl Comment {}
621 425
622// Condition 426// Condition
623#[derive(Debug, Clone, Copy,)] 427#[derive(Debug, PartialEq, Eq, Hash)]
624pub struct ConditionNode<R: TreeRoot<RaTypes> = OwnedRoot> { 428#[repr(transparent)]
625 pub(crate) syntax: SyntaxNode<R>, 429pub struct Condition {
430 pub(crate) syntax: SyntaxNode,
626} 431}
627pub type Condition<'a> = ConditionNode<RefRoot<'a>>; 432unsafe impl TransparentNewType for Condition {
628 433 type Repr = rowan::SyntaxNode<RaTypes>;
629impl<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}
632impl<R: TreeRoot<RaTypes>> Eq for ConditionNode<R> {}
633impl<R: TreeRoot<RaTypes>> Hash for ConditionNode<R> {
634 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
635} 434}
636 435
637impl<'a> AstNode<'a> for Condition<'a> { 436impl AstNode for Condition {
638 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 437 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
639 match syntax.kind() { 438 match syntax.kind() {
640 CONDITION => Some(Condition { syntax }), 439 CONDITION => Some(Condition::from_repr(syntax.into_repr())),
641 _ => None, 440 _ => None,
642 } 441 }
643 } 442 }
644 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 443 fn syntax(&self) -> &SyntaxNode { &self.syntax }
645} 444 fn to_owned(&self) -> TreePtr<Condition> { TreePtr::cast(self.syntax.to_owned()) }
646
647impl<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} 445}
655 446
656 447
657impl<'a> Condition<'a> { 448impl Condition {
658 pub fn pat(self) -> Option<Pat<'a>> { 449 pub fn pat(&self) -> Option<&Pat> {
659 super::child_opt(self) 450 super::child_opt(self)
660 } 451 }
661 452
662 pub fn expr(self) -> Option<Expr<'a>> { 453 pub fn expr(&self) -> Option<&Expr> {
663 super::child_opt(self) 454 super::child_opt(self)
664 } 455 }
665} 456}
666 457
667// ConstDef 458// ConstDef
668#[derive(Debug, Clone, Copy,)] 459#[derive(Debug, PartialEq, Eq, Hash)]
669pub struct ConstDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 460#[repr(transparent)]
670 pub(crate) syntax: SyntaxNode<R>, 461pub struct ConstDef {
462 pub(crate) syntax: SyntaxNode,
671} 463}
672pub type ConstDef<'a> = ConstDefNode<RefRoot<'a>>; 464unsafe impl TransparentNewType for ConstDef {
673 465 type Repr = rowan::SyntaxNode<RaTypes>;
674impl<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}
677impl<R: TreeRoot<RaTypes>> Eq for ConstDefNode<R> {}
678impl<R: TreeRoot<RaTypes>> Hash for ConstDefNode<R> {
679 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
680} 466}
681 467
682impl<'a> AstNode<'a> for ConstDef<'a> { 468impl AstNode for ConstDef {
683 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 469 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
684 match syntax.kind() { 470 match syntax.kind() {
685 CONST_DEF => Some(ConstDef { syntax }), 471 CONST_DEF => Some(ConstDef::from_repr(syntax.into_repr())),
686 _ => None, 472 _ => None,
687 } 473 }
688 } 474 }
689 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 475 fn syntax(&self) -> &SyntaxNode { &self.syntax }
690} 476 fn to_owned(&self) -> TreePtr<ConstDef> { TreePtr::cast(self.syntax.to_owned()) }
691
692impl<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} 477}
700 478
701 479
702impl<'a> ast::VisibilityOwner<'a> for ConstDef<'a> {} 480impl ast::VisibilityOwner for ConstDef {}
703impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} 481impl ast::NameOwner for ConstDef {}
704impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} 482impl ast::TypeParamsOwner for ConstDef {}
705impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} 483impl ast::AttrsOwner for ConstDef {}
706impl<'a> ast::DocCommentsOwner<'a> for ConstDef<'a> {} 484impl ast::DocCommentsOwner for ConstDef {}
707impl<'a> ConstDef<'a> {} 485impl ConstDef {}
708 486
709// ContinueExpr 487// ContinueExpr
710#[derive(Debug, Clone, Copy,)] 488#[derive(Debug, PartialEq, Eq, Hash)]
711pub struct ContinueExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 489#[repr(transparent)]
712 pub(crate) syntax: SyntaxNode<R>, 490pub struct ContinueExpr {
491 pub(crate) syntax: SyntaxNode,
713} 492}
714pub type ContinueExpr<'a> = ContinueExprNode<RefRoot<'a>>; 493unsafe impl TransparentNewType for ContinueExpr {
715 494 type Repr = rowan::SyntaxNode<RaTypes>;
716impl<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}
719impl<R: TreeRoot<RaTypes>> Eq for ContinueExprNode<R> {}
720impl<R: TreeRoot<RaTypes>> Hash for ContinueExprNode<R> {
721 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
722} 495}
723 496
724impl<'a> AstNode<'a> for ContinueExpr<'a> { 497impl AstNode for ContinueExpr {
725 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 498 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
726 match syntax.kind() { 499 match syntax.kind() {
727 CONTINUE_EXPR => Some(ContinueExpr { syntax }), 500 CONTINUE_EXPR => Some(ContinueExpr::from_repr(syntax.into_repr())),
728 _ => None, 501 _ => None,
729 } 502 }
730 } 503 }
731 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 504 fn syntax(&self) -> &SyntaxNode { &self.syntax }
505 fn to_owned(&self) -> TreePtr<ContinueExpr> { TreePtr::cast(self.syntax.to_owned()) }
732} 506}
733 507
734impl<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 508
743 509impl ContinueExpr {}
744impl<'a> ContinueExpr<'a> {}
745 510
746// DynTraitType 511// DynTraitType
747#[derive(Debug, Clone, Copy,)] 512#[derive(Debug, PartialEq, Eq, Hash)]
748pub struct DynTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 513#[repr(transparent)]
749 pub(crate) syntax: SyntaxNode<R>, 514pub struct DynTraitType {
750} 515 pub(crate) syntax: SyntaxNode,
751pub type DynTraitType<'a> = DynTraitTypeNode<RefRoot<'a>>;
752
753impl<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} 516}
756impl<R: TreeRoot<RaTypes>> Eq for DynTraitTypeNode<R> {} 517unsafe impl TransparentNewType for DynTraitType {
757impl<R: TreeRoot<RaTypes>> Hash for DynTraitTypeNode<R> { 518 type Repr = rowan::SyntaxNode<RaTypes>;
758 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
759} 519}
760 520
761impl<'a> AstNode<'a> for DynTraitType<'a> { 521impl AstNode for DynTraitType {
762 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 522 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
763 match syntax.kind() { 523 match syntax.kind() {
764 DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), 524 DYN_TRAIT_TYPE => Some(DynTraitType::from_repr(syntax.into_repr())),
765 _ => None, 525 _ => None,
766 } 526 }
767 } 527 }
768 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 528 fn syntax(&self) -> &SyntaxNode { &self.syntax }
529 fn to_owned(&self) -> TreePtr<DynTraitType> { TreePtr::cast(self.syntax.to_owned()) }
769} 530}
770 531
771impl<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 532
780 533impl DynTraitType {}
781impl<'a> DynTraitType<'a> {}
782 534
783// EnumDef 535// EnumDef
784#[derive(Debug, Clone, Copy,)] 536#[derive(Debug, PartialEq, Eq, Hash)]
785pub struct EnumDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 537#[repr(transparent)]
786 pub(crate) syntax: SyntaxNode<R>, 538pub struct EnumDef {
787} 539 pub(crate) syntax: SyntaxNode,
788pub type EnumDef<'a> = EnumDefNode<RefRoot<'a>>;
789
790impl<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} 540}
793impl<R: TreeRoot<RaTypes>> Eq for EnumDefNode<R> {} 541unsafe impl TransparentNewType for EnumDef {
794impl<R: TreeRoot<RaTypes>> Hash for EnumDefNode<R> { 542 type Repr = rowan::SyntaxNode<RaTypes>;
795 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
796} 543}
797 544
798impl<'a> AstNode<'a> for EnumDef<'a> { 545impl AstNode for EnumDef {
799 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 546 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
800 match syntax.kind() { 547 match syntax.kind() {
801 ENUM_DEF => Some(EnumDef { syntax }), 548 ENUM_DEF => Some(EnumDef::from_repr(syntax.into_repr())),
802 _ => None, 549 _ => None,
803 } 550 }
804 } 551 }
805 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 552 fn syntax(&self) -> &SyntaxNode { &self.syntax }
806} 553 fn to_owned(&self) -> TreePtr<EnumDef> { TreePtr::cast(self.syntax.to_owned()) }
807
808impl<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} 554}
816 555
817 556
818impl<'a> ast::VisibilityOwner<'a> for EnumDef<'a> {} 557impl ast::VisibilityOwner for EnumDef {}
819impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} 558impl ast::NameOwner for EnumDef {}
820impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} 559impl ast::TypeParamsOwner for EnumDef {}
821impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} 560impl ast::AttrsOwner for EnumDef {}
822impl<'a> ast::DocCommentsOwner<'a> for EnumDef<'a> {} 561impl ast::DocCommentsOwner for EnumDef {}
823impl<'a> EnumDef<'a> { 562impl EnumDef {
824 pub fn variant_list(self) -> Option<EnumVariantList<'a>> { 563 pub fn variant_list(&self) -> Option<&EnumVariantList> {
825 super::child_opt(self) 564 super::child_opt(self)
826 } 565 }
827} 566}
828 567
829// EnumVariant 568// EnumVariant
830#[derive(Debug, Clone, Copy,)] 569#[derive(Debug, PartialEq, Eq, Hash)]
831pub struct EnumVariantNode<R: TreeRoot<RaTypes> = OwnedRoot> { 570#[repr(transparent)]
832 pub(crate) syntax: SyntaxNode<R>, 571pub struct EnumVariant {
572 pub(crate) syntax: SyntaxNode,
833} 573}
834pub type EnumVariant<'a> = EnumVariantNode<RefRoot<'a>>; 574unsafe impl TransparentNewType for EnumVariant {
835 575 type Repr = rowan::SyntaxNode<RaTypes>;
836impl<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}
839impl<R: TreeRoot<RaTypes>> Eq for EnumVariantNode<R> {}
840impl<R: TreeRoot<RaTypes>> Hash for EnumVariantNode<R> {
841 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
842} 576}
843 577
844impl<'a> AstNode<'a> for EnumVariant<'a> { 578impl AstNode for EnumVariant {
845 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 579 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
846 match syntax.kind() { 580 match syntax.kind() {
847 ENUM_VARIANT => Some(EnumVariant { syntax }), 581 ENUM_VARIANT => Some(EnumVariant::from_repr(syntax.into_repr())),
848 _ => None, 582 _ => None,
849 } 583 }
850 } 584 }
851 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 585 fn syntax(&self) -> &SyntaxNode { &self.syntax }
852} 586 fn to_owned(&self) -> TreePtr<EnumVariant> { TreePtr::cast(self.syntax.to_owned()) }
853
854impl<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} 587}
862 588
863 589
864impl<'a> ast::NameOwner<'a> for EnumVariant<'a> {} 590impl ast::NameOwner for EnumVariant {}
865impl<'a> EnumVariant<'a> { 591impl EnumVariant {
866 pub fn expr(self) -> Option<Expr<'a>> { 592 pub fn expr(&self) -> Option<&Expr> {
867 super::child_opt(self) 593 super::child_opt(self)
868 } 594 }
869} 595}
870 596
871// EnumVariantList 597// EnumVariantList
872#[derive(Debug, Clone, Copy,)] 598#[derive(Debug, PartialEq, Eq, Hash)]
873pub struct EnumVariantListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 599#[repr(transparent)]
874 pub(crate) syntax: SyntaxNode<R>, 600pub struct EnumVariantList {
875} 601 pub(crate) syntax: SyntaxNode,
876pub type EnumVariantList<'a> = EnumVariantListNode<RefRoot<'a>>;
877
878impl<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} 602}
881impl<R: TreeRoot<RaTypes>> Eq for EnumVariantListNode<R> {} 603unsafe impl TransparentNewType for EnumVariantList {
882impl<R: TreeRoot<RaTypes>> Hash for EnumVariantListNode<R> { 604 type Repr = rowan::SyntaxNode<RaTypes>;
883 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
884} 605}
885 606
886impl<'a> AstNode<'a> for EnumVariantList<'a> { 607impl AstNode for EnumVariantList {
887 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 608 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
888 match syntax.kind() { 609 match syntax.kind() {
889 ENUM_VARIANT_LIST => Some(EnumVariantList { syntax }), 610 ENUM_VARIANT_LIST => Some(EnumVariantList::from_repr(syntax.into_repr())),
890 _ => None, 611 _ => None,
891 } 612 }
892 } 613 }
893 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 614 fn syntax(&self) -> &SyntaxNode { &self.syntax }
615 fn to_owned(&self) -> TreePtr<EnumVariantList> { TreePtr::cast(self.syntax.to_owned()) }
894} 616}
895 617
896impl<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 618
905 619impl EnumVariantList {
906impl<'a> EnumVariantList<'a> { 620 pub fn variants(&self) -> impl Iterator<Item = &EnumVariant> {
907 pub fn variants(self) -> impl Iterator<Item = EnumVariant<'a>> + 'a {
908 super::children(self) 621 super::children(self)
909 } 622 }
910} 623}
911 624
912// Expr 625// Expr
913#[derive(Debug, Clone, Copy, PartialEq, Eq)] 626#[derive(Debug, PartialEq, Eq, Hash)]
914pub enum Expr<'a> { 627#[repr(transparent)]
915 TupleExpr(TupleExpr<'a>), 628pub struct Expr {
916 ArrayExpr(ArrayExpr<'a>), 629 pub(crate) syntax: SyntaxNode,
917 ParenExpr(ParenExpr<'a>), 630}
918 PathExpr(PathExpr<'a>), 631unsafe impl TransparentNewType for Expr {
919 LambdaExpr(LambdaExpr<'a>), 632 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
944impl<'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} 633}
1009 634
1010impl<'a> Expr<'a> {} 635#[derive(Debug, Clone, Copy, PartialEq, Eq)]
636pub enum ExprKind<'a> {
637 TupleExpr(&'a TupleExpr),
638 ArrayExpr(&'a ArrayExpr),
639 ParenExpr(&'a ParenExpr),
640 PathExpr(&'a PathExpr),
641 LambdaExpr(&'a LambdaExpr),
642 IfExpr(&'a IfExpr),
643 LoopExpr(&'a LoopExpr),
644 ForExpr(&'a ForExpr),
645 WhileExpr(&'a WhileExpr),
646 ContinueExpr(&'a ContinueExpr),
647 BreakExpr(&'a BreakExpr),
648 Label(&'a Label),
649 BlockExpr(&'a BlockExpr),
650 ReturnExpr(&'a ReturnExpr),
651 MatchExpr(&'a MatchExpr),
652 StructLit(&'a StructLit),
653 CallExpr(&'a CallExpr),
654 IndexExpr(&'a IndexExpr),
655 MethodCallExpr(&'a MethodCallExpr),
656 FieldExpr(&'a FieldExpr),
657 TryExpr(&'a TryExpr),
658 CastExpr(&'a CastExpr),
659 RefExpr(&'a RefExpr),
660 PrefixExpr(&'a PrefixExpr),
661 RangeExpr(&'a RangeExpr),
662 BinExpr(&'a BinExpr),
663 Literal(&'a Literal),
664}
665
666impl AstNode for Expr {
667 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
668 match syntax.kind() {
669 | TUPLE_EXPR
670 | ARRAY_EXPR
671 | PAREN_EXPR
672 | PATH_EXPR
673 | LAMBDA_EXPR
674 | IF_EXPR
675 | LOOP_EXPR
676 | FOR_EXPR
677 | WHILE_EXPR
678 | CONTINUE_EXPR
679 | BREAK_EXPR
680 | LABEL
681 | BLOCK_EXPR
682 | RETURN_EXPR
683 | MATCH_EXPR
684 | STRUCT_LIT
685 | CALL_EXPR
686 | INDEX_EXPR
687 | METHOD_CALL_EXPR
688 | FIELD_EXPR
689 | TRY_EXPR
690 | CAST_EXPR
691 | REF_EXPR
692 | PREFIX_EXPR
693 | RANGE_EXPR
694 | BIN_EXPR
695 | LITERAL => Some(Expr::from_repr(syntax.into_repr())),
696 _ => None,
697 }
698 }
699 fn syntax(&self) -> &SyntaxNode { &self.syntax }
700 fn to_owned(&self) -> TreePtr<Expr> { TreePtr::cast(self.syntax.to_owned()) }
701}
702
703impl Expr {
704 pub fn kind(&self) -> ExprKind {
705 match self.syntax.kind() {
706 TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(&self.syntax).unwrap()),
707 ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(&self.syntax).unwrap()),
708 PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(&self.syntax).unwrap()),
709 PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(&self.syntax).unwrap()),
710 LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(&self.syntax).unwrap()),
711 IF_EXPR => ExprKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()),
712 LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(&self.syntax).unwrap()),
713 FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(&self.syntax).unwrap()),
714 WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(&self.syntax).unwrap()),
715 CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(&self.syntax).unwrap()),
716 BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(&self.syntax).unwrap()),
717 LABEL => ExprKind::Label(Label::cast(&self.syntax).unwrap()),
718 BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(&self.syntax).unwrap()),
719 RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(&self.syntax).unwrap()),
720 MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(&self.syntax).unwrap()),
721 STRUCT_LIT => ExprKind::StructLit(StructLit::cast(&self.syntax).unwrap()),
722 CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(&self.syntax).unwrap()),
723 INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(&self.syntax).unwrap()),
724 METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()),
725 FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()),
726 TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()),
727 CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()),
728 REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()),
729 PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()),
730 RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()),
731 BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()),
732 LITERAL => ExprKind::Literal(Literal::cast(&self.syntax).unwrap()),
733 _ => unreachable!(),
734 }
735 }
736}
737
738impl Expr {}
1011 739
1012// ExprStmt 740// ExprStmt
1013#[derive(Debug, Clone, Copy,)] 741#[derive(Debug, PartialEq, Eq, Hash)]
1014pub struct ExprStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { 742#[repr(transparent)]
1015 pub(crate) syntax: SyntaxNode<R>, 743pub struct ExprStmt {
744 pub(crate) syntax: SyntaxNode,
1016} 745}
1017pub type ExprStmt<'a> = ExprStmtNode<RefRoot<'a>>; 746unsafe impl TransparentNewType for ExprStmt {
1018 747 type Repr = rowan::SyntaxNode<RaTypes>;
1019impl<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}
1022impl<R: TreeRoot<RaTypes>> Eq for ExprStmtNode<R> {}
1023impl<R: TreeRoot<RaTypes>> Hash for ExprStmtNode<R> {
1024 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1025} 748}
1026 749
1027impl<'a> AstNode<'a> for ExprStmt<'a> { 750impl AstNode for ExprStmt {
1028 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 751 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1029 match syntax.kind() { 752 match syntax.kind() {
1030 EXPR_STMT => Some(ExprStmt { syntax }), 753 EXPR_STMT => Some(ExprStmt::from_repr(syntax.into_repr())),
1031 _ => None, 754 _ => None,
1032 } 755 }
1033 } 756 }
1034 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 757 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1035} 758 fn to_owned(&self) -> TreePtr<ExprStmt> { TreePtr::cast(self.syntax.to_owned()) }
1036
1037impl<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} 759}
1045 760
1046 761
1047impl<'a> ExprStmt<'a> { 762impl ExprStmt {
1048 pub fn expr(self) -> Option<Expr<'a>> { 763 pub fn expr(&self) -> Option<&Expr> {
1049 super::child_opt(self) 764 super::child_opt(self)
1050 } 765 }
1051} 766}
1052 767
1053// ExternCrateItem 768// ExternCrateItem
1054#[derive(Debug, Clone, Copy,)] 769#[derive(Debug, PartialEq, Eq, Hash)]
1055pub struct ExternCrateItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { 770#[repr(transparent)]
1056 pub(crate) syntax: SyntaxNode<R>, 771pub struct ExternCrateItem {
1057} 772 pub(crate) syntax: SyntaxNode,
1058pub type ExternCrateItem<'a> = ExternCrateItemNode<RefRoot<'a>>;
1059
1060impl<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} 773}
1063impl<R: TreeRoot<RaTypes>> Eq for ExternCrateItemNode<R> {} 774unsafe impl TransparentNewType for ExternCrateItem {
1064impl<R: TreeRoot<RaTypes>> Hash for ExternCrateItemNode<R> { 775 type Repr = rowan::SyntaxNode<RaTypes>;
1065 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1066} 776}
1067 777
1068impl<'a> AstNode<'a> for ExternCrateItem<'a> { 778impl AstNode for ExternCrateItem {
1069 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 779 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1070 match syntax.kind() { 780 match syntax.kind() {
1071 EXTERN_CRATE_ITEM => Some(ExternCrateItem { syntax }), 781 EXTERN_CRATE_ITEM => Some(ExternCrateItem::from_repr(syntax.into_repr())),
1072 _ => None, 782 _ => None,
1073 } 783 }
1074 } 784 }
1075 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 785 fn syntax(&self) -> &SyntaxNode { &self.syntax }
786 fn to_owned(&self) -> TreePtr<ExternCrateItem> { TreePtr::cast(self.syntax.to_owned()) }
1076} 787}
1077 788
1078impl<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 789
1087 790impl ExternCrateItem {}
1088impl<'a> ExternCrateItem<'a> {}
1089 791
1090// FieldExpr 792// FieldExpr
1091#[derive(Debug, Clone, Copy,)] 793#[derive(Debug, PartialEq, Eq, Hash)]
1092pub struct FieldExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 794#[repr(transparent)]
1093 pub(crate) syntax: SyntaxNode<R>, 795pub struct FieldExpr {
1094} 796 pub(crate) syntax: SyntaxNode,
1095pub type FieldExpr<'a> = FieldExprNode<RefRoot<'a>>;
1096
1097impl<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} 797}
1100impl<R: TreeRoot<RaTypes>> Eq for FieldExprNode<R> {} 798unsafe impl TransparentNewType for FieldExpr {
1101impl<R: TreeRoot<RaTypes>> Hash for FieldExprNode<R> { 799 type Repr = rowan::SyntaxNode<RaTypes>;
1102 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1103} 800}
1104 801
1105impl<'a> AstNode<'a> for FieldExpr<'a> { 802impl AstNode for FieldExpr {
1106 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 803 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1107 match syntax.kind() { 804 match syntax.kind() {
1108 FIELD_EXPR => Some(FieldExpr { syntax }), 805 FIELD_EXPR => Some(FieldExpr::from_repr(syntax.into_repr())),
1109 _ => None, 806 _ => None,
1110 } 807 }
1111 } 808 }
1112 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 809 fn syntax(&self) -> &SyntaxNode { &self.syntax }
810 fn to_owned(&self) -> TreePtr<FieldExpr> { TreePtr::cast(self.syntax.to_owned()) }
1113} 811}
1114 812
1115impl<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 813
1124 814impl FieldExpr {
1125impl<'a> FieldExpr<'a> { 815 pub fn expr(&self) -> Option<&Expr> {
1126 pub fn expr(self) -> Option<Expr<'a>> {
1127 super::child_opt(self) 816 super::child_opt(self)
1128 } 817 }
1129 818
1130 pub fn name_ref(self) -> Option<NameRef<'a>> { 819 pub fn name_ref(&self) -> Option<&NameRef> {
1131 super::child_opt(self) 820 super::child_opt(self)
1132 } 821 }
1133} 822}
1134 823
1135// FieldPatList 824// FieldPatList
1136#[derive(Debug, Clone, Copy,)] 825#[derive(Debug, PartialEq, Eq, Hash)]
1137pub struct FieldPatListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 826#[repr(transparent)]
1138 pub(crate) syntax: SyntaxNode<R>, 827pub struct FieldPatList {
828 pub(crate) syntax: SyntaxNode,
1139} 829}
1140pub type FieldPatList<'a> = FieldPatListNode<RefRoot<'a>>; 830unsafe impl TransparentNewType for FieldPatList {
1141 831 type Repr = rowan::SyntaxNode<RaTypes>;
1142impl<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}
1145impl<R: TreeRoot<RaTypes>> Eq for FieldPatListNode<R> {}
1146impl<R: TreeRoot<RaTypes>> Hash for FieldPatListNode<R> {
1147 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1148} 832}
1149 833
1150impl<'a> AstNode<'a> for FieldPatList<'a> { 834impl AstNode for FieldPatList {
1151 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 835 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1152 match syntax.kind() { 836 match syntax.kind() {
1153 FIELD_PAT_LIST => Some(FieldPatList { syntax }), 837 FIELD_PAT_LIST => Some(FieldPatList::from_repr(syntax.into_repr())),
1154 _ => None, 838 _ => None,
1155 } 839 }
1156 } 840 }
1157 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 841 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1158} 842 fn to_owned(&self) -> TreePtr<FieldPatList> { TreePtr::cast(self.syntax.to_owned()) }
1159
1160impl<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} 843}
1168 844
1169 845
1170impl<'a> FieldPatList<'a> {} 846impl FieldPatList {}
1171 847
1172// FnDef 848// FnDef
1173#[derive(Debug, Clone, Copy,)] 849#[derive(Debug, PartialEq, Eq, Hash)]
1174pub struct FnDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 850#[repr(transparent)]
1175 pub(crate) syntax: SyntaxNode<R>, 851pub struct FnDef {
852 pub(crate) syntax: SyntaxNode,
1176} 853}
1177pub type FnDef<'a> = FnDefNode<RefRoot<'a>>; 854unsafe impl TransparentNewType for FnDef {
1178 855 type Repr = rowan::SyntaxNode<RaTypes>;
1179impl<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}
1182impl<R: TreeRoot<RaTypes>> Eq for FnDefNode<R> {}
1183impl<R: TreeRoot<RaTypes>> Hash for FnDefNode<R> {
1184 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1185} 856}
1186 857
1187impl<'a> AstNode<'a> for FnDef<'a> { 858impl AstNode for FnDef {
1188 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 859 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1189 match syntax.kind() { 860 match syntax.kind() {
1190 FN_DEF => Some(FnDef { syntax }), 861 FN_DEF => Some(FnDef::from_repr(syntax.into_repr())),
1191 _ => None, 862 _ => None,
1192 } 863 }
1193 } 864 }
1194 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 865 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1195} 866 fn to_owned(&self) -> TreePtr<FnDef> { TreePtr::cast(self.syntax.to_owned()) }
1196
1197impl<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} 867}
1205 868
1206 869
1207impl<'a> ast::VisibilityOwner<'a> for FnDef<'a> {} 870impl ast::VisibilityOwner for FnDef {}
1208impl<'a> ast::NameOwner<'a> for FnDef<'a> {} 871impl ast::NameOwner for FnDef {}
1209impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} 872impl ast::TypeParamsOwner for FnDef {}
1210impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} 873impl ast::AttrsOwner for FnDef {}
1211impl<'a> ast::DocCommentsOwner<'a> for FnDef<'a> {} 874impl ast::DocCommentsOwner for FnDef {}
1212impl<'a> FnDef<'a> { 875impl FnDef {
1213 pub fn param_list(self) -> Option<ParamList<'a>> { 876 pub fn param_list(&self) -> Option<&ParamList> {
1214 super::child_opt(self) 877 super::child_opt(self)
1215 } 878 }
1216 879
1217 pub fn body(self) -> Option<Block<'a>> { 880 pub fn body(&self) -> Option<&Block> {
1218 super::child_opt(self) 881 super::child_opt(self)
1219 } 882 }
1220 883
1221 pub fn ret_type(self) -> Option<RetType<'a>> { 884 pub fn ret_type(&self) -> Option<&RetType> {
1222 super::child_opt(self) 885 super::child_opt(self)
1223 } 886 }
1224} 887}
1225 888
1226// FnPointerType 889// FnPointerType
1227#[derive(Debug, Clone, Copy,)] 890#[derive(Debug, PartialEq, Eq, Hash)]
1228pub struct FnPointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 891#[repr(transparent)]
1229 pub(crate) syntax: SyntaxNode<R>, 892pub struct FnPointerType {
1230} 893 pub(crate) syntax: SyntaxNode,
1231pub type FnPointerType<'a> = FnPointerTypeNode<RefRoot<'a>>;
1232
1233impl<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} 894}
1236impl<R: TreeRoot<RaTypes>> Eq for FnPointerTypeNode<R> {} 895unsafe impl TransparentNewType for FnPointerType {
1237impl<R: TreeRoot<RaTypes>> Hash for FnPointerTypeNode<R> { 896 type Repr = rowan::SyntaxNode<RaTypes>;
1238 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1239} 897}
1240 898
1241impl<'a> AstNode<'a> for FnPointerType<'a> { 899impl AstNode for FnPointerType {
1242 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 900 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1243 match syntax.kind() { 901 match syntax.kind() {
1244 FN_POINTER_TYPE => Some(FnPointerType { syntax }), 902 FN_POINTER_TYPE => Some(FnPointerType::from_repr(syntax.into_repr())),
1245 _ => None, 903 _ => None,
1246 } 904 }
1247 } 905 }
1248 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 906 fn syntax(&self) -> &SyntaxNode { &self.syntax }
907 fn to_owned(&self) -> TreePtr<FnPointerType> { TreePtr::cast(self.syntax.to_owned()) }
1249} 908}
1250 909
1251impl<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 910
1260 911impl FnPointerType {
1261impl<'a> FnPointerType<'a> { 912 pub fn param_list(&self) -> Option<&ParamList> {
1262 pub fn param_list(self) -> Option<ParamList<'a>> {
1263 super::child_opt(self) 913 super::child_opt(self)
1264 } 914 }
1265 915
1266 pub fn ret_type(self) -> Option<RetType<'a>> { 916 pub fn ret_type(&self) -> Option<&RetType> {
1267 super::child_opt(self) 917 super::child_opt(self)
1268 } 918 }
1269} 919}
1270 920
1271// ForExpr 921// ForExpr
1272#[derive(Debug, Clone, Copy,)] 922#[derive(Debug, PartialEq, Eq, Hash)]
1273pub struct ForExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 923#[repr(transparent)]
1274 pub(crate) syntax: SyntaxNode<R>, 924pub struct ForExpr {
1275} 925 pub(crate) syntax: SyntaxNode,
1276pub type ForExpr<'a> = ForExprNode<RefRoot<'a>>;
1277
1278impl<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} 926}
1281impl<R: TreeRoot<RaTypes>> Eq for ForExprNode<R> {} 927unsafe impl TransparentNewType for ForExpr {
1282impl<R: TreeRoot<RaTypes>> Hash for ForExprNode<R> { 928 type Repr = rowan::SyntaxNode<RaTypes>;
1283 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1284} 929}
1285 930
1286impl<'a> AstNode<'a> for ForExpr<'a> { 931impl AstNode for ForExpr {
1287 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 932 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1288 match syntax.kind() { 933 match syntax.kind() {
1289 FOR_EXPR => Some(ForExpr { syntax }), 934 FOR_EXPR => Some(ForExpr::from_repr(syntax.into_repr())),
1290 _ => None, 935 _ => None,
1291 } 936 }
1292 } 937 }
1293 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 938 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1294} 939 fn to_owned(&self) -> TreePtr<ForExpr> { TreePtr::cast(self.syntax.to_owned()) }
1295
1296impl<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} 940}
1304 941
1305 942
1306impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} 943impl ast::LoopBodyOwner for ForExpr {}
1307impl<'a> ForExpr<'a> { 944impl ForExpr {
1308 pub fn pat(self) -> Option<Pat<'a>> { 945 pub fn pat(&self) -> Option<&Pat> {
1309 super::child_opt(self) 946 super::child_opt(self)
1310 } 947 }
1311 948
1312 pub fn iterable(self) -> Option<Expr<'a>> { 949 pub fn iterable(&self) -> Option<&Expr> {
1313 super::child_opt(self) 950 super::child_opt(self)
1314 } 951 }
1315} 952}
1316 953
1317// ForType 954// ForType
1318#[derive(Debug, Clone, Copy,)] 955#[derive(Debug, PartialEq, Eq, Hash)]
1319pub struct ForTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 956#[repr(transparent)]
1320 pub(crate) syntax: SyntaxNode<R>, 957pub struct ForType {
1321} 958 pub(crate) syntax: SyntaxNode,
1322pub type ForType<'a> = ForTypeNode<RefRoot<'a>>;
1323
1324impl<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} 959}
1327impl<R: TreeRoot<RaTypes>> Eq for ForTypeNode<R> {} 960unsafe impl TransparentNewType for ForType {
1328impl<R: TreeRoot<RaTypes>> Hash for ForTypeNode<R> { 961 type Repr = rowan::SyntaxNode<RaTypes>;
1329 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1330} 962}
1331 963
1332impl<'a> AstNode<'a> for ForType<'a> { 964impl AstNode for ForType {
1333 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 965 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1334 match syntax.kind() { 966 match syntax.kind() {
1335 FOR_TYPE => Some(ForType { syntax }), 967 FOR_TYPE => Some(ForType::from_repr(syntax.into_repr())),
1336 _ => None, 968 _ => None,
1337 } 969 }
1338 } 970 }
1339 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 971 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1340} 972 fn to_owned(&self) -> TreePtr<ForType> { TreePtr::cast(self.syntax.to_owned()) }
1341
1342impl<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} 973}
1350 974
1351 975
1352impl<'a> ForType<'a> { 976impl ForType {
1353 pub fn type_ref(self) -> Option<TypeRef<'a>> { 977 pub fn type_ref(&self) -> Option<&TypeRef> {
1354 super::child_opt(self) 978 super::child_opt(self)
1355 } 979 }
1356} 980}
1357 981
1358// IfExpr 982// IfExpr
1359#[derive(Debug, Clone, Copy,)] 983#[derive(Debug, PartialEq, Eq, Hash)]
1360pub struct IfExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 984#[repr(transparent)]
1361 pub(crate) syntax: SyntaxNode<R>, 985pub struct IfExpr {
986 pub(crate) syntax: SyntaxNode,
1362} 987}
1363pub type IfExpr<'a> = IfExprNode<RefRoot<'a>>; 988unsafe impl TransparentNewType for IfExpr {
1364 989 type Repr = rowan::SyntaxNode<RaTypes>;
1365impl<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}
1368impl<R: TreeRoot<RaTypes>> Eq for IfExprNode<R> {}
1369impl<R: TreeRoot<RaTypes>> Hash for IfExprNode<R> {
1370 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1371} 990}
1372 991
1373impl<'a> AstNode<'a> for IfExpr<'a> { 992impl AstNode for IfExpr {
1374 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 993 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1375 match syntax.kind() { 994 match syntax.kind() {
1376 IF_EXPR => Some(IfExpr { syntax }), 995 IF_EXPR => Some(IfExpr::from_repr(syntax.into_repr())),
1377 _ => None, 996 _ => None,
1378 } 997 }
1379 } 998 }
1380 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 999 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1381} 1000 fn to_owned(&self) -> TreePtr<IfExpr> { TreePtr::cast(self.syntax.to_owned()) }
1382
1383impl<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} 1001}
1391 1002
1392 1003
1393impl<'a> IfExpr<'a> { 1004impl IfExpr {
1394 pub fn condition(self) -> Option<Condition<'a>> { 1005 pub fn condition(&self) -> Option<&Condition> {
1395 super::child_opt(self) 1006 super::child_opt(self)
1396 } 1007 }
1397} 1008}
1398 1009
1399// ImplBlock 1010// ImplBlock
1400#[derive(Debug, Clone, Copy,)] 1011#[derive(Debug, PartialEq, Eq, Hash)]
1401pub struct ImplBlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1012#[repr(transparent)]
1402 pub(crate) syntax: SyntaxNode<R>, 1013pub struct ImplBlock {
1014 pub(crate) syntax: SyntaxNode,
1403} 1015}
1404pub type ImplBlock<'a> = ImplBlockNode<RefRoot<'a>>; 1016unsafe impl TransparentNewType for ImplBlock {
1405 1017 type Repr = rowan::SyntaxNode<RaTypes>;
1406impl<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}
1409impl<R: TreeRoot<RaTypes>> Eq for ImplBlockNode<R> {}
1410impl<R: TreeRoot<RaTypes>> Hash for ImplBlockNode<R> {
1411 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1412} 1018}
1413 1019
1414impl<'a> AstNode<'a> for ImplBlock<'a> { 1020impl AstNode for ImplBlock {
1415 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1021 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1416 match syntax.kind() { 1022 match syntax.kind() {
1417 IMPL_BLOCK => Some(ImplBlock { syntax }), 1023 IMPL_BLOCK => Some(ImplBlock::from_repr(syntax.into_repr())),
1418 _ => None, 1024 _ => None,
1419 } 1025 }
1420 } 1026 }
1421 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1027 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1422} 1028 fn to_owned(&self) -> TreePtr<ImplBlock> { TreePtr::cast(self.syntax.to_owned()) }
1423
1424impl<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} 1029}
1432 1030
1433 1031
1434impl<'a> ImplBlock<'a> { 1032impl ImplBlock {
1435 pub fn item_list(self) -> Option<ItemList<'a>> { 1033 pub fn item_list(&self) -> Option<&ItemList> {
1436 super::child_opt(self) 1034 super::child_opt(self)
1437 } 1035 }
1438} 1036}
1439 1037
1440// ImplItem 1038// ImplItem
1039#[derive(Debug, PartialEq, Eq, Hash)]
1040#[repr(transparent)]
1041pub struct ImplItem {
1042 pub(crate) syntax: SyntaxNode,
1043}
1044unsafe impl TransparentNewType for ImplItem {
1045 type Repr = rowan::SyntaxNode<RaTypes>;
1046}
1047
1441#[derive(Debug, Clone, Copy, PartialEq, Eq)] 1048#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1442pub enum ImplItem<'a> { 1049pub enum ImplItemKind<'a> {
1443 FnDef(FnDef<'a>), 1050 FnDef(&'a FnDef),
1444 TypeDef(TypeDef<'a>), 1051 TypeDef(&'a TypeDef),
1445 ConstDef(ConstDef<'a>), 1052 ConstDef(&'a ConstDef),
1446} 1053}
1447 1054
1448impl<'a> AstNode<'a> for ImplItem<'a> { 1055impl AstNode for ImplItem {
1449 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1056 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1450 match syntax.kind() { 1057 match syntax.kind() {
1451 FN_DEF => Some(ImplItem::FnDef(FnDef { syntax })), 1058 | FN_DEF
1452 TYPE_DEF => Some(ImplItem::TypeDef(TypeDef { syntax })), 1059 | TYPE_DEF
1453 CONST_DEF => Some(ImplItem::ConstDef(ConstDef { syntax })), 1060 | CONST_DEF => Some(ImplItem::from_repr(syntax.into_repr())),
1454 _ => None, 1061 _ => None,
1455 } 1062 }
1456 } 1063 }
1457 fn syntax(self) -> SyntaxNodeRef<'a> { 1064 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1458 match self { 1065 fn to_owned(&self) -> TreePtr<ImplItem> { TreePtr::cast(self.syntax.to_owned()) }
1459 ImplItem::FnDef(inner) => inner.syntax(), 1066}
1460 ImplItem::TypeDef(inner) => inner.syntax(), 1067
1461 ImplItem::ConstDef(inner) => inner.syntax(), 1068impl ImplItem {
1069 pub fn kind(&self) -> ImplItemKind {
1070 match self.syntax.kind() {
1071 FN_DEF => ImplItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()),
1072 TYPE_DEF => ImplItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()),
1073 CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()),
1074 _ => unreachable!(),
1462 } 1075 }
1463 } 1076 }
1464} 1077}
1465 1078
1466impl<'a> ImplItem<'a> {} 1079impl ImplItem {}
1467 1080
1468// ImplTraitType 1081// ImplTraitType
1469#[derive(Debug, Clone, Copy,)] 1082#[derive(Debug, PartialEq, Eq, Hash)]
1470pub struct ImplTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1083#[repr(transparent)]
1471 pub(crate) syntax: SyntaxNode<R>, 1084pub struct ImplTraitType {
1472} 1085 pub(crate) syntax: SyntaxNode,
1473pub type ImplTraitType<'a> = ImplTraitTypeNode<RefRoot<'a>>;
1474
1475impl<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} 1086}
1478impl<R: TreeRoot<RaTypes>> Eq for ImplTraitTypeNode<R> {} 1087unsafe impl TransparentNewType for ImplTraitType {
1479impl<R: TreeRoot<RaTypes>> Hash for ImplTraitTypeNode<R> { 1088 type Repr = rowan::SyntaxNode<RaTypes>;
1480 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1481} 1089}
1482 1090
1483impl<'a> AstNode<'a> for ImplTraitType<'a> { 1091impl AstNode for ImplTraitType {
1484 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1092 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1485 match syntax.kind() { 1093 match syntax.kind() {
1486 IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), 1094 IMPL_TRAIT_TYPE => Some(ImplTraitType::from_repr(syntax.into_repr())),
1487 _ => None, 1095 _ => None,
1488 } 1096 }
1489 } 1097 }
1490 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1098 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1099 fn to_owned(&self) -> TreePtr<ImplTraitType> { TreePtr::cast(self.syntax.to_owned()) }
1491} 1100}
1492 1101
1493impl<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 1102
1502 1103impl ImplTraitType {}
1503impl<'a> ImplTraitType<'a> {}
1504 1104
1505// IndexExpr 1105// IndexExpr
1506#[derive(Debug, Clone, Copy,)] 1106#[derive(Debug, PartialEq, Eq, Hash)]
1507pub struct IndexExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1107#[repr(transparent)]
1508 pub(crate) syntax: SyntaxNode<R>, 1108pub struct IndexExpr {
1109 pub(crate) syntax: SyntaxNode,
1509} 1110}
1510pub type IndexExpr<'a> = IndexExprNode<RefRoot<'a>>; 1111unsafe impl TransparentNewType for IndexExpr {
1511 1112 type Repr = rowan::SyntaxNode<RaTypes>;
1512impl<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}
1515impl<R: TreeRoot<RaTypes>> Eq for IndexExprNode<R> {}
1516impl<R: TreeRoot<RaTypes>> Hash for IndexExprNode<R> {
1517 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1518} 1113}
1519 1114
1520impl<'a> AstNode<'a> for IndexExpr<'a> { 1115impl AstNode for IndexExpr {
1521 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1116 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1522 match syntax.kind() { 1117 match syntax.kind() {
1523 INDEX_EXPR => Some(IndexExpr { syntax }), 1118 INDEX_EXPR => Some(IndexExpr::from_repr(syntax.into_repr())),
1524 _ => None, 1119 _ => None,
1525 } 1120 }
1526 } 1121 }
1527 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1122 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1528} 1123 fn to_owned(&self) -> TreePtr<IndexExpr> { TreePtr::cast(self.syntax.to_owned()) }
1529
1530impl<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} 1124}
1538 1125
1539 1126
1540impl<'a> IndexExpr<'a> {} 1127impl IndexExpr {}
1541 1128
1542// ItemList 1129// ItemList
1543#[derive(Debug, Clone, Copy,)] 1130#[derive(Debug, PartialEq, Eq, Hash)]
1544pub struct ItemListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1131#[repr(transparent)]
1545 pub(crate) syntax: SyntaxNode<R>, 1132pub struct ItemList {
1133 pub(crate) syntax: SyntaxNode,
1546} 1134}
1547pub type ItemList<'a> = ItemListNode<RefRoot<'a>>; 1135unsafe impl TransparentNewType for ItemList {
1548 1136 type Repr = rowan::SyntaxNode<RaTypes>;
1549impl<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}
1552impl<R: TreeRoot<RaTypes>> Eq for ItemListNode<R> {}
1553impl<R: TreeRoot<RaTypes>> Hash for ItemListNode<R> {
1554 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1555} 1137}
1556 1138
1557impl<'a> AstNode<'a> for ItemList<'a> { 1139impl AstNode for ItemList {
1558 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1140 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1559 match syntax.kind() { 1141 match syntax.kind() {
1560 ITEM_LIST => Some(ItemList { syntax }), 1142 ITEM_LIST => Some(ItemList::from_repr(syntax.into_repr())),
1561 _ => None, 1143 _ => None,
1562 } 1144 }
1563 } 1145 }
1564 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1146 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1565} 1147 fn to_owned(&self) -> TreePtr<ItemList> { TreePtr::cast(self.syntax.to_owned()) }
1566
1567impl<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} 1148}
1575 1149
1576 1150
1577impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} 1151impl ast::FnDefOwner for ItemList {}
1578impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} 1152impl ast::ModuleItemOwner for ItemList {}
1579impl<'a> ItemList<'a> { 1153impl ItemList {
1580 pub fn impl_items(self) -> impl Iterator<Item = ImplItem<'a>> + 'a { 1154 pub fn impl_items(&self) -> impl Iterator<Item = &ImplItem> {
1581 super::children(self) 1155 super::children(self)
1582 } 1156 }
1583} 1157}
1584 1158
1585// Label 1159// Label
1586#[derive(Debug, Clone, Copy,)] 1160#[derive(Debug, PartialEq, Eq, Hash)]
1587pub struct LabelNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1161#[repr(transparent)]
1588 pub(crate) syntax: SyntaxNode<R>, 1162pub struct Label {
1163 pub(crate) syntax: SyntaxNode,
1589} 1164}
1590pub type Label<'a> = LabelNode<RefRoot<'a>>; 1165unsafe impl TransparentNewType for Label {
1591 1166 type Repr = rowan::SyntaxNode<RaTypes>;
1592impl<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}
1595impl<R: TreeRoot<RaTypes>> Eq for LabelNode<R> {}
1596impl<R: TreeRoot<RaTypes>> Hash for LabelNode<R> {
1597 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1598} 1167}
1599 1168
1600impl<'a> AstNode<'a> for Label<'a> { 1169impl AstNode for Label {
1601 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1170 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1602 match syntax.kind() { 1171 match syntax.kind() {
1603 LABEL => Some(Label { syntax }), 1172 LABEL => Some(Label::from_repr(syntax.into_repr())),
1604 _ => None, 1173 _ => None,
1605 } 1174 }
1606 } 1175 }
1607 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1176 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1608} 1177 fn to_owned(&self) -> TreePtr<Label> { TreePtr::cast(self.syntax.to_owned()) }
1609
1610impl<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} 1178}
1618 1179
1619 1180
1620impl<'a> Label<'a> {} 1181impl Label {}
1621 1182
1622// LambdaExpr 1183// LambdaExpr
1623#[derive(Debug, Clone, Copy,)] 1184#[derive(Debug, PartialEq, Eq, Hash)]
1624pub struct LambdaExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1185#[repr(transparent)]
1625 pub(crate) syntax: SyntaxNode<R>, 1186pub struct LambdaExpr {
1626} 1187 pub(crate) syntax: SyntaxNode,
1627pub type LambdaExpr<'a> = LambdaExprNode<RefRoot<'a>>;
1628
1629impl<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} 1188}
1632impl<R: TreeRoot<RaTypes>> Eq for LambdaExprNode<R> {} 1189unsafe impl TransparentNewType for LambdaExpr {
1633impl<R: TreeRoot<RaTypes>> Hash for LambdaExprNode<R> { 1190 type Repr = rowan::SyntaxNode<RaTypes>;
1634 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1635} 1191}
1636 1192
1637impl<'a> AstNode<'a> for LambdaExpr<'a> { 1193impl AstNode for LambdaExpr {
1638 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1194 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1639 match syntax.kind() { 1195 match syntax.kind() {
1640 LAMBDA_EXPR => Some(LambdaExpr { syntax }), 1196 LAMBDA_EXPR => Some(LambdaExpr::from_repr(syntax.into_repr())),
1641 _ => None, 1197 _ => None,
1642 } 1198 }
1643 } 1199 }
1644 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1200 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1645} 1201 fn to_owned(&self) -> TreePtr<LambdaExpr> { TreePtr::cast(self.syntax.to_owned()) }
1646
1647impl<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} 1202}
1655 1203
1656 1204
1657impl<'a> LambdaExpr<'a> { 1205impl LambdaExpr {
1658 pub fn param_list(self) -> Option<ParamList<'a>> { 1206 pub fn param_list(&self) -> Option<&ParamList> {
1659 super::child_opt(self) 1207 super::child_opt(self)
1660 } 1208 }
1661 1209
1662 pub fn body(self) -> Option<Expr<'a>> { 1210 pub fn body(&self) -> Option<&Expr> {
1663 super::child_opt(self) 1211 super::child_opt(self)
1664 } 1212 }
1665} 1213}
1666 1214
1667// LetStmt 1215// LetStmt
1668#[derive(Debug, Clone, Copy,)] 1216#[derive(Debug, PartialEq, Eq, Hash)]
1669pub struct LetStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1217#[repr(transparent)]
1670 pub(crate) syntax: SyntaxNode<R>, 1218pub struct LetStmt {
1671} 1219 pub(crate) syntax: SyntaxNode,
1672pub type LetStmt<'a> = LetStmtNode<RefRoot<'a>>;
1673
1674impl<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} 1220}
1677impl<R: TreeRoot<RaTypes>> Eq for LetStmtNode<R> {} 1221unsafe impl TransparentNewType for LetStmt {
1678impl<R: TreeRoot<RaTypes>> Hash for LetStmtNode<R> { 1222 type Repr = rowan::SyntaxNode<RaTypes>;
1679 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1680} 1223}
1681 1224
1682impl<'a> AstNode<'a> for LetStmt<'a> { 1225impl AstNode for LetStmt {
1683 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1226 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1684 match syntax.kind() { 1227 match syntax.kind() {
1685 LET_STMT => Some(LetStmt { syntax }), 1228 LET_STMT => Some(LetStmt::from_repr(syntax.into_repr())),
1686 _ => None, 1229 _ => None,
1687 } 1230 }
1688 } 1231 }
1689 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1232 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1690} 1233 fn to_owned(&self) -> TreePtr<LetStmt> { TreePtr::cast(self.syntax.to_owned()) }
1691
1692impl<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} 1234}
1700 1235
1701 1236
1702impl<'a> LetStmt<'a> { 1237impl LetStmt {
1703 pub fn pat(self) -> Option<Pat<'a>> { 1238 pub fn pat(&self) -> Option<&Pat> {
1704 super::child_opt(self) 1239 super::child_opt(self)
1705 } 1240 }
1706 1241
1707 pub fn type_ref(self) -> Option<TypeRef<'a>> { 1242 pub fn type_ref(&self) -> Option<&TypeRef> {
1708 super::child_opt(self) 1243 super::child_opt(self)
1709 } 1244 }
1710 1245
1711 pub fn initializer(self) -> Option<Expr<'a>> { 1246 pub fn initializer(&self) -> Option<&Expr> {
1712 super::child_opt(self) 1247 super::child_opt(self)
1713 } 1248 }
1714} 1249}
1715 1250
1716// Lifetime 1251// Lifetime
1717#[derive(Debug, Clone, Copy,)] 1252#[derive(Debug, PartialEq, Eq, Hash)]
1718pub struct LifetimeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1253#[repr(transparent)]
1719 pub(crate) syntax: SyntaxNode<R>, 1254pub struct Lifetime {
1255 pub(crate) syntax: SyntaxNode,
1720} 1256}
1721pub type Lifetime<'a> = LifetimeNode<RefRoot<'a>>; 1257unsafe impl TransparentNewType for Lifetime {
1722 1258 type Repr = rowan::SyntaxNode<RaTypes>;
1723impl<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}
1726impl<R: TreeRoot<RaTypes>> Eq for LifetimeNode<R> {}
1727impl<R: TreeRoot<RaTypes>> Hash for LifetimeNode<R> {
1728 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1729} 1259}
1730 1260
1731impl<'a> AstNode<'a> for Lifetime<'a> { 1261impl AstNode for Lifetime {
1732 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1262 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1733 match syntax.kind() { 1263 match syntax.kind() {
1734 LIFETIME => Some(Lifetime { syntax }), 1264 LIFETIME => Some(Lifetime::from_repr(syntax.into_repr())),
1735 _ => None, 1265 _ => None,
1736 } 1266 }
1737 } 1267 }
1738 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1268 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1739} 1269 fn to_owned(&self) -> TreePtr<Lifetime> { TreePtr::cast(self.syntax.to_owned()) }
1740
1741impl<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} 1270}
1749 1271
1750 1272
1751impl<'a> Lifetime<'a> {} 1273impl Lifetime {}
1752 1274
1753// LifetimeParam 1275// LifetimeParam
1754#[derive(Debug, Clone, Copy,)] 1276#[derive(Debug, PartialEq, Eq, Hash)]
1755pub struct LifetimeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1277#[repr(transparent)]
1756 pub(crate) syntax: SyntaxNode<R>, 1278pub struct LifetimeParam {
1757} 1279 pub(crate) syntax: SyntaxNode,
1758pub type LifetimeParam<'a> = LifetimeParamNode<RefRoot<'a>>;
1759
1760impl<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} 1280}
1763impl<R: TreeRoot<RaTypes>> Eq for LifetimeParamNode<R> {} 1281unsafe impl TransparentNewType for LifetimeParam {
1764impl<R: TreeRoot<RaTypes>> Hash for LifetimeParamNode<R> { 1282 type Repr = rowan::SyntaxNode<RaTypes>;
1765 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1766} 1283}
1767 1284
1768impl<'a> AstNode<'a> for LifetimeParam<'a> { 1285impl AstNode for LifetimeParam {
1769 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1286 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1770 match syntax.kind() { 1287 match syntax.kind() {
1771 LIFETIME_PARAM => Some(LifetimeParam { syntax }), 1288 LIFETIME_PARAM => Some(LifetimeParam::from_repr(syntax.into_repr())),
1772 _ => None, 1289 _ => None,
1773 } 1290 }
1774 } 1291 }
1775 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1292 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1293 fn to_owned(&self) -> TreePtr<LifetimeParam> { TreePtr::cast(self.syntax.to_owned()) }
1776} 1294}
1777 1295
1778impl<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 1296
1787 1297impl LifetimeParam {
1788impl<'a> LifetimeParam<'a> { 1298 pub fn lifetime(&self) -> Option<&Lifetime> {
1789 pub fn lifetime(self) -> Option<Lifetime<'a>> {
1790 super::child_opt(self) 1299 super::child_opt(self)
1791 } 1300 }
1792} 1301}
1793 1302
1794// Literal 1303// Literal
1795#[derive(Debug, Clone, Copy,)] 1304#[derive(Debug, PartialEq, Eq, Hash)]
1796pub struct LiteralNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1305#[repr(transparent)]
1797 pub(crate) syntax: SyntaxNode<R>, 1306pub struct Literal {
1798} 1307 pub(crate) syntax: SyntaxNode,
1799pub type Literal<'a> = LiteralNode<RefRoot<'a>>;
1800
1801impl<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} 1308}
1804impl<R: TreeRoot<RaTypes>> Eq for LiteralNode<R> {} 1309unsafe impl TransparentNewType for Literal {
1805impl<R: TreeRoot<RaTypes>> Hash for LiteralNode<R> { 1310 type Repr = rowan::SyntaxNode<RaTypes>;
1806 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1807} 1311}
1808 1312
1809impl<'a> AstNode<'a> for Literal<'a> { 1313impl AstNode for Literal {
1810 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1314 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1811 match syntax.kind() { 1315 match syntax.kind() {
1812 LITERAL => Some(Literal { syntax }), 1316 LITERAL => Some(Literal::from_repr(syntax.into_repr())),
1813 _ => None, 1317 _ => None,
1814 } 1318 }
1815 } 1319 }
1816 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1320 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1817} 1321 fn to_owned(&self) -> TreePtr<Literal> { TreePtr::cast(self.syntax.to_owned()) }
1818
1819impl<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} 1322}
1827 1323
1828 1324
1829impl<'a> Literal<'a> {} 1325impl Literal {}
1830 1326
1831// LoopExpr 1327// LoopExpr
1832#[derive(Debug, Clone, Copy,)] 1328#[derive(Debug, PartialEq, Eq, Hash)]
1833pub struct LoopExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1329#[repr(transparent)]
1834 pub(crate) syntax: SyntaxNode<R>, 1330pub struct LoopExpr {
1331 pub(crate) syntax: SyntaxNode,
1835} 1332}
1836pub type LoopExpr<'a> = LoopExprNode<RefRoot<'a>>; 1333unsafe impl TransparentNewType for LoopExpr {
1837 1334 type Repr = rowan::SyntaxNode<RaTypes>;
1838impl<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}
1841impl<R: TreeRoot<RaTypes>> Eq for LoopExprNode<R> {}
1842impl<R: TreeRoot<RaTypes>> Hash for LoopExprNode<R> {
1843 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1844} 1335}
1845 1336
1846impl<'a> AstNode<'a> for LoopExpr<'a> { 1337impl AstNode for LoopExpr {
1847 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1338 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1848 match syntax.kind() { 1339 match syntax.kind() {
1849 LOOP_EXPR => Some(LoopExpr { syntax }), 1340 LOOP_EXPR => Some(LoopExpr::from_repr(syntax.into_repr())),
1850 _ => None, 1341 _ => None,
1851 } 1342 }
1852 } 1343 }
1853 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1344 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1854} 1345 fn to_owned(&self) -> TreePtr<LoopExpr> { TreePtr::cast(self.syntax.to_owned()) }
1855
1856impl<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} 1346}
1864 1347
1865 1348
1866impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} 1349impl ast::LoopBodyOwner for LoopExpr {}
1867impl<'a> LoopExpr<'a> {} 1350impl LoopExpr {}
1868 1351
1869// MacroCall 1352// MacroCall
1870#[derive(Debug, Clone, Copy,)] 1353#[derive(Debug, PartialEq, Eq, Hash)]
1871pub struct MacroCallNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1354#[repr(transparent)]
1872 pub(crate) syntax: SyntaxNode<R>, 1355pub struct MacroCall {
1356 pub(crate) syntax: SyntaxNode,
1873} 1357}
1874pub type MacroCall<'a> = MacroCallNode<RefRoot<'a>>; 1358unsafe impl TransparentNewType for MacroCall {
1875 1359 type Repr = rowan::SyntaxNode<RaTypes>;
1876impl<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}
1879impl<R: TreeRoot<RaTypes>> Eq for MacroCallNode<R> {}
1880impl<R: TreeRoot<RaTypes>> Hash for MacroCallNode<R> {
1881 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1882} 1360}
1883 1361
1884impl<'a> AstNode<'a> for MacroCall<'a> { 1362impl AstNode for MacroCall {
1885 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1363 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1886 match syntax.kind() { 1364 match syntax.kind() {
1887 MACRO_CALL => Some(MacroCall { syntax }), 1365 MACRO_CALL => Some(MacroCall::from_repr(syntax.into_repr())),
1888 _ => None, 1366 _ => None,
1889 } 1367 }
1890 } 1368 }
1891 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1369 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1892} 1370 fn to_owned(&self) -> TreePtr<MacroCall> { TreePtr::cast(self.syntax.to_owned()) }
1893
1894impl<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} 1371}
1902 1372
1903 1373
1904impl<'a> MacroCall<'a> { 1374impl MacroCall {
1905 pub fn token_tree(self) -> Option<TokenTree<'a>> { 1375 pub fn token_tree(&self) -> Option<&TokenTree> {
1906 super::child_opt(self) 1376 super::child_opt(self)
1907 } 1377 }
1908 1378
1909 pub fn path(self) -> Option<Path<'a>> { 1379 pub fn path(&self) -> Option<&Path> {
1910 super::child_opt(self) 1380 super::child_opt(self)
1911 } 1381 }
1912} 1382}
1913 1383
1914// MatchArm 1384// MatchArm
1915#[derive(Debug, Clone, Copy,)] 1385#[derive(Debug, PartialEq, Eq, Hash)]
1916pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1386#[repr(transparent)]
1917 pub(crate) syntax: SyntaxNode<R>, 1387pub struct MatchArm {
1388 pub(crate) syntax: SyntaxNode,
1918} 1389}
1919pub type MatchArm<'a> = MatchArmNode<RefRoot<'a>>; 1390unsafe impl TransparentNewType for MatchArm {
1920 1391 type Repr = rowan::SyntaxNode<RaTypes>;
1921impl<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}
1924impl<R: TreeRoot<RaTypes>> Eq for MatchArmNode<R> {}
1925impl<R: TreeRoot<RaTypes>> Hash for MatchArmNode<R> {
1926 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1927} 1392}
1928 1393
1929impl<'a> AstNode<'a> for MatchArm<'a> { 1394impl AstNode for MatchArm {
1930 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1395 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1931 match syntax.kind() { 1396 match syntax.kind() {
1932 MATCH_ARM => Some(MatchArm { syntax }), 1397 MATCH_ARM => Some(MatchArm::from_repr(syntax.into_repr())),
1933 _ => None, 1398 _ => None,
1934 } 1399 }
1935 } 1400 }
1936 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1401 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1402 fn to_owned(&self) -> TreePtr<MatchArm> { TreePtr::cast(self.syntax.to_owned()) }
1937} 1403}
1938 1404
1939impl<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 1405
1948 1406impl MatchArm {
1949impl<'a> MatchArm<'a> { 1407 pub fn pats(&self) -> impl Iterator<Item = &Pat> {
1950 pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a {
1951 super::children(self) 1408 super::children(self)
1952 } 1409 }
1953 1410
1954 pub fn guard(self) -> Option<MatchGuard<'a>> { 1411 pub fn guard(&self) -> Option<&MatchGuard> {
1955 super::child_opt(self) 1412 super::child_opt(self)
1956 } 1413 }
1957 1414
1958 pub fn expr(self) -> Option<Expr<'a>> { 1415 pub fn expr(&self) -> Option<&Expr> {
1959 super::child_opt(self) 1416 super::child_opt(self)
1960 } 1417 }
1961} 1418}
1962 1419
1963// MatchArmList 1420// MatchArmList
1964#[derive(Debug, Clone, Copy,)] 1421#[derive(Debug, PartialEq, Eq, Hash)]
1965pub struct MatchArmListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1422#[repr(transparent)]
1966 pub(crate) syntax: SyntaxNode<R>, 1423pub struct MatchArmList {
1967} 1424 pub(crate) syntax: SyntaxNode,
1968pub type MatchArmList<'a> = MatchArmListNode<RefRoot<'a>>;
1969
1970impl<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} 1425}
1973impl<R: TreeRoot<RaTypes>> Eq for MatchArmListNode<R> {} 1426unsafe impl TransparentNewType for MatchArmList {
1974impl<R: TreeRoot<RaTypes>> Hash for MatchArmListNode<R> { 1427 type Repr = rowan::SyntaxNode<RaTypes>;
1975 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1976} 1428}
1977 1429
1978impl<'a> AstNode<'a> for MatchArmList<'a> { 1430impl AstNode for MatchArmList {
1979 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1431 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1980 match syntax.kind() { 1432 match syntax.kind() {
1981 MATCH_ARM_LIST => Some(MatchArmList { syntax }), 1433 MATCH_ARM_LIST => Some(MatchArmList::from_repr(syntax.into_repr())),
1982 _ => None, 1434 _ => None,
1983 } 1435 }
1984 } 1436 }
1985 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1437 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1438 fn to_owned(&self) -> TreePtr<MatchArmList> { TreePtr::cast(self.syntax.to_owned()) }
1986} 1439}
1987 1440
1988impl<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 1441
1997 1442impl MatchArmList {
1998impl<'a> MatchArmList<'a> { 1443 pub fn arms(&self) -> impl Iterator<Item = &MatchArm> {
1999 pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a {
2000 super::children(self) 1444 super::children(self)
2001 } 1445 }
2002} 1446}
2003 1447
2004// MatchExpr 1448// MatchExpr
2005#[derive(Debug, Clone, Copy,)] 1449#[derive(Debug, PartialEq, Eq, Hash)]
2006pub struct MatchExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1450#[repr(transparent)]
2007 pub(crate) syntax: SyntaxNode<R>, 1451pub struct MatchExpr {
2008} 1452 pub(crate) syntax: SyntaxNode,
2009pub type MatchExpr<'a> = MatchExprNode<RefRoot<'a>>;
2010
2011impl<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} 1453}
2014impl<R: TreeRoot<RaTypes>> Eq for MatchExprNode<R> {} 1454unsafe impl TransparentNewType for MatchExpr {
2015impl<R: TreeRoot<RaTypes>> Hash for MatchExprNode<R> { 1455 type Repr = rowan::SyntaxNode<RaTypes>;
2016 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2017} 1456}
2018 1457
2019impl<'a> AstNode<'a> for MatchExpr<'a> { 1458impl AstNode for MatchExpr {
2020 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1459 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2021 match syntax.kind() { 1460 match syntax.kind() {
2022 MATCH_EXPR => Some(MatchExpr { syntax }), 1461 MATCH_EXPR => Some(MatchExpr::from_repr(syntax.into_repr())),
2023 _ => None, 1462 _ => None,
2024 } 1463 }
2025 } 1464 }
2026 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1465 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2027} 1466 fn to_owned(&self) -> TreePtr<MatchExpr> { TreePtr::cast(self.syntax.to_owned()) }
2028
2029impl<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} 1467}
2037 1468
2038 1469
2039impl<'a> MatchExpr<'a> { 1470impl MatchExpr {
2040 pub fn expr(self) -> Option<Expr<'a>> { 1471 pub fn expr(&self) -> Option<&Expr> {
2041 super::child_opt(self) 1472 super::child_opt(self)
2042 } 1473 }
2043 1474
2044 pub fn match_arm_list(self) -> Option<MatchArmList<'a>> { 1475 pub fn match_arm_list(&self) -> Option<&MatchArmList> {
2045 super::child_opt(self) 1476 super::child_opt(self)
2046 } 1477 }
2047} 1478}
2048 1479
2049// MatchGuard 1480// MatchGuard
2050#[derive(Debug, Clone, Copy,)] 1481#[derive(Debug, PartialEq, Eq, Hash)]
2051pub struct MatchGuardNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1482#[repr(transparent)]
2052 pub(crate) syntax: SyntaxNode<R>, 1483pub struct MatchGuard {
1484 pub(crate) syntax: SyntaxNode,
2053} 1485}
2054pub type MatchGuard<'a> = MatchGuardNode<RefRoot<'a>>; 1486unsafe impl TransparentNewType for MatchGuard {
2055 1487 type Repr = rowan::SyntaxNode<RaTypes>;
2056impl<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}
2059impl<R: TreeRoot<RaTypes>> Eq for MatchGuardNode<R> {}
2060impl<R: TreeRoot<RaTypes>> Hash for MatchGuardNode<R> {
2061 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2062} 1488}
2063 1489
2064impl<'a> AstNode<'a> for MatchGuard<'a> { 1490impl AstNode for MatchGuard {
2065 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1491 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2066 match syntax.kind() { 1492 match syntax.kind() {
2067 MATCH_GUARD => Some(MatchGuard { syntax }), 1493 MATCH_GUARD => Some(MatchGuard::from_repr(syntax.into_repr())),
2068 _ => None, 1494 _ => None,
2069 } 1495 }
2070 } 1496 }
2071 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1497 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2072} 1498 fn to_owned(&self) -> TreePtr<MatchGuard> { TreePtr::cast(self.syntax.to_owned()) }
2073
2074impl<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} 1499}
2082 1500
2083 1501
2084impl<'a> MatchGuard<'a> {} 1502impl MatchGuard {}
2085 1503
2086// MethodCallExpr 1504// MethodCallExpr
2087#[derive(Debug, Clone, Copy,)] 1505#[derive(Debug, PartialEq, Eq, Hash)]
2088pub struct MethodCallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1506#[repr(transparent)]
2089 pub(crate) syntax: SyntaxNode<R>, 1507pub struct MethodCallExpr {
2090} 1508 pub(crate) syntax: SyntaxNode,
2091pub type MethodCallExpr<'a> = MethodCallExprNode<RefRoot<'a>>;
2092
2093impl<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} 1509}
2096impl<R: TreeRoot<RaTypes>> Eq for MethodCallExprNode<R> {} 1510unsafe impl TransparentNewType for MethodCallExpr {
2097impl<R: TreeRoot<RaTypes>> Hash for MethodCallExprNode<R> { 1511 type Repr = rowan::SyntaxNode<RaTypes>;
2098 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2099} 1512}
2100 1513
2101impl<'a> AstNode<'a> for MethodCallExpr<'a> { 1514impl AstNode for MethodCallExpr {
2102 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1515 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2103 match syntax.kind() { 1516 match syntax.kind() {
2104 METHOD_CALL_EXPR => Some(MethodCallExpr { syntax }), 1517 METHOD_CALL_EXPR => Some(MethodCallExpr::from_repr(syntax.into_repr())),
2105 _ => None, 1518 _ => None,
2106 } 1519 }
2107 } 1520 }
2108 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1521 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1522 fn to_owned(&self) -> TreePtr<MethodCallExpr> { TreePtr::cast(self.syntax.to_owned()) }
2109} 1523}
2110 1524
2111impl<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 1525
2120 1526impl ast::ArgListOwner for MethodCallExpr {}
2121impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} 1527impl MethodCallExpr {
2122impl<'a> MethodCallExpr<'a> { 1528 pub fn expr(&self) -> Option<&Expr> {
2123 pub fn expr(self) -> Option<Expr<'a>> {
2124 super::child_opt(self) 1529 super::child_opt(self)
2125 } 1530 }
2126 1531
2127 pub fn name_ref(self) -> Option<NameRef<'a>> { 1532 pub fn name_ref(&self) -> Option<&NameRef> {
2128 super::child_opt(self) 1533 super::child_opt(self)
2129 } 1534 }
2130} 1535}
2131 1536
2132// Module 1537// Module
2133#[derive(Debug, Clone, Copy,)] 1538#[derive(Debug, PartialEq, Eq, Hash)]
2134pub struct ModuleNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1539#[repr(transparent)]
2135 pub(crate) syntax: SyntaxNode<R>, 1540pub struct Module {
2136} 1541 pub(crate) syntax: SyntaxNode,
2137pub type Module<'a> = ModuleNode<RefRoot<'a>>;
2138
2139impl<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} 1542}
2142impl<R: TreeRoot<RaTypes>> Eq for ModuleNode<R> {} 1543unsafe impl TransparentNewType for Module {
2143impl<R: TreeRoot<RaTypes>> Hash for ModuleNode<R> { 1544 type Repr = rowan::SyntaxNode<RaTypes>;
2144 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2145} 1545}
2146