aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-07 13:16:02 +0000
committerAleksey Kladov <[email protected]>2019-01-08 08:20:15 +0000
commit5618c8ade1885ca17a56d9303a7559b332ae3e9e (patch)
tree8752ac3f18e2ef7461ccd67f688c2d459a710b0f /crates/ra_syntax/src/ast
parentd91a98ec843ec8562c58ccb01a1e29d00cc744dc (diff)
regenerate
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs4843
1 files changed, 1791 insertions, 3052 deletions
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 1546
2147impl<'a> AstNode<'a> for Module<'a> { 1547impl AstNode for Module {
2148 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1548 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2149 match syntax.kind() { 1549 match syntax.kind() {
2150 MODULE => Some(Module { syntax }), 1550 MODULE => Some(Module::from_repr(syntax.into_repr())),
2151 _ => None, 1551 _ => None,
2152 } 1552 }
2153 } 1553 }
2154 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1554 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1555 fn to_owned(&self) -> TreePtr<Module> { TreePtr::cast(self.syntax.to_owned()) }
2155} 1556}
2156 1557
2157impl<R: TreeRoot<RaTypes>> ModuleNode<R> {
2158 pub fn borrowed(&self) -> Module {
2159 ModuleNode { syntax: self.syntax.borrowed() }
2160 }
2161 pub fn owned(&self) -> ModuleNode {
2162 ModuleNode { syntax: self.syntax.owned() }
2163 }
2164}
2165 1558
2166 1559impl ast::VisibilityOwner for Module {}
2167impl<'a> ast::VisibilityOwner<'a> for Module<'a> {} 1560impl ast::NameOwner for Module {}
2168impl<'a> ast::NameOwner<'a> for Module<'a> {} 1561impl ast::AttrsOwner for Module {}
2169impl<'a> ast::AttrsOwner<'a> for Module<'a> {} 1562impl ast::DocCommentsOwner for Module {}
2170impl<'a> ast::DocCommentsOwner<'a> for Module<'a> {} 1563impl Module {
2171impl<'a> Module<'a> { 1564 pub fn item_list(&self) -> Option<&ItemList> {
2172 pub fn item_list(self) -> Option<ItemList<'a>> {
2173 super::child_opt(self) 1565 super::child_opt(self)
2174 } 1566 }
2175} 1567}
2176 1568
2177// ModuleItem 1569// ModuleItem
2178#[derive(Debug, Clone, Copy, PartialEq, Eq)] 1570#[derive(Debug, PartialEq, Eq, Hash)]
2179pub enum ModuleItem<'a> { 1571#[repr(transparent)]
2180 StructDef(StructDef<'a>), 1572pub struct ModuleItem {
2181 EnumDef(EnumDef<'a>), 1573 pub(crate) syntax: SyntaxNode,
2182 FnDef(FnDef<'a>), 1574}
2183 TraitDef(TraitDef<'a>), 1575unsafe impl TransparentNewType for ModuleItem {
2184 TypeDef(TypeDef<'a>), 1576 type Repr = rowan::SyntaxNode<RaTypes>;
2185 ImplBlock(ImplBlock<'a>),
2186 UseItem(UseItem<'a>),
2187 ExternCrateItem(ExternCrateItem<'a>),
2188 ConstDef(ConstDef<'a>),
2189 StaticDef(StaticDef<'a>),
2190 Module(Module<'a>),
2191}
2192
2193impl<'a> AstNode<'a> for ModuleItem<'a> {
2194 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
2195 match syntax.kind() {
2196 STRUCT_DEF => Some(ModuleItem::StructDef(StructDef { syntax })),
2197 ENUM_DEF => Some(ModuleItem::EnumDef(EnumDef { syntax })),
2198 FN_DEF => Some(ModuleItem::FnDef(FnDef { syntax })),
2199 TRAIT_DEF => Some(ModuleItem::TraitDef(TraitDef { syntax })),
2200 TYPE_DEF => Some(ModuleItem::TypeDef(TypeDef { syntax })),
2201 IMPL_BLOCK => Some(ModuleItem::ImplBlock(ImplBlock { syntax })),
2202 USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })),
2203 EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })),
2204 CONST_DEF => Some(ModuleItem::ConstDef(ConstDef { syntax })),
2205 STATIC_DEF => Some(ModuleItem::StaticDef(StaticDef { syntax })),
2206 MODULE => Some(ModuleItem::Module(Module { syntax })),
2207 _ => None,
2208 }
2209 }
2210 fn syntax(self) -> SyntaxNodeRef<'a> {
2211 match self {
2212 ModuleItem::StructDef(inner) => inner.syntax(),
2213 ModuleItem::EnumDef(inner) => inner.syntax(),
2214 ModuleItem::FnDef(inner) => inner.syntax(),
2215 ModuleItem::TraitDef(inner) => inner.syntax(),
2216 ModuleItem::TypeDef(inner) => inner.syntax(),
2217 ModuleItem::ImplBlock(inner) => inner.syntax(),
2218 ModuleItem::UseItem(inner) => inner.syntax(),
2219 ModuleItem::ExternCrateItem(inner) => inner.syntax(),
2220 ModuleItem::ConstDef(inner) => inner.syntax(),
2221 ModuleItem::StaticDef(inner) => inner.syntax(),
2222 ModuleItem::Module(inner) => inner.syntax(),
2223 }
2224 }
2225} 1577}
2226 1578
2227impl<'a> ModuleItem<'a> {} 1579#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1580pub enum ModuleItemKind<'a> {
1581 StructDef(&'a StructDef),
1582 EnumDef(&'a EnumDef),
1583 FnDef(&'a FnDef),
1584 TraitDef(&'a TraitDef),
1585 TypeDef(&'a TypeDef),
1586 ImplBlock(&'a ImplBlock),
1587 UseItem(&'a UseItem),
1588 ExternCrateItem(&'a ExternCrateItem),
1589 ConstDef(&'a ConstDef),
1590 StaticDef(&'a StaticDef),
1591 Module(&'a Module),
1592}
1593
1594impl AstNode for ModuleItem {
1595 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1596 match syntax.kind() {
1597 | STRUCT_DEF
1598 | ENUM_DEF
1599 | FN_DEF
1600 | TRAIT_DEF
1601 | TYPE_DEF
1602 | IMPL_BLOCK
1603 | USE_ITEM
1604 | EXTERN_CRATE_ITEM
1605 | CONST_DEF
1606 | STATIC_DEF
1607 | MODULE => Some(ModuleItem::from_repr(syntax.into_repr())),
1608 _ => None,
1609 }
1610 }
1611 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1612 fn to_owned(&self) -> TreePtr<ModuleItem> { TreePtr::cast(self.syntax.to_owned()) }
1613}
1614
1615impl ModuleItem {
1616 pub fn kind(&self) -> ModuleItemKind {
1617 match self.syntax.kind() {
1618 STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(&self.syntax).unwrap()),
1619 ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()),
1620 FN_DEF => ModuleItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()),
1621 TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(&self.syntax).unwrap()),
1622 TYPE_DEF => ModuleItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()),
1623 IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(&self.syntax).unwrap()),
1624 USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(&self.syntax).unwrap()),
1625 EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(&self.syntax).unwrap()),
1626 CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()),
1627 STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(&self.syntax).unwrap()),
1628 MODULE => ModuleItemKind::Module(Module::cast(&self.syntax).unwrap()),
1629 _ => unreachable!(),
1630 }
1631 }
1632}
1633
1634impl ModuleItem {}
2228 1635
2229// Name 1636// Name
2230#[derive(Debug, Clone, Copy,)] 1637#[derive(Debug, PartialEq, Eq, Hash)]
2231pub struct NameNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1638#[repr(transparent)]
2232 pub(crate) syntax: SyntaxNode<R>, 1639pub struct Name {
2233} 1640 pub(crate) syntax: SyntaxNode,
2234pub type Name<'a> = NameNode<RefRoot<'a>>;
2235
2236impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameNode<R1>> for NameNode<R2> {
2237 fn eq(&self, other: &NameNode<R1>) -> bool { self.syntax == other.syntax }
2238} 1641}
2239impl<R: TreeRoot<RaTypes>> Eq for NameNode<R> {} 1642unsafe impl TransparentNewType for Name {
2240impl<R: TreeRoot<RaTypes>> Hash for NameNode<R> { 1643 type Repr = rowan::SyntaxNode<RaTypes>;
2241 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2242} 1644}
2243 1645
2244impl<'a> AstNode<'a> for Name<'a> { 1646impl AstNode for Name {
2245 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1647 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2246 match syntax.kind() { 1648 match syntax.kind() {
2247 NAME => Some(Name { syntax }), 1649 NAME => Some(Name::from_repr(syntax.into_repr())),
2248 _ => None, 1650 _ => None,
2249 } 1651 }
2250 } 1652 }
2251 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1653 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1654 fn to_owned(&self) -> TreePtr<Name> { TreePtr::cast(self.syntax.to_owned()) }
2252} 1655}
2253 1656
2254impl<R: TreeRoot<RaTypes>> NameNode<R> {
2255 pub fn borrowed(&self) -> Name {
2256 NameNode { syntax: self.syntax.borrowed() }
2257 }
2258 pub fn owned(&self) -> NameNode {
2259 NameNode { syntax: self.syntax.owned() }
2260 }
2261}
2262 1657
2263 1658impl Name {}
2264impl<'a> Name<'a> {}
2265 1659
2266// NameRef 1660// NameRef
2267#[derive(Debug, Clone, Copy,)] 1661#[derive(Debug, PartialEq, Eq, Hash)]
2268pub struct NameRefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1662#[repr(transparent)]
2269 pub(crate) syntax: SyntaxNode<R>, 1663pub struct NameRef {
2270} 1664 pub(crate) syntax: SyntaxNode,
2271pub type NameRef<'a> = NameRefNode<RefRoot<'a>>;
2272
2273impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameRefNode<R1>> for NameRefNode<R2> {
2274 fn eq(&self, other: &NameRefNode<R1>) -> bool { self.syntax == other.syntax }
2275} 1665}
2276impl<R: TreeRoot<RaTypes>> Eq for NameRefNode<R> {} 1666unsafe impl TransparentNewType for NameRef {
2277impl<R: TreeRoot<RaTypes>> Hash for NameRefNode<R> { 1667 type Repr = rowan::SyntaxNode<RaTypes>;
2278 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2279} 1668}
2280 1669
2281impl<'a> AstNode<'a> for NameRef<'a> { 1670impl AstNode for NameRef {
2282 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1671 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2283 match syntax.kind() { 1672 match syntax.kind() {
2284 NAME_REF => Some(NameRef { syntax }), 1673 NAME_REF => Some(NameRef::from_repr(syntax.into_repr())),
2285 _ => None, 1674 _ => None,
2286 } 1675 }
2287 } 1676 }
2288 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1677 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1678 fn to_owned(&self) -> TreePtr<NameRef> { TreePtr::cast(self.syntax.to_owned()) }
2289} 1679}
2290 1680
2291impl<R: TreeRoot<RaTypes>> NameRefNode<R> {
2292 pub fn borrowed(&self) -> NameRef {
2293 NameRefNode { syntax: self.syntax.borrowed() }
2294 }
2295 pub fn owned(&self) -> NameRefNode {
2296 NameRefNode { syntax: self.syntax.owned() }
2297 }
2298}
2299 1681
2300 1682impl NameRef {}
2301impl<'a> NameRef<'a> {}
2302 1683
2303// NamedField 1684// NamedField
2304#[derive(Debug, Clone, Copy,)] 1685#[derive(Debug, PartialEq, Eq, Hash)]
2305pub struct NamedFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1686#[repr(transparent)]
2306 pub(crate) syntax: SyntaxNode<R>, 1687pub struct NamedField {
1688 pub(crate) syntax: SyntaxNode,
2307} 1689}
2308pub type NamedField<'a> = NamedFieldNode<RefRoot<'a>>; 1690unsafe impl TransparentNewType for NamedField {
2309 1691 type Repr = rowan::SyntaxNode<RaTypes>;
2310impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldNode<R1>> for NamedFieldNode<R2> {
2311 fn eq(&self, other: &NamedFieldNode<R1>) -> bool { self.syntax == other.syntax }
2312}
2313impl<R: TreeRoot<RaTypes>> Eq for NamedFieldNode<R> {}
2314impl<R: TreeRoot<RaTypes>> Hash for NamedFieldNode<R> {
2315 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2316} 1692}
2317 1693
2318impl<'a> AstNode<'a> for NamedField<'a> { 1694impl AstNode for NamedField {
2319 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1695 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2320 match syntax.kind() { 1696 match syntax.kind() {
2321 NAMED_FIELD => Some(NamedField { syntax }), 1697 NAMED_FIELD => Some(NamedField::from_repr(syntax.into_repr())),
2322 _ => None, 1698 _ => None,
2323 } 1699 }
2324 } 1700 }
2325 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1701 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2326} 1702 fn to_owned(&self) -> TreePtr<NamedField> { TreePtr::cast(self.syntax.to_owned()) }
2327
2328impl<R: TreeRoot<RaTypes>> NamedFieldNode<R> {
2329 pub fn borrowed(&self) -> NamedField {
2330 NamedFieldNode { syntax: self.syntax.borrowed() }
2331 }
2332 pub fn owned(&self) -> NamedFieldNode {
2333 NamedFieldNode { syntax: self.syntax.owned() }
2334 }
2335} 1703}
2336 1704
2337 1705
2338impl<'a> NamedField<'a> { 1706impl NamedField {
2339 pub fn name_ref(self) -> Option<NameRef<'a>> { 1707 pub fn name_ref(&self) -> Option<&NameRef> {
2340 super::child_opt(self) 1708 super::child_opt(self)
2341 } 1709 }
2342 1710
2343 pub fn expr(self) -> Option<Expr<'a>> { 1711 pub fn expr(&self) -> Option<&Expr> {
2344 super::child_opt(self) 1712 super::child_opt(self)
2345 } 1713 }
2346} 1714}
2347 1715
2348// NamedFieldDef 1716// NamedFieldDef
2349#[derive(Debug, Clone, Copy,)] 1717#[derive(Debug, PartialEq, Eq, Hash)]
2350pub struct NamedFieldDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1718#[repr(transparent)]
2351 pub(crate) syntax: SyntaxNode<R>, 1719pub struct NamedFieldDef {
1720 pub(crate) syntax: SyntaxNode,
2352} 1721}
2353pub type NamedFieldDef<'a> = NamedFieldDefNode<RefRoot<'a>>; 1722unsafe impl TransparentNewType for NamedFieldDef {
2354 1723 type Repr = rowan::SyntaxNode<RaTypes>;
2355impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefNode<R1>> for NamedFieldDefNode<R2> {
2356 fn eq(&self, other: &NamedFieldDefNode<R1>) -> bool { self.syntax == other.syntax }
2357}
2358impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefNode<R> {}
2359impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefNode<R> {
2360 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2361} 1724}
2362 1725
2363impl<'a> AstNode<'a> for NamedFieldDef<'a> { 1726impl AstNode for NamedFieldDef {
2364 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1727 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2365 match syntax.kind() { 1728 match syntax.kind() {
2366 NAMED_FIELD_DEF => Some(NamedFieldDef { syntax }), 1729 NAMED_FIELD_DEF => Some(NamedFieldDef::from_repr(syntax.into_repr())),
2367 _ => None, 1730 _ => None,
2368 } 1731 }
2369 } 1732 }
2370 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1733 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1734 fn to_owned(&self) -> TreePtr<NamedFieldDef> { TreePtr::cast(self.syntax.to_owned()) }
2371} 1735}
2372 1736
2373impl<R: TreeRoot<RaTypes>> NamedFieldDefNode<R> {
2374 pub fn borrowed(&self) -> NamedFieldDef {
2375 NamedFieldDefNode { syntax: self.syntax.borrowed() }
2376 }
2377 pub fn owned(&self) -> NamedFieldDefNode {
2378 NamedFieldDefNode { syntax: self.syntax.owned() }
2379 }
2380}
2381 1737
2382 1738impl ast::VisibilityOwner for NamedFieldDef {}
2383impl<'a> ast::VisibilityOwner<'a> for NamedFieldDef<'a> {} 1739impl ast::NameOwner for NamedFieldDef {}
2384impl<'a> ast::NameOwner<'a> for NamedFieldDef<'a> {} 1740impl ast::AttrsOwner for NamedFieldDef {}
2385impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {} 1741impl NamedFieldDef {
2386impl<'a> NamedFieldDef<'a> { 1742 pub fn type_ref(&self) -> Option<&TypeRef> {
2387 pub fn type_ref(self) -> Option<TypeRef<'a>> {
2388 super::child_opt(self) 1743 super::child_opt(self)
2389 } 1744 }
2390} 1745}
2391 1746
2392// NamedFieldDefList 1747// NamedFieldDefList
2393#[derive(Debug, Clone, Copy,)] 1748#[derive(Debug, PartialEq, Eq, Hash)]
2394pub struct NamedFieldDefListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1749#[repr(transparent)]
2395 pub(crate) syntax: SyntaxNode<R>, 1750pub struct NamedFieldDefList {
2396} 1751 pub(crate) syntax: SyntaxNode,
2397pub type NamedFieldDefList<'a> = NamedFieldDefListNode<RefRoot<'a>>;
2398
2399impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefListNode<R1>> for NamedFieldDefListNode<R2> {
2400 fn eq(&self, other: &NamedFieldDefListNode<R1>) -> bool { self.syntax == other.syntax }
2401} 1752}
2402impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefListNode<R> {} 1753unsafe impl TransparentNewType for NamedFieldDefList {
2403impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefListNode<R> { 1754 type Repr = rowan::SyntaxNode<RaTypes>;
2404 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2405} 1755}
2406 1756
2407impl<'a> AstNode<'a> for NamedFieldDefList<'a> { 1757impl AstNode for NamedFieldDefList {
2408 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1758 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2409 match syntax.kind() { 1759 match syntax.kind() {
2410 NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList { syntax }), 1760 NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList::from_repr(syntax.into_repr())),
2411 _ => None, 1761 _ => None,
2412 } 1762 }
2413 } 1763 }
2414 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1764 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1765 fn to_owned(&self) -> TreePtr<NamedFieldDefList> { TreePtr::cast(self.syntax.to_owned()) }
2415} 1766}
2416 1767
2417impl<R: TreeRoot<RaTypes>> NamedFieldDefListNode<R> {
2418 pub fn borrowed(&self) -> NamedFieldDefList {
2419 NamedFieldDefListNode { syntax: self.syntax.borrowed() }
2420 }
2421 pub fn owned(&self) -> NamedFieldDefListNode {
2422 NamedFieldDefListNode { syntax: self.syntax.owned() }
2423 }
2424}
2425 1768
2426 1769impl NamedFieldDefList {
2427impl<'a> NamedFieldDefList<'a> { 1770 pub fn fields(&self) -> impl Iterator<Item = &NamedFieldDef> {
2428 pub fn fields(self) -> impl Iterator<Item = NamedFieldDef<'a>> + 'a {
2429 super::children(self) 1771 super::children(self)
2430 } 1772 }
2431} 1773}
2432 1774
2433// NamedFieldList 1775// NamedFieldList
2434#[derive(Debug, Clone, Copy,)] 1776#[derive(Debug, PartialEq, Eq, Hash)]
2435pub struct NamedFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1777#[repr(transparent)]
2436 pub(crate) syntax: SyntaxNode<R>, 1778pub struct NamedFieldList {
2437} 1779 pub(crate) syntax: SyntaxNode,
2438pub type NamedFieldList<'a> = NamedFieldListNode<RefRoot<'a>>;
2439
2440impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldListNode<R1>> for NamedFieldListNode<R2> {
2441 fn eq(&self, other: &NamedFieldListNode<R1>) -> bool { self.syntax == other.syntax }
2442} 1780}
2443impl<R: TreeRoot<RaTypes>> Eq for NamedFieldListNode<R> {} 1781unsafe impl TransparentNewType for NamedFieldList {
2444impl<R: TreeRoot<RaTypes>> Hash for NamedFieldListNode<R> { 1782 type Repr = rowan::SyntaxNode<RaTypes>;
2445 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2446} 1783}
2447 1784
2448impl<'a> AstNode<'a> for NamedFieldList<'a> { 1785impl AstNode for NamedFieldList {
2449 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1786 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2450 match syntax.kind() { 1787 match syntax.kind() {
2451 NAMED_FIELD_LIST => Some(NamedFieldList { syntax }), 1788 NAMED_FIELD_LIST => Some(NamedFieldList::from_repr(syntax.into_repr())),
2452 _ => None, 1789 _ => None,
2453 } 1790 }
2454 } 1791 }
2455 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1792 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2456} 1793 fn to_owned(&self) -> TreePtr<NamedFieldList> { TreePtr::cast(self.syntax.to_owned()) }
2457
2458impl<R: TreeRoot<RaTypes>> NamedFieldListNode<R> {
2459 pub fn borrowed(&self) -> NamedFieldList {
2460 NamedFieldListNode { syntax: self.syntax.borrowed() }
2461 }
2462 pub fn owned(&self) -> NamedFieldListNode {
2463 NamedFieldListNode { syntax: self.syntax.owned() }
2464 }
2465} 1794}
2466 1795
2467 1796
2468impl<'a> NamedFieldList<'a> { 1797impl NamedFieldList {
2469 pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a { 1798 pub fn fields(&self) -> impl Iterator<Item = &NamedField> {
2470 super::children(self) 1799 super::children(self)
2471 } 1800 }
2472} 1801}
2473 1802
2474// NeverType 1803// NeverType
2475#[derive(Debug, Clone, Copy,)] 1804#[derive(Debug, PartialEq, Eq, Hash)]
2476pub struct NeverTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1805#[repr(transparent)]
2477 pub(crate) syntax: SyntaxNode<R>, 1806pub struct NeverType {
2478} 1807 pub(crate) syntax: SyntaxNode,
2479pub type NeverType<'a> = NeverTypeNode<RefRoot<'a>>;
2480
2481impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NeverTypeNode<R1>> for NeverTypeNode<R2> {
2482 fn eq(&self, other: &NeverTypeNode<R1>) -> bool { self.syntax == other.syntax }
2483} 1808}
2484impl<R: TreeRoot<RaTypes>> Eq for NeverTypeNode<R> {} 1809unsafe impl TransparentNewType for NeverType {
2485impl<R: TreeRoot<RaTypes>> Hash for NeverTypeNode<R> { 1810 type Repr = rowan::SyntaxNode<RaTypes>;
2486 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2487} 1811}
2488 1812
2489impl<'a> AstNode<'a> for NeverType<'a> { 1813impl AstNode for NeverType {
2490 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1814 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2491 match syntax.kind() { 1815 match syntax.kind() {
2492 NEVER_TYPE => Some(NeverType { syntax }), 1816 NEVER_TYPE => Some(NeverType::from_repr(syntax.into_repr())),
2493 _ => None, 1817 _ => None,
2494 } 1818 }
2495 } 1819 }
2496 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1820 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2497} 1821 fn to_owned(&self) -> TreePtr<NeverType> { TreePtr::cast(self.syntax.to_owned()) }
2498
2499impl<R: TreeRoot<RaTypes>> NeverTypeNode<R> {
2500 pub fn borrowed(&self) -> NeverType {
2501 NeverTypeNode { syntax: self.syntax.borrowed() }
2502 }
2503 pub fn owned(&self) -> NeverTypeNode {
2504 NeverTypeNode { syntax: self.syntax.owned() }
2505 }
2506} 1822}
2507 1823
2508 1824
2509impl<'a> NeverType<'a> {} 1825impl NeverType {}
2510 1826
2511// NominalDef 1827// NominalDef
1828#[derive(Debug, PartialEq, Eq, Hash)]
1829#[repr(transparent)]
1830pub struct NominalDef {
1831 pub(crate) syntax: SyntaxNode,
1832}
1833unsafe impl TransparentNewType for NominalDef {
1834 type Repr = rowan::SyntaxNode<RaTypes>;
1835}
1836
2512#[derive(Debug, Clone, Copy, PartialEq, Eq)] 1837#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2513pub enum NominalDef<'a> { 1838pub enum NominalDefKind<'a> {
2514 StructDef(StructDef<'a>), 1839 StructDef(&'a StructDef),
2515 EnumDef(EnumDef<'a>), 1840 EnumDef(&'a EnumDef),
2516} 1841}
2517 1842
2518impl<'a> AstNode<'a> for NominalDef<'a> { 1843impl AstNode for NominalDef {
2519 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1844 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2520 match syntax.kind() { 1845 match syntax.kind() {
2521 STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })), 1846 | STRUCT_DEF
2522 ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })), 1847 | ENUM_DEF => Some(NominalDef::from_repr(syntax.into_repr())),
2523 _ => None, 1848 _ => None,
2524 } 1849 }
2525 } 1850 }
2526 fn syntax(self) -> SyntaxNodeRef<'a> { 1851 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2527 match self { 1852 fn to_owned(&self) -> TreePtr<NominalDef> { TreePtr::cast(self.syntax.to_owned()) }
2528 NominalDef::StructDef(inner) => inner.syntax(), 1853}
2529 NominalDef::EnumDef(inner) => inner.syntax(), 1854
1855impl NominalDef {
1856 pub fn kind(&self) -> NominalDefKind {
1857 match self.syntax.kind() {
1858 STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(&self.syntax).unwrap()),
1859 ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()),
1860 _ => unreachable!(),
2530 } 1861 }
2531 } 1862 }
2532} 1863}
2533 1864
2534impl<'a> ast::NameOwner<'a> for NominalDef<'a> {} 1865impl ast::NameOwner for NominalDef {}
2535impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {} 1866impl ast::TypeParamsOwner for NominalDef {}
2536impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} 1867impl ast::AttrsOwner for NominalDef {}
2537impl<'a> NominalDef<'a> {} 1868impl NominalDef {}
2538 1869
2539// Param 1870// Param
2540#[derive(Debug, Clone, Copy,)] 1871#[derive(Debug, PartialEq, Eq, Hash)]
2541pub struct ParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1872#[repr(transparent)]
2542 pub(crate) syntax: SyntaxNode<R>, 1873pub struct Param {
2543} 1874 pub(crate) syntax: SyntaxNode,
2544pub type Param<'a> = ParamNode<RefRoot<'a>>;
2545
2546impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamNode<R1>> for ParamNode<R2> {
2547 fn eq(&self, other: &ParamNode<R1>) -> bool { self.syntax == other.syntax }
2548} 1875}
2549impl<R: TreeRoot<RaTypes>> Eq for ParamNode<R> {} 1876unsafe impl TransparentNewType for Param {
2550impl<R: TreeRoot<RaTypes>> Hash for ParamNode<R> { 1877 type Repr = rowan::SyntaxNode<RaTypes>;
2551 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2552} 1878}
2553 1879
2554impl<'a> AstNode<'a> for Param<'a> { 1880impl AstNode for Param {
2555 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1881 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2556 match syntax.kind() { 1882 match syntax.kind() {
2557 PARAM => Some(Param { syntax }), 1883 PARAM => Some(Param::from_repr(syntax.into_repr())),
2558 _ => None, 1884 _ => None,
2559 } 1885 }
2560 } 1886 }
2561 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1887 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2562} 1888 fn to_owned(&self) -> TreePtr<Param> { TreePtr::cast(self.syntax.to_owned()) }
2563
2564impl<R: TreeRoot<RaTypes>> ParamNode<R> {
2565 pub fn borrowed(&self) -> Param {
2566 ParamNode { syntax: self.syntax.borrowed() }
2567 }
2568 pub fn owned(&self) -> ParamNode {
2569 ParamNode { syntax: self.syntax.owned() }
2570 }
2571} 1889}
2572 1890
2573 1891
2574impl<'a> Param<'a> { 1892impl Param {
2575 pub fn pat(self) -> Option<Pat<'a>> { 1893 pub fn pat(&self) -> Option<&Pat> {
2576 super::child_opt(self) 1894 super::child_opt(self)
2577 } 1895 }
2578 1896
2579 pub fn type_ref(self) -> Option<TypeRef<'a>> { 1897 pub fn type_ref(&self) -> Option<&TypeRef> {
2580 super::child_opt(self) 1898 super::child_opt(self)
2581 } 1899 }
2582} 1900}
2583 1901
2584// ParamList 1902// ParamList
2585#[derive(Debug, Clone, Copy,)] 1903#[derive(Debug, PartialEq, Eq, Hash)]
2586pub struct ParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1904#[repr(transparent)]
2587 pub(crate) syntax: SyntaxNode<R>, 1905pub struct ParamList {
1906 pub(crate) syntax: SyntaxNode,
2588} 1907}
2589pub type ParamList<'a> = ParamListNode<RefRoot<'a>>; 1908unsafe impl TransparentNewType for ParamList {
2590 1909 type Repr = rowan::SyntaxNode<RaTypes>;
2591impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamListNode<R1>> for ParamListNode<R2> {
2592 fn eq(&self, other: &ParamListNode<R1>) -> bool { self.syntax == other.syntax }
2593}
2594impl<R: TreeRoot<RaTypes>> Eq for ParamListNode<R> {}
2595impl<R: TreeRoot<RaTypes>> Hash for ParamListNode<R> {
2596 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2597} 1910}
2598 1911
2599impl<'a> AstNode<'a> for ParamList<'a> { 1912impl AstNode for ParamList {
2600 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1913 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2601 match syntax.kind() { 1914 match syntax.kind() {
2602 PARAM_LIST => Some(ParamList { syntax }), 1915 PARAM_LIST => Some(ParamList::from_repr(syntax.into_repr())),
2603 _ => None, 1916 _ => None,
2604 } 1917 }
2605 } 1918 }
2606 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1919 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2607} 1920 fn to_owned(&self) -> TreePtr<ParamList> { TreePtr::cast(self.syntax.to_owned()) }
2608
2609impl<R: TreeRoot<RaTypes>> ParamListNode<R> {
2610 pub fn borrowed(&self) -> ParamList {
2611 ParamListNode { syntax: self.syntax.borrowed() }
2612 }
2613 pub fn owned(&self) -> ParamListNode {
2614 ParamListNode { syntax: self.syntax.owned() }
2615 }
2616} 1921}
2617 1922
2618 1923
2619impl<'a> ParamList<'a> { 1924impl ParamList {
2620 pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { 1925 pub fn params(&self) -> impl Iterator<Item = &Param> {
2621 super::children(self) 1926 super::children(self)
2622 } 1927 }
2623 1928
2624 pub fn self_param(self) -> Option<SelfParam<'a>> { 1929 pub fn self_param(&self) -> Option<&SelfParam> {
2625 super::child_opt(self) 1930 super::child_opt(self)
2626 } 1931 }
2627} 1932}
2628 1933
2629// ParenExpr 1934// ParenExpr
2630#[derive(Debug, Clone, Copy,)] 1935#[derive(Debug, PartialEq, Eq, Hash)]
2631pub struct ParenExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1936#[repr(transparent)]
2632 pub(crate) syntax: SyntaxNode<R>, 1937pub struct ParenExpr {
2633} 1938 pub(crate) syntax: SyntaxNode,
2634pub type ParenExpr<'a> = ParenExprNode<RefRoot<'a>>;
2635
2636impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenExprNode<R1>> for ParenExprNode<R2> {
2637 fn eq(&self, other: &ParenExprNode<R1>) -> bool { self.syntax == other.syntax }
2638} 1939}
2639impl<R: TreeRoot<RaTypes>> Eq for ParenExprNode<R> {} 1940unsafe impl TransparentNewType for ParenExpr {
2640impl<R: TreeRoot<RaTypes>> Hash for ParenExprNode<R> { 1941 type Repr = rowan::SyntaxNode<RaTypes>;
2641 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2642} 1942}
2643 1943
2644impl<'a> AstNode<'a> for ParenExpr<'a> { 1944impl AstNode for ParenExpr {
2645 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1945 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2646 match syntax.kind() { 1946 match syntax.kind() {
2647 PAREN_EXPR => Some(ParenExpr { syntax }), 1947 PAREN_EXPR => Some(ParenExpr::from_repr(syntax.into_repr())),
2648 _ => None, 1948 _ => None,
2649 } 1949 }
2650 } 1950 }
2651 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1951 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1952 fn to_owned(&self) -> TreePtr<ParenExpr> { TreePtr::cast(self.syntax.to_owned()) }
2652} 1953}
2653 1954
2654impl<R: TreeRoot<RaTypes>> ParenExprNode<R> {
2655 pub fn borrowed(&self) -> ParenExpr {
2656 ParenExprNode { syntax: self.syntax.borrowed() }
2657 }
2658 pub fn owned(&self) -> ParenExprNode {
2659 ParenExprNode { syntax: self.syntax.owned() }
2660 }
2661}
2662 1955
2663 1956impl ParenExpr {
2664impl<'a> ParenExpr<'a> { 1957 pub fn expr(&self) -> Option<&Expr> {
2665 pub fn expr(self) -> Option<Expr<'a>> {
2666 super::child_opt(self) 1958 super::child_opt(self)
2667 } 1959 }
2668} 1960}
2669 1961
2670// ParenType 1962// ParenType
2671#[derive(Debug, Clone, Copy,)] 1963#[derive(Debug, PartialEq, Eq, Hash)]
2672pub struct ParenTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1964#[repr(transparent)]
2673 pub(crate) syntax: SyntaxNode<R>, 1965pub struct ParenType {
1966 pub(crate) syntax: SyntaxNode,
2674} 1967}
2675pub type ParenType<'a> = ParenTypeNode<RefRoot<'a>>; 1968unsafe impl TransparentNewType for ParenType {
2676 1969 type Repr = rowan::SyntaxNode<RaTypes>;
2677impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenTypeNode<R1>> for ParenTypeNode<R2> {
2678 fn eq(&self, other: &ParenTypeNode<R1>) -> bool { self.syntax == other.syntax }
2679}
2680impl<R: TreeRoot<RaTypes>> Eq for ParenTypeNode<R> {}
2681impl<R: TreeRoot<RaTypes>> Hash for ParenTypeNode<R> {
2682 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2683} 1970}
2684 1971
2685impl<'a> AstNode<'a> for ParenType<'a> { 1972impl AstNode for ParenType {
2686 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 1973 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2687 match syntax.kind() { 1974 match syntax.kind() {
2688 PAREN_TYPE => Some(ParenType { syntax }), 1975 PAREN_TYPE => Some(ParenType::from_repr(syntax.into_repr())),
2689 _ => None, 1976 _ => None,
2690 } 1977 }
2691 } 1978 }
2692 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1979 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2693} 1980 fn to_owned(&self) -> TreePtr<ParenType> { TreePtr::cast(self.syntax.to_owned()) }
2694
2695impl<R: TreeRoot<RaTypes>> ParenTypeNode<R> {
2696 pub fn borrowed(&self) -> ParenType {
2697 ParenTypeNode { syntax: self.syntax.borrowed() }
2698 }
2699 pub fn owned(&self) -> ParenTypeNode {
2700 ParenTypeNode { syntax: self.syntax.owned() }
2701 }
2702} 1981}
2703 1982
2704 1983
2705impl<'a> ParenType<'a> { 1984impl ParenType {
2706 pub fn type_ref(self) -> Option<TypeRef<'a>> { 1985 pub fn type_ref(&self) -> Option<&TypeRef> {
2707 super::child_opt(self) 1986 super::child_opt(self)
2708 } 1987 }
2709} 1988}
2710 1989
2711// Pat 1990// Pat
1991#[derive(Debug, PartialEq, Eq, Hash)]
1992#[repr(transparent)]
1993pub struct Pat {
1994 pub(crate) syntax: SyntaxNode,
1995}
1996unsafe impl TransparentNewType for Pat {
1997 type Repr = rowan::SyntaxNode<RaTypes>;
1998}
1999
2712#[derive(Debug, Clone, Copy, PartialEq, Eq)] 2000#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2713pub enum Pat<'a> { 2001pub enum PatKind<'a> {
2714 RefPat(RefPat<'a>), 2002 RefPat(&'a RefPat),
2715 BindPat(BindPat<'a>), 2003 BindPat(&'a BindPat),
2716 PlaceholderPat(PlaceholderPat<'a>), 2004 PlaceholderPat(&'a PlaceholderPat),
2717 PathPat(PathPat<'a>), 2005 PathPat(&'a PathPat),
2718 StructPat(StructPat<'a>), 2006 StructPat(&'a StructPat),
2719 FieldPatList(FieldPatList<'a>), 2007 FieldPatList(&'a FieldPatList),
2720 TupleStructPat(TupleStructPat<'a>), 2008 TupleStructPat(&'a TupleStructPat),
2721 TuplePat(TuplePat<'a>), 2009 TuplePat(&'a TuplePat),
2722 SlicePat(SlicePat<'a>), 2010 SlicePat(&'a SlicePat),
2723 RangePat(RangePat<'a>), 2011 RangePat(&'a RangePat),
2724} 2012}
2725 2013
2726impl<'a> AstNode<'a> for Pat<'a> { 2014impl AstNode for Pat {
2727 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2015 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2728 match syntax.kind() { 2016 match syntax.kind() {
2729 REF_PAT => Some(Pat::RefPat(RefPat { syntax })), 2017 | REF_PAT
2730 BIND_PAT => Some(Pat::BindPat(BindPat { syntax })), 2018 | BIND_PAT
2731 PLACEHOLDER_PAT => Some(Pat::PlaceholderPat(PlaceholderPat { syntax })), 2019 | PLACEHOLDER_PAT
2732 PATH_PAT => Some(Pat::PathPat(PathPat { syntax })), 2020 | PATH_PAT
2733 STRUCT_PAT => Some(Pat::StructPat(StructPat { syntax })), 2021 | STRUCT_PAT
2734 FIELD_PAT_LIST => Some(Pat::FieldPatList(FieldPatList { syntax })), 2022 | FIELD_PAT_LIST
2735 TUPLE_STRUCT_PAT => Some(Pat::TupleStructPat(TupleStructPat { syntax })), 2023 | TUPLE_STRUCT_PAT
2736 TUPLE_PAT => Some(Pat::TuplePat(TuplePat { syntax })), 2024 | TUPLE_PAT
2737 SLICE_PAT => Some(Pat::SlicePat(SlicePat { syntax })), 2025 | SLICE_PAT
2738 RANGE_PAT => Some(Pat::RangePat(RangePat { syntax })), 2026 | RANGE_PAT => Some(Pat::from_repr(syntax.into_repr())),
2739 _ => None, 2027 _ => None,
2740 } 2028 }
2741 } 2029 }
2742 fn syntax(self) -> SyntaxNodeRef<'a> { 2030 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2743 match self { 2031 fn to_owned(&self) -> TreePtr<Pat> { TreePtr::cast(self.syntax.to_owned()) }
2744 Pat::RefPat(inner) => inner.syntax(), 2032}
2745 Pat::BindPat(inner) => inner.syntax(), 2033
2746 Pat::PlaceholderPat(inner) => inner.syntax(), 2034impl Pat {
2747 Pat::PathPat(inner) => inner.syntax(), 2035 pub fn kind(&self) -> PatKind {
2748 Pat::StructPat(inner) => inner.syntax(), 2036 match self.syntax.kind() {
2749 Pat::FieldPatList(inner) => inner.syntax(), 2037 REF_PAT => PatKind::RefPat(RefPat::cast(&self.syntax).unwrap()),
2750 Pat::TupleStructPat(inner) => inner.syntax(), 2038 BIND_PAT => PatKind::BindPat(BindPat::cast(&self.syntax).unwrap()),
2751 Pat::TuplePat(inner) => inner.syntax(), 2039 PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(&self.syntax).unwrap()),
2752 Pat::SlicePat(inner) => inner.syntax(), 2040 PATH_PAT => PatKind::PathPat(PathPat::cast(&self.syntax).unwrap()),
2753 Pat::RangePat(inner) => inner.syntax(), 2041 STRUCT_PAT => PatKind::StructPat(StructPat::cast(&self.syntax).unwrap()),
2042 FIELD_PAT_LIST => PatKind::FieldPatList(FieldPatList::cast(&self.syntax).unwrap()),
2043 TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(&self.syntax).unwrap()),
2044 TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(&self.syntax).unwrap()),
2045 SLICE_PAT => PatKind::SlicePat(SlicePat::cast(&self.syntax).unwrap()),
2046 RANGE_PAT => PatKind::RangePat(RangePat::cast(&self.syntax).unwrap()),
2047 _ => unreachable!(),
2754 } 2048 }
2755 } 2049 }
2756} 2050}
2757 2051
2758impl<'a> Pat<'a> {} 2052impl Pat {}
2759 2053
2760// Path 2054// Path
2761#[derive(Debug, Clone, Copy,)] 2055#[derive(Debug, PartialEq, Eq, Hash)]
2762pub struct PathNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2056#[repr(transparent)]
2763 pub(crate) syntax: SyntaxNode<R>, 2057pub struct Path {
2764} 2058 pub(crate) syntax: SyntaxNode,
2765pub type Path<'a> = PathNode<RefRoot<'a>>;
2766
2767impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathNode<R1>> for PathNode<R2> {
2768 fn eq(&self, other: &PathNode<R1>) -> bool { self.syntax == other.syntax }
2769} 2059}
2770impl<R: TreeRoot<RaTypes>> Eq for PathNode<R> {} 2060unsafe impl TransparentNewType for Path {
2771impl<R: TreeRoot<RaTypes>> Hash for PathNode<R> { 2061 type Repr = rowan::SyntaxNode<RaTypes>;
2772 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2773} 2062}
2774 2063
2775impl<'a> AstNode<'a> for Path<'a> { 2064impl AstNode for Path {
2776 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2065 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2777 match syntax.kind() { 2066 match syntax.kind() {
2778 PATH => Some(Path { syntax }), 2067 PATH => Some(Path::from_repr(syntax.into_repr())),
2779 _ => None, 2068 _ => None,
2780 } 2069 }
2781 } 2070 }
2782 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2071 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2783} 2072 fn to_owned(&self) -> TreePtr<Path> { TreePtr::cast(self.syntax.to_owned()) }
2784
2785impl<R: TreeRoot<RaTypes>> PathNode<R> {
2786 pub fn borrowed(&self) -> Path {
2787 PathNode { syntax: self.syntax.borrowed() }
2788 }
2789 pub fn owned(&self) -> PathNode {
2790 PathNode { syntax: self.syntax.owned() }
2791 }
2792} 2073}
2793 2074
2794 2075
2795impl<'a> Path<'a> { 2076impl Path {
2796 pub fn segment(self) -> Option<PathSegment<'a>> { 2077 pub fn segment(&self) -> Option<&PathSegment> {
2797 super::child_opt(self) 2078 super::child_opt(self)
2798 } 2079 }
2799 2080
2800 pub fn qualifier(self) -> Option<Path<'a>> { 2081 pub fn qualifier(&self) -> Option<&Path> {
2801 super::child_opt(self) 2082 super::child_opt(self)
2802 } 2083 }
2803} 2084}
2804 2085
2805// PathExpr 2086// PathExpr
2806#[derive(Debug, Clone, Copy,)] 2087#[derive(Debug, PartialEq, Eq, Hash)]
2807pub struct PathExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2088#[repr(transparent)]
2808 pub(crate) syntax: SyntaxNode<R>, 2089pub struct PathExpr {
2090 pub(crate) syntax: SyntaxNode,
2809} 2091}
2810pub type PathExpr<'a> = PathExprNode<RefRoot<'a>>; 2092unsafe impl TransparentNewType for PathExpr {
2811 2093 type Repr = rowan::SyntaxNode<RaTypes>;
2812impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathExprNode<R1>> for PathExprNode<R2> {
2813 fn eq(&self, other: &PathExprNode<R1>) -> bool { self.syntax == other.syntax }
2814}
2815impl<R: TreeRoot<RaTypes>> Eq for PathExprNode<R> {}
2816impl<R: TreeRoot<RaTypes>> Hash for PathExprNode<R> {
2817 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2818} 2094}
2819 2095
2820impl<'a> AstNode<'a> for PathExpr<'a> { 2096impl AstNode for PathExpr {
2821 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2097 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2822 match syntax.kind() { 2098 match syntax.kind() {
2823 PATH_EXPR => Some(PathExpr { syntax }), 2099 PATH_EXPR => Some(PathExpr::from_repr(syntax.into_repr())),
2824 _ => None, 2100 _ => None,
2825 } 2101 }
2826 } 2102 }
2827 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2103 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2828} 2104 fn to_owned(&self) -> TreePtr<PathExpr> { TreePtr::cast(self.syntax.to_owned()) }
2829
2830impl<R: TreeRoot<RaTypes>> PathExprNode<R> {
2831 pub fn borrowed(&self) -> PathExpr {
2832 PathExprNode { syntax: self.syntax.borrowed() }
2833 }
2834 pub fn owned(&self) -> PathExprNode {
2835 PathExprNode { syntax: self.syntax.owned() }
2836 }
2837} 2105}
2838 2106
2839 2107
2840impl<'a> PathExpr<'a> { 2108impl PathExpr {
2841 pub fn path(self) -> Option<Path<'a>> { 2109 pub fn path(&self) -> Option<&Path> {
2842 super::child_opt(self) 2110 super::child_opt(self)
2843 } 2111 }
2844} 2112}
2845 2113
2846// PathPat 2114// PathPat
2847#[derive(Debug, Clone, Copy,)] 2115#[derive(Debug, PartialEq, Eq, Hash)]
2848pub struct PathPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2116#[repr(transparent)]
2849 pub(crate) syntax: SyntaxNode<R>, 2117pub struct PathPat {
2118 pub(crate) syntax: SyntaxNode,
2850} 2119}
2851pub type PathPat<'a> = PathPatNode<RefRoot<'a>>; 2120unsafe impl TransparentNewType for PathPat {
2852 2121 type Repr = rowan::SyntaxNode<RaTypes>;
2853impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathPatNode<R1>> for PathPatNode<R2> {
2854 fn eq(&self, other: &PathPatNode<R1>) -> bool { self.syntax == other.syntax }
2855}
2856impl<R: TreeRoot<RaTypes>> Eq for PathPatNode<R> {}
2857impl<R: TreeRoot<RaTypes>> Hash for PathPatNode<R> {
2858 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2859} 2122}
2860 2123
2861impl<'a> AstNode<'a> for PathPat<'a> { 2124impl AstNode for PathPat {
2862 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2125 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2863 match syntax.kind() { 2126 match syntax.kind() {
2864 PATH_PAT => Some(PathPat { syntax }), 2127 PATH_PAT => Some(PathPat::from_repr(syntax.into_repr())),
2865 _ => None, 2128 _ => None,
2866 } 2129 }
2867 } 2130 }
2868 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2131 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2869} 2132 fn to_owned(&self) -> TreePtr<PathPat> { TreePtr::cast(self.syntax.to_owned()) }
2870
2871impl<R: TreeRoot<RaTypes>> PathPatNode<R> {
2872 pub fn borrowed(&self) -> PathPat {
2873 PathPatNode { syntax: self.syntax.borrowed() }
2874 }
2875 pub fn owned(&self) -> PathPatNode {
2876 PathPatNode { syntax: self.syntax.owned() }
2877 }
2878} 2133}
2879 2134
2880 2135
2881impl<'a> PathPat<'a> {} 2136impl PathPat {}
2882 2137
2883// PathSegment 2138// PathSegment
2884#[derive(Debug, Clone, Copy,)] 2139#[derive(Debug, PartialEq, Eq, Hash)]
2885pub struct PathSegmentNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2140#[repr(transparent)]
2886 pub(crate) syntax: SyntaxNode<R>, 2141pub struct PathSegment {
2887} 2142 pub(crate) syntax: SyntaxNode,
2888pub type PathSegment<'a> = PathSegmentNode<RefRoot<'a>>;
2889
2890impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathSegmentNode<R1>> for PathSegmentNode<R2> {
2891 fn eq(&self, other: &PathSegmentNode<R1>) -> bool { self.syntax == other.syntax }
2892} 2143}
2893impl<R: TreeRoot<RaTypes>> Eq for PathSegmentNode<R> {} 2144unsafe impl TransparentNewType for PathSegment {
2894impl<R: TreeRoot<RaTypes>> Hash for PathSegmentNode<R> { 2145 type Repr = rowan::SyntaxNode<RaTypes>;
2895 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2896} 2146}
2897 2147
2898impl<'a> AstNode<'a> for PathSegment<'a> { 2148impl AstNode for PathSegment {
2899 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2149 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2900 match syntax.kind() { 2150 match syntax.kind() {
2901 PATH_SEGMENT => Some(PathSegment { syntax }), 2151 PATH_SEGMENT => Some(PathSegment::from_repr(syntax.into_repr())),
2902 _ => None, 2152 _ => None,
2903 } 2153 }
2904 } 2154 }
2905 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2155 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2156 fn to_owned(&self) -> TreePtr<PathSegment> { TreePtr::cast(self.syntax.to_owned()) }
2906} 2157}
2907 2158
2908impl<R: TreeRoot<RaTypes>> PathSegmentNode<R> {
2909 pub fn borrowed(&self) -> PathSegment {
2910 PathSegmentNode { syntax: self.syntax.borrowed() }
2911 }
2912 pub fn owned(&self) -> PathSegmentNode {
2913 PathSegmentNode { syntax: self.syntax.owned() }
2914 }
2915}
2916 2159
2917 2160impl PathSegment {
2918impl<'a> PathSegment<'a> { 2161 pub fn name_ref(&self) -> Option<&NameRef> {
2919 pub fn name_ref(self) -> Option<NameRef<'a>> {
2920 super::child_opt(self) 2162 super::child_opt(self)
2921 } 2163 }
2922} 2164}
2923 2165
2924// PathType 2166// PathType
2925#[derive(Debug, Clone, Copy,)] 2167#[derive(Debug, PartialEq, Eq, Hash)]
2926pub struct PathTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2168#[repr(transparent)]
2927 pub(crate) syntax: SyntaxNode<R>, 2169pub struct PathType {
2928} 2170 pub(crate) syntax: SyntaxNode,
2929pub type PathType<'a> = PathTypeNode<RefRoot<'a>>;
2930
2931impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathTypeNode<R1>> for PathTypeNode<R2> {
2932 fn eq(&self, other: &PathTypeNode<R1>) -> bool { self.syntax == other.syntax }
2933} 2171}
2934impl<R: TreeRoot<RaTypes>> Eq for PathTypeNode<R> {} 2172unsafe impl TransparentNewType for PathType {
2935impl<R: TreeRoot<RaTypes>> Hash for PathTypeNode<R> { 2173 type Repr = rowan::SyntaxNode<RaTypes>;
2936 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2937} 2174}
2938 2175
2939impl<'a> AstNode<'a> for PathType<'a> { 2176impl AstNode for PathType {
2940 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2177 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2941 match syntax.kind() { 2178 match syntax.kind() {
2942 PATH_TYPE => Some(PathType { syntax }), 2179 PATH_TYPE => Some(PathType::from_repr(syntax.into_repr())),
2943 _ => None, 2180 _ => None,
2944 } 2181 }
2945 } 2182 }
2946 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2183 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2947} 2184 fn to_owned(&self) -> TreePtr<PathType> { TreePtr::cast(self.syntax.to_owned()) }
2948
2949impl<R: TreeRoot<RaTypes>> PathTypeNode<R> {
2950 pub fn borrowed(&self) -> PathType {
2951 PathTypeNode { syntax: self.syntax.borrowed() }
2952 }
2953 pub fn owned(&self) -> PathTypeNode {
2954 PathTypeNode { syntax: self.syntax.owned() }
2955 }
2956} 2185}
2957 2186
2958 2187
2959impl<'a> PathType<'a> { 2188impl PathType {
2960 pub fn path(self) -> Option<Path<'a>> { 2189 pub fn path(&self) -> Option<&Path> {
2961 super::child_opt(self) 2190 super::child_opt(self)
2962 } 2191 }
2963} 2192}
2964 2193
2965// PlaceholderPat 2194// PlaceholderPat
2966#[derive(Debug, Clone, Copy,)] 2195#[derive(Debug, PartialEq, Eq, Hash)]
2967pub struct PlaceholderPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2196#[repr(transparent)]
2968 pub(crate) syntax: SyntaxNode<R>, 2197pub struct PlaceholderPat {
2198 pub(crate) syntax: SyntaxNode,
2969} 2199}
2970pub type PlaceholderPat<'a> = PlaceholderPatNode<RefRoot<'a>>; 2200unsafe impl TransparentNewType for PlaceholderPat {
2971 2201 type Repr = rowan::SyntaxNode<RaTypes>;
2972impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderPatNode<R1>> for PlaceholderPatNode<R2> {
2973 fn eq(&self, other: &PlaceholderPatNode<R1>) -> bool { self.syntax == other.syntax }
2974}
2975impl<R: TreeRoot<RaTypes>> Eq for PlaceholderPatNode<R> {}
2976impl<R: TreeRoot<RaTypes>> Hash for PlaceholderPatNode<R> {
2977 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
2978} 2202}
2979 2203
2980impl<'a> AstNode<'a> for PlaceholderPat<'a> { 2204impl AstNode for PlaceholderPat {
2981 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2205 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2982 match syntax.kind() { 2206 match syntax.kind() {
2983 PLACEHOLDER_PAT => Some(PlaceholderPat { syntax }), 2207 PLACEHOLDER_PAT => Some(PlaceholderPat::from_repr(syntax.into_repr())),
2984 _ => None, 2208 _ => None,
2985 } 2209 }
2986 } 2210 }
2987 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2211 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2988} 2212 fn to_owned(&self) -> TreePtr<PlaceholderPat> { TreePtr::cast(self.syntax.to_owned()) }
2989
2990impl<R: TreeRoot<RaTypes>> PlaceholderPatNode<R> {
2991 pub fn borrowed(&self) -> PlaceholderPat {
2992 PlaceholderPatNode { syntax: self.syntax.borrowed() }
2993 }
2994 pub fn owned(&self) -> PlaceholderPatNode {
2995 PlaceholderPatNode { syntax: self.syntax.owned() }
2996 }
2997} 2213}
2998 2214
2999 2215
3000impl<'a> PlaceholderPat<'a> {} 2216impl PlaceholderPat {}
3001 2217
3002// PlaceholderType 2218// PlaceholderType
3003#[derive(Debug, Clone, Copy,)] 2219#[derive(Debug, PartialEq, Eq, Hash)]
3004pub struct PlaceholderTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2220#[repr(transparent)]
3005 pub(crate) syntax: SyntaxNode<R>, 2221pub struct PlaceholderType {
2222 pub(crate) syntax: SyntaxNode,
3006} 2223}
3007pub type PlaceholderType<'a> = PlaceholderTypeNode<RefRoot<'a>>; 2224unsafe impl TransparentNewType for PlaceholderType {
3008 2225 type Repr = rowan::SyntaxNode<RaTypes>;
3009impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderTypeNode<R1>> for PlaceholderTypeNode<R2> {
3010 fn eq(&self, other: &PlaceholderTypeNode<R1>) -> bool { self.syntax == other.syntax }
3011}
3012impl<R: TreeRoot<RaTypes>> Eq for PlaceholderTypeNode<R> {}
3013impl<R: TreeRoot<RaTypes>> Hash for PlaceholderTypeNode<R> {
3014 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3015} 2226}
3016 2227
3017impl<'a> AstNode<'a> for PlaceholderType<'a> { 2228impl AstNode for PlaceholderType {
3018 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2229 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3019 match syntax.kind() { 2230 match syntax.kind() {
3020 PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }), 2231 PLACEHOLDER_TYPE => Some(PlaceholderType::from_repr(syntax.into_repr())),
3021 _ => None, 2232 _ => None,
3022 } 2233 }
3023 } 2234 }
3024 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2235 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3025} 2236 fn to_owned(&self) -> TreePtr<PlaceholderType> { TreePtr::cast(self.syntax.to_owned()) }
3026
3027impl<R: TreeRoot<RaTypes>> PlaceholderTypeNode<R> {
3028 pub fn borrowed(&self) -> PlaceholderType {
3029 PlaceholderTypeNode { syntax: self.syntax.borrowed() }
3030 }
3031 pub fn owned(&self) -> PlaceholderTypeNode {
3032 PlaceholderTypeNode { syntax: self.syntax.owned() }
3033 }
3034} 2237}
3035 2238
3036 2239
3037impl<'a> PlaceholderType<'a> {} 2240impl PlaceholderType {}
3038 2241
3039// PointerType 2242// PointerType
3040#[derive(Debug, Clone, Copy,)] 2243#[derive(Debug, PartialEq, Eq, Hash)]
3041pub struct PointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2244#[repr(transparent)]
3042 pub(crate) syntax: SyntaxNode<R>, 2245pub struct PointerType {
3043} 2246 pub(crate) syntax: SyntaxNode,
3044pub type PointerType<'a> = PointerTypeNode<RefRoot<'a>>;
3045
3046impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PointerTypeNode<R1>> for PointerTypeNode<R2> {
3047 fn eq(&self, other: &PointerTypeNode<R1>) -> bool { self.syntax == other.syntax }
3048} 2247}
3049impl<R: TreeRoot<RaTypes>> Eq for PointerTypeNode<R> {} 2248unsafe impl TransparentNewType for PointerType {
3050impl<R: TreeRoot<RaTypes>> Hash for PointerTypeNode<R> { 2249 type Repr = rowan::SyntaxNode<RaTypes>;
3051 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3052} 2250}
3053 2251
3054impl<'a> AstNode<'a> for PointerType<'a> { 2252impl AstNode for PointerType {
3055 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2253 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3056 match syntax.kind() { 2254 match syntax.kind() {
3057 POINTER_TYPE => Some(PointerType { syntax }), 2255 POINTER_TYPE => Some(PointerType::from_repr(syntax.into_repr())),
3058 _ => None, 2256 _ => None,
3059 } 2257 }
3060 } 2258 }
3061 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2259 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2260 fn to_owned(&self) -> TreePtr<PointerType> { TreePtr::cast(self.syntax.to_owned()) }
3062} 2261}
3063 2262
3064impl<R: TreeRoot<RaTypes>> PointerTypeNode<R> {
3065 pub fn borrowed(&self) -> PointerType {
3066 PointerTypeNode { syntax: self.syntax.borrowed() }
3067 }
3068 pub fn owned(&self) -> PointerTypeNode {
3069 PointerTypeNode { syntax: self.syntax.owned() }
3070 }
3071}
3072 2263
3073 2264impl PointerType {
3074impl<'a> PointerType<'a> { 2265 pub fn type_ref(&self) -> Option<&TypeRef> {
3075 pub fn type_ref(self) -> Option<TypeRef<'a>> {
3076 super::child_opt(self) 2266 super::child_opt(self)
3077 } 2267 }
3078} 2268}
3079 2269
3080// PosField 2270// PosField
3081#[derive(Debug, Clone, Copy,)] 2271#[derive(Debug, PartialEq, Eq, Hash)]
3082pub struct PosFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2272#[repr(transparent)]
3083 pub(crate) syntax: SyntaxNode<R>, 2273pub struct PosField {
3084} 2274 pub(crate) syntax: SyntaxNode,
3085pub type PosField<'a> = PosFieldNode<RefRoot<'a>>;
3086
3087impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PosFieldNode<R1>> for PosFieldNode<R2> {
3088 fn eq(&self, other: &PosFieldNode<R1>) -> bool { self.syntax == other.syntax }
3089} 2275}
3090impl<R: TreeRoot<RaTypes>> Eq for PosFieldNode<R> {} 2276unsafe impl TransparentNewType for PosField {
3091impl<R: TreeRoot<RaTypes>> Hash for PosFieldNode<R> { 2277 type Repr = rowan::SyntaxNode<RaTypes>;
3092 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3093} 2278}
3094 2279
3095impl<'a> AstNode<'a> for PosField<'a> { 2280impl AstNode for PosField {
3096 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2281 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3097 match syntax.kind() { 2282 match syntax.kind() {
3098 POS_FIELD => Some(PosField { syntax }), 2283 POS_FIELD => Some(PosField::from_repr(syntax.into_repr())),
3099 _ => None, 2284 _ => None,
3100 } 2285 }
3101 } 2286 }
3102 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2287 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3103} 2288 fn to_owned(&self) -> TreePtr<PosField> { TreePtr::cast(self.syntax.to_owned()) }
3104
3105impl<R: TreeRoot<RaTypes>> PosFieldNode<R> {
3106 pub fn borrowed(&self) -> PosField {
3107 PosFieldNode { syntax: self.syntax.borrowed() }
3108 }
3109 pub fn owned(&self) -> PosFieldNode {
3110 PosFieldNode { syntax: self.syntax.owned() }
3111 }
3112} 2289}
3113 2290
3114 2291
3115impl<'a> ast::VisibilityOwner<'a> for PosField<'a> {} 2292impl ast::VisibilityOwner for PosField {}
3116impl<'a> ast::AttrsOwner<'a> for PosField<'a> {} 2293impl ast::AttrsOwner for PosField {}
3117impl<'a> PosField<'a> { 2294impl PosField {
3118 pub fn type_ref(self) -> Option<TypeRef<'a>> { 2295 pub fn type_ref(&self) -> Option<&TypeRef> {
3119 super::child_opt(self) 2296 super::child_opt(self)
3120 } 2297 }
3121} 2298}
3122 2299
3123// PosFieldList 2300// PosFieldList
3124#[derive(Debug, Clone, Copy,)] 2301#[derive(Debug, PartialEq, Eq, Hash)]
3125pub struct PosFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2302#[repr(transparent)]
3126 pub(crate) syntax: SyntaxNode<R>, 2303pub struct PosFieldList {
3127} 2304 pub(crate) syntax: SyntaxNode,
3128pub type PosFieldList<'a> = PosFieldListNode<RefRoot<'a>>;
3129
3130impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PosFieldListNode<R1>> for PosFieldListNode<R2> {
3131 fn eq(&self, other: &PosFieldListNode<R1>) -> bool { self.syntax == other.syntax }
3132} 2305}
3133impl<R: TreeRoot<RaTypes>> Eq for PosFieldListNode<R> {} 2306unsafe impl TransparentNewType for PosFieldList {
3134impl<R: TreeRoot<RaTypes>> Hash for PosFieldListNode<R> { 2307 type Repr = rowan::SyntaxNode<RaTypes>;
3135 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3136} 2308}
3137 2309
3138impl<'a> AstNode<'a> for PosFieldList<'a> { 2310impl AstNode for PosFieldList {
3139 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2311 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3140 match syntax.kind() { 2312 match syntax.kind() {
3141 POS_FIELD_LIST => Some(PosFieldList { syntax }), 2313 POS_FIELD_LIST => Some(PosFieldList::from_repr(syntax.into_repr())),
3142 _ => None, 2314 _ => None,
3143 } 2315 }
3144 } 2316 }
3145 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2317 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3146} 2318 fn to_owned(&self) -> TreePtr<PosFieldList> { TreePtr::cast(self.syntax.to_owned()) }
3147
3148impl<R: TreeRoot<RaTypes>> PosFieldListNode<R> {
3149 pub fn borrowed(&self) -> PosFieldList {
3150 PosFieldListNode { syntax: self.syntax.borrowed() }
3151 }
3152 pub fn owned(&self) -> PosFieldListNode {
3153 PosFieldListNode { syntax: self.syntax.owned() }
3154 }
3155} 2319}
3156 2320
3157 2321
3158impl<'a> PosFieldList<'a> { 2322impl PosFieldList {
3159 pub fn fields(self) -> impl Iterator<Item = PosField<'a>> + 'a { 2323 pub fn fields(&self) -> impl Iterator<Item = &PosField> {
3160 super::children(self) 2324 super::children(self)
3161 } 2325 }
3162} 2326}
3163 2327
3164// PrefixExpr 2328// PrefixExpr
3165#[derive(Debug, Clone, Copy,)] 2329#[derive(Debug, PartialEq, Eq, Hash)]
3166pub struct PrefixExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2330#[repr(transparent)]
3167 pub(crate) syntax: SyntaxNode<R>, 2331pub struct PrefixExpr {
2332 pub(crate) syntax: SyntaxNode,
3168} 2333}
3169pub type PrefixExpr<'a> = PrefixExprNode<RefRoot<'a>>; 2334unsafe impl TransparentNewType for PrefixExpr {
3170 2335 type Repr = rowan::SyntaxNode<RaTypes>;
3171impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PrefixExprNode<R1>> for PrefixExprNode<R2> {
3172 fn eq(&self, other: &PrefixExprNode<R1>) -> bool { self.syntax == other.syntax }
3173}
3174impl<R: TreeRoot<RaTypes>> Eq for PrefixExprNode<R> {}
3175impl<R: TreeRoot<RaTypes>> Hash for PrefixExprNode<R> {
3176 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3177} 2336}
3178 2337
3179impl<'a> AstNode<'a> for PrefixExpr<'a> { 2338impl AstNode for PrefixExpr {
3180 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2339 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3181 match syntax.kind() { 2340 match syntax.kind() {
3182 PREFIX_EXPR => Some(PrefixExpr { syntax }), 2341 PREFIX_EXPR => Some(PrefixExpr::from_repr(syntax.into_repr())),
3183 _ => None, 2342 _ => None,
3184 } 2343 }
3185 } 2344 }
3186 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2345 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3187} 2346 fn to_owned(&self) -> TreePtr<PrefixExpr> { TreePtr::cast(self.syntax.to_owned()) }
3188
3189impl<R: TreeRoot<RaTypes>> PrefixExprNode<R> {
3190 pub fn borrowed(&self) -> PrefixExpr {
3191 PrefixExprNode { syntax: self.syntax.borrowed() }
3192 }
3193 pub fn owned(&self) -> PrefixExprNode {
3194 PrefixExprNode { syntax: self.syntax.owned() }
3195 }
3196} 2347}
3197 2348
3198 2349
3199impl<'a> PrefixExpr<'a> { 2350impl PrefixExpr {
3200 pub fn expr(self) -> Option<Expr<'a>> { 2351 pub fn expr(&self) -> Option<&Expr> {
3201 super::child_opt(self) 2352 super::child_opt(self)
3202 } 2353 }
3203} 2354}
3204 2355
3205// RangeExpr 2356// RangeExpr
3206#[derive(Debug, Clone, Copy,)] 2357#[derive(Debug, PartialEq, Eq, Hash)]
3207pub struct RangeExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2358#[repr(transparent)]
3208 pub(crate) syntax: SyntaxNode<R>, 2359pub struct RangeExpr {
3209} 2360 pub(crate) syntax: SyntaxNode,
3210pub type RangeExpr<'a> = RangeExprNode<RefRoot<'a>>;
3211
3212impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RangeExprNode<R1>> for RangeExprNode<R2> {
3213 fn eq(&self, other: &RangeExprNode<R1>) -> bool { self.syntax == other.syntax }
3214} 2361}
3215impl<R: TreeRoot<RaTypes>> Eq for RangeExprNode<R> {} 2362unsafe impl TransparentNewType for RangeExpr {
3216impl<R: TreeRoot<RaTypes>> Hash for RangeExprNode<R> { 2363 type Repr = rowan::SyntaxNode<RaTypes>;
3217 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3218} 2364}
3219 2365
3220impl<'a> AstNode<'a> for RangeExpr<'a> { 2366impl AstNode for RangeExpr {
3221 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2367 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3222 match syntax.kind() { 2368 match syntax.kind() {
3223 RANGE_EXPR => Some(RangeExpr { syntax }), 2369 RANGE_EXPR => Some(RangeExpr::from_repr(syntax.into_repr())),
3224 _ => None, 2370 _ => None,
3225 } 2371 }
3226 } 2372 }
3227 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2373 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2374 fn to_owned(&self) -> TreePtr<RangeExpr> { TreePtr::cast(self.syntax.to_owned()) }
3228} 2375}
3229 2376
3230impl<R: TreeRoot<RaTypes>> RangeExprNode<R> {
3231 pub fn borrowed(&self) -> RangeExpr {
3232 RangeExprNode { syntax: self.syntax.borrowed() }
3233 }
3234 pub fn owned(&self) -> RangeExprNode {
3235 RangeExprNode { syntax: self.syntax.owned() }
3236 }
3237}
3238 2377
3239 2378impl RangeExpr {}
3240impl<'a> RangeExpr<'a> {}
3241 2379
3242// RangePat 2380// RangePat
3243#[derive(Debug, Clone, Copy,)] 2381#[derive(Debug, PartialEq, Eq, Hash)]
3244pub struct RangePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2382#[repr(transparent)]
3245 pub(crate) syntax: SyntaxNode<R>, 2383pub struct RangePat {
2384 pub(crate) syntax: SyntaxNode,
3246} 2385}
3247pub type RangePat<'a> = RangePatNode<RefRoot<'a>>; 2386unsafe impl TransparentNewType for RangePat {
3248 2387 type Repr = rowan::SyntaxNode<RaTypes>;
3249impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RangePatNode<R1>> for RangePatNode<R2> {
3250 fn eq(&self, other: &RangePatNode<R1>) -> bool { self.syntax == other.syntax }
3251}
3252impl<R: TreeRoot<RaTypes>> Eq for RangePatNode<R> {}
3253impl<R: TreeRoot<RaTypes>> Hash for RangePatNode<R> {
3254 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3255} 2388}
3256 2389
3257impl<'a> AstNode<'a> for RangePat<'a> { 2390impl AstNode for RangePat {
3258 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2391 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3259 match syntax.kind() { 2392 match syntax.kind() {
3260 RANGE_PAT => Some(RangePat { syntax }), 2393 RANGE_PAT => Some(RangePat::from_repr(syntax.into_repr())),
3261 _ => None, 2394 _ => None,
3262 } 2395 }
3263 } 2396 }
3264 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2397 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3265} 2398 fn to_owned(&self) -> TreePtr<RangePat> { TreePtr::cast(self.syntax.to_owned()) }
3266
3267impl<R: TreeRoot<RaTypes>> RangePatNode<R> {
3268 pub fn borrowed(&self) -> RangePat {
3269 RangePatNode { syntax: self.syntax.borrowed() }
3270 }
3271 pub fn owned(&self) -> RangePatNode {
3272 RangePatNode { syntax: self.syntax.owned() }
3273 }
3274} 2399}
3275 2400
3276 2401
3277impl<'a> RangePat<'a> {} 2402impl RangePat {}
3278 2403
3279// RefExpr 2404// RefExpr
3280#[derive(Debug, Clone, Copy,)] 2405#[derive(Debug, PartialEq, Eq, Hash)]
3281pub struct RefExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2406#[repr(transparent)]
3282 pub(crate) syntax: SyntaxNode<R>, 2407pub struct RefExpr {
2408 pub(crate) syntax: SyntaxNode,
3283} 2409}
3284pub type RefExpr<'a> = RefExprNode<RefRoot<'a>>; 2410unsafe impl TransparentNewType for RefExpr {
3285 2411 type Repr = rowan::SyntaxNode<RaTypes>;
3286impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RefExprNode<R1>> for RefExprNode<R2> {
3287 fn eq(&self, other: &RefExprNode<R1>) -> bool { self.syntax == other.syntax }
3288}
3289impl<R: TreeRoot<RaTypes>> Eq for RefExprNode<R> {}
3290impl<R: TreeRoot<RaTypes>> Hash for RefExprNode<R> {
3291 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3292} 2412}
3293 2413
3294impl<'a> AstNode<'a> for RefExpr<'a> { 2414impl AstNode for RefExpr {
3295 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2415 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3296 match syntax.kind() { 2416 match syntax.kind() {
3297 REF_EXPR => Some(RefExpr { syntax }), 2417 REF_EXPR => Some(RefExpr::from_repr(syntax.into_repr())),
3298 _ => None, 2418 _ => None,
3299 } 2419 }
3300 } 2420 }
3301 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2421 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3302} 2422 fn to_owned(&self) -> TreePtr<RefExpr> { TreePtr::cast(self.syntax.to_owned()) }
3303
3304impl<R: TreeRoot<RaTypes>> RefExprNode<R> {
3305 pub fn borrowed(&self) -> RefExpr {
3306 RefExprNode { syntax: self.syntax.borrowed() }
3307 }
3308 pub fn owned(&self) -> RefExprNode {
3309 RefExprNode { syntax: self.syntax.owned() }
3310 }
3311} 2423}
3312 2424
3313 2425
3314impl<'a> RefExpr<'a> { 2426impl RefExpr {
3315 pub fn expr(self) -> Option<Expr<'a>> { 2427 pub fn expr(&self) -> Option<&Expr> {
3316 super::child_opt(self) 2428 super::child_opt(self)
3317 } 2429 }
3318} 2430}
3319 2431
3320// RefPat 2432// RefPat
3321#[derive(Debug, Clone, Copy,)] 2433#[derive(Debug, PartialEq, Eq, Hash)]
3322pub struct RefPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2434#[repr(transparent)]
3323 pub(crate) syntax: SyntaxNode<R>, 2435pub struct RefPat {
2436 pub(crate) syntax: SyntaxNode,
3324} 2437}
3325pub type RefPat<'a> = RefPatNode<RefRoot<'a>>; 2438unsafe impl TransparentNewType for RefPat {
3326 2439 type Repr = rowan::SyntaxNode<RaTypes>;
3327impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RefPatNode<R1>> for RefPatNode<R2> {
3328 fn eq(&self, other: &RefPatNode<R1>) -> bool { self.syntax == other.syntax }
3329}
3330impl<R: TreeRoot<RaTypes>> Eq for RefPatNode<R> {}
3331impl<R: TreeRoot<RaTypes>> Hash for RefPatNode<R> {
3332 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3333} 2440}
3334 2441
3335impl<'a> AstNode<'a> for RefPat<'a> { 2442impl AstNode for RefPat {
3336 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2443 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3337 match syntax.kind() { 2444 match syntax.kind() {
3338 REF_PAT => Some(RefPat { syntax }), 2445 REF_PAT => Some(RefPat::from_repr(syntax.into_repr())),
3339 _ => None, 2446 _ => None,
3340 } 2447 }
3341 } 2448 }
3342 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2449 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3343} 2450 fn to_owned(&self) -> TreePtr<RefPat> { TreePtr::cast(self.syntax.to_owned()) }
3344
3345impl<R: TreeRoot<RaTypes>> RefPatNode<R> {
3346 pub fn borrowed(&self) -> RefPat {
3347 RefPatNode { syntax: self.syntax.borrowed() }
3348 }
3349 pub fn owned(&self) -> RefPatNode {
3350 RefPatNode { syntax: self.syntax.owned() }
3351 }
3352} 2451}
3353 2452
3354 2453
3355impl<'a> RefPat<'a> {} 2454impl RefPat {}
3356 2455
3357// ReferenceType 2456// ReferenceType
3358#[derive(Debug, Clone, Copy,)] 2457#[derive(Debug, PartialEq, Eq, Hash)]
3359pub struct ReferenceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2458#[repr(transparent)]
3360 pub(crate) syntax: SyntaxNode<R>, 2459pub struct ReferenceType {
3361} 2460 pub(crate) syntax: SyntaxNode,
3362pub type ReferenceType<'a> = ReferenceTypeNode<RefRoot<'a>>;
3363
3364impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ReferenceTypeNode<R1>> for ReferenceTypeNode<R2> {
3365 fn eq(&self, other: &ReferenceTypeNode<R1>) -> bool { self.syntax == other.syntax }
3366} 2461}
3367impl<R: TreeRoot<RaTypes>> Eq for ReferenceTypeNode<R> {} 2462unsafe impl TransparentNewType for ReferenceType {
3368impl<R: TreeRoot<RaTypes>> Hash for ReferenceTypeNode<R> { 2463 type Repr = rowan::SyntaxNode<RaTypes>;
3369 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3370} 2464}
3371 2465
3372impl<'a> AstNode<'a> for ReferenceType<'a> { 2466impl AstNode for ReferenceType {
3373 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2467 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3374 match syntax.kind() { 2468 match syntax.kind() {
3375 REFERENCE_TYPE => Some(ReferenceType { syntax }), 2469 REFERENCE_TYPE => Some(ReferenceType::from_repr(syntax.into_repr())),
3376 _ => None, 2470 _ => None,
3377 } 2471 }
3378 } 2472 }
3379 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2473 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3380} 2474 fn to_owned(&self) -> TreePtr<ReferenceType> { TreePtr::cast(self.syntax.to_owned()) }
3381
3382impl<R: TreeRoot<RaTypes>> ReferenceTypeNode<R> {
3383 pub fn borrowed(&self) -> ReferenceType {
3384 ReferenceTypeNode { syntax: self.syntax.borrowed() }
3385 }
3386 pub fn owned(&self) -> ReferenceTypeNode {
3387 ReferenceTypeNode { syntax: self.syntax.owned() }
3388 }
3389} 2475}
3390 2476
3391 2477
3392impl<'a> ReferenceType<'a> { 2478impl ReferenceType {
3393 pub fn type_ref(self) -> Option<TypeRef<'a>> { 2479 pub fn type_ref(&self) -> Option<&TypeRef> {
3394 super::child_opt(self) 2480 super::child_opt(self)
3395 } 2481 }
3396} 2482}
3397 2483
3398// RetType 2484// RetType
3399#[derive(Debug, Clone, Copy,)] 2485#[derive(Debug, PartialEq, Eq, Hash)]
3400pub struct RetTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2486#[repr(transparent)]
3401 pub(crate) syntax: SyntaxNode<R>, 2487pub struct RetType {
3402} 2488 pub(crate) syntax: SyntaxNode,
3403pub type RetType<'a> = RetTypeNode<RefRoot<'a>>;
3404
3405impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RetTypeNode<R1>> for RetTypeNode<R2> {
3406 fn eq(&self, other: &RetTypeNode<R1>) -> bool { self.syntax == other.syntax }
3407} 2489}
3408impl<R: TreeRoot<RaTypes>> Eq for RetTypeNode<R> {} 2490unsafe impl TransparentNewType for RetType {
3409impl<R: TreeRoot<RaTypes>> Hash for RetTypeNode<R> { 2491 type Repr = rowan::SyntaxNode<RaTypes>;
3410 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3411} 2492}
3412 2493
3413impl<'a> AstNode<'a> for RetType<'a> { 2494impl AstNode for RetType {
3414 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2495 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3415 match syntax.kind() { 2496 match syntax.kind() {
3416 RET_TYPE => Some(RetType { syntax }), 2497 RET_TYPE => Some(RetType::from_repr(syntax.into_repr())),
3417 _ => None, 2498 _ => None,
3418 } 2499 }
3419 } 2500 }
3420 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2501 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3421} 2502 fn to_owned(&self) -> TreePtr<RetType> { TreePtr::cast(self.syntax.to_owned()) }
3422
3423impl<R: TreeRoot<RaTypes>> RetTypeNode<R> {
3424 pub fn borrowed(&self) -> RetType {
3425 RetTypeNode { syntax: self.syntax.borrowed() }
3426 }
3427 pub fn owned(&self) -> RetTypeNode {
3428 RetTypeNode { syntax: self.syntax.owned() }
3429 }
3430} 2503}
3431 2504
3432 2505
3433impl<'a> RetType<'a> { 2506impl RetType {
3434 pub fn type_ref(self) -> Option<TypeRef<'a>> { 2507 pub fn type_ref(&self) -> Option<&TypeRef> {
3435 super::child_opt(self) 2508 super::child_opt(self)
3436 } 2509 }
3437} 2510}
3438 2511
3439// ReturnExpr 2512// ReturnExpr
3440#[derive(Debug, Clone, Copy,)] 2513#[derive(Debug, PartialEq, Eq, Hash)]
3441pub struct ReturnExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2514#[repr(transparent)]
3442 pub(crate) syntax: SyntaxNode<R>, 2515pub struct ReturnExpr {
2516 pub(crate) syntax: SyntaxNode,
3443} 2517}
3444pub type ReturnExpr<'a> = ReturnExprNode<RefRoot<'a>>; 2518unsafe impl TransparentNewType for ReturnExpr {
3445 2519 type Repr = rowan::SyntaxNode<RaTypes>;
3446impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ReturnExprNode<R1>> for ReturnExprNode<R2> {
3447 fn eq(&self, other: &ReturnExprNode<R1>) -> bool { self.syntax == other.syntax }
3448}
3449impl<R: TreeRoot<RaTypes>> Eq for ReturnExprNode<R> {}
3450impl<R: TreeRoot<RaTypes>> Hash for ReturnExprNode<R> {
3451 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3452} 2520}
3453 2521
3454impl<'a> AstNode<'a> for ReturnExpr<'a> { 2522impl AstNode for ReturnExpr {
3455 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2523 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3456 match syntax.kind() { 2524 match syntax.kind() {
3457 RETURN_EXPR => Some(ReturnExpr { syntax }), 2525 RETURN_EXPR => Some(ReturnExpr::from_repr(syntax.into_repr())),
3458 _ => None, 2526 _ => None,
3459 } 2527 }
3460 } 2528 }
3461 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2529 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3462} 2530 fn to_owned(&self) -> TreePtr<ReturnExpr> { TreePtr::cast(self.syntax.to_owned()) }
3463
3464impl<R: TreeRoot<RaTypes>> ReturnExprNode<R> {
3465 pub fn borrowed(&self) -> ReturnExpr {
3466 ReturnExprNode { syntax: self.syntax.borrowed() }
3467 }
3468 pub fn owned(&self) -> ReturnExprNode {
3469 ReturnExprNode { syntax: self.syntax.owned() }
3470 }
3471} 2531}
3472 2532
3473 2533
3474impl<'a> ReturnExpr<'a> { 2534impl ReturnExpr {
3475 pub fn expr(self) -> Option<Expr<'a>> { 2535 pub fn expr(&self) -> Option<&Expr> {
3476 super::child_opt(self) 2536 super::child_opt(self)
3477 } 2537 }
3478} 2538}
3479 2539
3480// SelfKw 2540// SelfKw
3481#[derive(Debug, Clone, Copy,)] 2541#[derive(Debug, PartialEq, Eq, Hash)]
3482pub struct SelfKwNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2542#[repr(transparent)]
3483 pub(crate) syntax: SyntaxNode<R>, 2543pub struct SelfKw {
3484} 2544 pub(crate) syntax: SyntaxNode,
3485pub type SelfKw<'a> = SelfKwNode<RefRoot<'a>>;
3486
3487impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SelfKwNode<R1>> for SelfKwNode<R2> {
3488 fn eq(&self, other: &SelfKwNode<R1>) -> bool { self.syntax == other.syntax }
3489} 2545}
3490impl<R: TreeRoot<RaTypes>> Eq for SelfKwNode<R> {} 2546unsafe impl TransparentNewType for SelfKw {
3491impl<R: TreeRoot<RaTypes>> Hash for SelfKwNode<R> { 2547 type Repr = rowan::SyntaxNode<RaTypes>;
3492 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3493} 2548}
3494 2549
3495impl<'a> AstNode<'a> for SelfKw<'a> { 2550impl AstNode for SelfKw {
3496 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2551 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3497 match syntax.kind() { 2552 match syntax.kind() {
3498 SELF_KW => Some(SelfKw { syntax }), 2553 SELF_KW => Some(SelfKw::from_repr(syntax.into_repr())),
3499 _ => None, 2554 _ => None,
3500 } 2555 }
3501 } 2556 }
3502 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2557 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2558 fn to_owned(&self) -> TreePtr<SelfKw> { TreePtr::cast(self.syntax.to_owned()) }
3503} 2559}
3504 2560
3505impl<R: TreeRoot<RaTypes>> SelfKwNode<R> {
3506 pub fn borrowed(&self) -> SelfKw {
3507 SelfKwNode { syntax: self.syntax.borrowed() }
3508 }
3509 pub fn owned(&self) -> SelfKwNode {
3510 SelfKwNode { syntax: self.syntax.owned() }
3511 }
3512}
3513 2561
3514 2562impl SelfKw {}
3515impl<'a> SelfKw<'a> {}
3516 2563
3517// SelfParam 2564// SelfParam
3518#[derive(Debug, Clone, Copy,)] 2565#[derive(Debug, PartialEq, Eq, Hash)]
3519pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2566#[repr(transparent)]
3520 pub(crate) syntax: SyntaxNode<R>, 2567pub struct SelfParam {
2568 pub(crate) syntax: SyntaxNode,
3521} 2569}
3522pub type SelfParam<'a> = SelfParamNode<RefRoot<'a>>; 2570unsafe impl TransparentNewType for SelfParam {
3523 2571 type Repr = rowan::SyntaxNode<RaTypes>;
3524impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SelfParamNode<R1>> for SelfParamNode<R2> {
3525 fn eq(&self, other: &SelfParamNode<R1>) -> bool { self.syntax == other.syntax }
3526}
3527impl<R: TreeRoot<RaTypes>> Eq for SelfParamNode<R> {}
3528impl<R: TreeRoot<RaTypes>> Hash for SelfParamNode<R> {
3529 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3530} 2572}
3531 2573
3532impl<'a> AstNode<'a> for SelfParam<'a> { 2574impl AstNode for SelfParam {
3533 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2575 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3534 match syntax.kind() { 2576 match syntax.kind() {
3535 SELF_PARAM => Some(SelfParam { syntax }), 2577 SELF_PARAM => Some(SelfParam::from_repr(syntax.into_repr())),
3536 _ => None, 2578 _ => None,
3537 } 2579 }
3538 } 2580 }
3539 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2581 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3540} 2582 fn to_owned(&self) -> TreePtr<SelfParam> { TreePtr::cast(self.syntax.to_owned()) }
3541
3542impl<R: TreeRoot<RaTypes>> SelfParamNode<R> {
3543 pub fn borrowed(&self) -> SelfParam {
3544 SelfParamNode { syntax: self.syntax.borrowed() }
3545 }
3546 pub fn owned(&self) -> SelfParamNode {
3547 SelfParamNode { syntax: self.syntax.owned() }
3548 }
3549} 2583}
3550 2584
3551 2585
3552impl<'a> SelfParam<'a> { 2586impl SelfParam {
3553 pub fn type_ref(self) -> Option<TypeRef<'a>> { 2587 pub fn type_ref(&self) -> Option<&TypeRef> {
3554 super::child_opt(self) 2588 super::child_opt(self)
3555 } 2589 }
3556 2590
3557 pub fn self_kw(self) -> Option<SelfKw<'a>> { 2591 pub fn self_kw(&self) -> Option<&SelfKw> {
3558 super::child_opt(self) 2592 super::child_opt(self)
3559 } 2593 }
3560} 2594}
3561 2595
3562// SlicePat 2596// SlicePat
3563#[derive(Debug, Clone, Copy,)] 2597#[derive(Debug, PartialEq, Eq, Hash)]
3564pub struct SlicePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2598#[repr(transparent)]
3565 pub(crate) syntax: SyntaxNode<R>, 2599pub struct SlicePat {
2600 pub(crate) syntax: SyntaxNode,
3566} 2601}
3567pub type SlicePat<'a> = SlicePatNode<RefRoot<'a>>; 2602unsafe impl TransparentNewType for SlicePat {
3568 2603 type Repr = rowan::SyntaxNode<RaTypes>;
3569impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SlicePatNode<R1>> for SlicePatNode<R2> {
3570 fn eq(&self, other: &SlicePatNode<R1>) -> bool { self.syntax == other.syntax }
3571}
3572impl<R: TreeRoot<RaTypes>> Eq for SlicePatNode<R> {}
3573impl<R: TreeRoot<RaTypes>> Hash for SlicePatNode<R> {
3574 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3575} 2604}
3576 2605
3577impl<'a> AstNode<'a> for SlicePat<'a> { 2606impl AstNode for SlicePat {
3578 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2607 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3579 match syntax.kind() { 2608 match syntax.kind() {
3580 SLICE_PAT => Some(SlicePat { syntax }), 2609 SLICE_PAT => Some(SlicePat::from_repr(syntax.into_repr())),
3581 _ => None, 2610 _ => None,
3582 } 2611 }
3583 } 2612 }
3584 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2613 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3585} 2614 fn to_owned(&self) -> TreePtr<SlicePat> { TreePtr::cast(self.syntax.to_owned()) }
3586
3587impl<R: TreeRoot<RaTypes>> SlicePatNode<R> {
3588 pub fn borrowed(&self) -> SlicePat {
3589 SlicePatNode { syntax: self.syntax.borrowed() }
3590 }
3591 pub fn owned(&self) -> SlicePatNode {
3592 SlicePatNode { syntax: self.syntax.owned() }
3593 }
3594} 2615}
3595 2616
3596 2617
3597impl<'a> SlicePat<'a> {} 2618impl SlicePat {}
3598 2619
3599// SliceType 2620// SliceType
3600#[derive(Debug, Clone, Copy,)] 2621#[derive(Debug, PartialEq, Eq, Hash)]
3601pub struct SliceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2622#[repr(transparent)]
3602 pub(crate) syntax: SyntaxNode<R>, 2623pub struct SliceType {
2624 pub(crate) syntax: SyntaxNode,
3603} 2625}
3604pub type SliceType<'a> = SliceTypeNode<RefRoot<'a>>; 2626unsafe impl TransparentNewType for SliceType {
3605 2627 type Repr = rowan::SyntaxNode<RaTypes>;
3606impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SliceTypeNode<R1>> for SliceTypeNode<R2> {
3607 fn eq(&self, other: &SliceTypeNode<R1>) -> bool { self.syntax == other.syntax }
3608}
3609impl<R: TreeRoot<RaTypes>> Eq for SliceTypeNode<R> {}
3610impl<R: TreeRoot<RaTypes>> Hash for SliceTypeNode<R> {
3611 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3612} 2628}
3613 2629
3614impl<'a> AstNode<'a> for SliceType<'a> { 2630impl AstNode for SliceType {
3615 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2631 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3616 match syntax.kind() { 2632 match syntax.kind() {
3617 SLICE_TYPE => Some(SliceType { syntax }), 2633 SLICE_TYPE => Some(SliceType::from_repr(syntax.into_repr())),
3618 _ => None, 2634 _ => None,
3619 } 2635 }
3620 } 2636 }
3621 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2637 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3622} 2638 fn to_owned(&self) -> TreePtr<SliceType> { TreePtr::cast(self.syntax.to_owned()) }
3623
3624impl<R: TreeRoot<RaTypes>> SliceTypeNode<R> {
3625 pub fn borrowed(&self) -> SliceType {
3626 SliceTypeNode { syntax: self.syntax.borrowed() }
3627 }
3628 pub fn owned(&self) -> SliceTypeNode {
3629 SliceTypeNode { syntax: self.syntax.owned() }
3630 }
3631} 2639}
3632 2640
3633 2641
3634impl<'a> SliceType<'a> { 2642impl SliceType {
3635 pub fn type_ref(self) -> Option<TypeRef<'a>> { 2643 pub fn type_ref(&self) -> Option<&TypeRef> {
3636 super::child_opt(self) 2644 super::child_opt(self)
3637 } 2645 }
3638} 2646}
3639 2647
3640// SourceFile 2648// SourceFile
3641#[derive(Debug, Clone, Copy,)] 2649#[derive(Debug, PartialEq, Eq, Hash)]
3642pub struct SourceFileNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2650#[repr(transparent)]
3643 pub(crate) syntax: SyntaxNode<R>, 2651pub struct SourceFile {
2652 pub(crate) syntax: SyntaxNode,
3644} 2653}
3645pub type SourceFile<'a> = SourceFileNode<RefRoot<'a>>; 2654unsafe impl TransparentNewType for SourceFile {
3646 2655 type Repr = rowan::SyntaxNode<RaTypes>;
3647impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SourceFileNode<R1>> for SourceFileNode<R2> {
3648 fn eq(&self, other: &SourceFileNode<R1>) -> bool { self.syntax == other.syntax }
3649}
3650impl<R: TreeRoot<RaTypes>> Eq for SourceFileNode<R> {}
3651impl<R: TreeRoot<RaTypes>> Hash for SourceFileNode<R> {
3652 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3653} 2656}
3654 2657
3655impl<'a> AstNode<'a> for SourceFile<'a> { 2658impl AstNode for SourceFile {
3656 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2659 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3657 match syntax.kind() { 2660 match syntax.kind() {
3658 SOURCE_FILE => Some(SourceFile { syntax }), 2661 SOURCE_FILE => Some(SourceFile::from_repr(syntax.into_repr())),
3659 _ => None, 2662 _ => None,
3660 } 2663 }
3661 } 2664 }
3662 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2665 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2666 fn to_owned(&self) -> TreePtr<SourceFile> { TreePtr::cast(self.syntax.to_owned()) }
3663} 2667}
3664 2668
3665impl<R: TreeRoot<RaTypes>> SourceFileNode<R> {
3666 pub fn borrowed(&self) -> SourceFile {
3667 SourceFileNode { syntax: self.syntax.borrowed() }
3668 }
3669 pub fn owned(&self) -> SourceFileNode {
3670 SourceFileNode { syntax: self.syntax.owned() }
3671 }
3672}
3673 2669
3674 2670impl ast::ModuleItemOwner for SourceFile {}
3675impl<'a> ast::ModuleItemOwner<'a> for SourceFile<'a> {} 2671impl ast::FnDefOwner for SourceFile {}
3676impl<'a> ast::FnDefOwner<'a> for SourceFile<'a> {} 2672impl SourceFile {
3677impl<'a> SourceFile<'a> { 2673 pub fn modules(&self) -> impl Iterator<Item = &Module> {
3678 pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a {
3679 super::children(self) 2674 super::children(self)
3680 } 2675 }
3681} 2676}
3682 2677
3683// StaticDef 2678// StaticDef
3684#[derive(Debug, Clone, Copy,)] 2679#[derive(Debug, PartialEq, Eq, Hash)]
3685pub struct StaticDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2680#[repr(transparent)]
3686 pub(crate) syntax: SyntaxNode<R>, 2681pub struct StaticDef {
3687} 2682 pub(crate) syntax: SyntaxNode,
3688pub type StaticDef<'a> = StaticDefNode<RefRoot<'a>>;
3689
3690impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StaticDefNode<R1>> for StaticDefNode<R2> {
3691 fn eq(&self, other: &StaticDefNode<R1>) -> bool { self.syntax == other.syntax }
3692} 2683}
3693impl<R: TreeRoot<RaTypes>> Eq for StaticDefNode<R> {} 2684unsafe impl TransparentNewType for StaticDef {
3694impl<R: TreeRoot<RaTypes>> Hash for StaticDefNode<R> { 2685 type Repr = rowan::SyntaxNode<RaTypes>;
3695 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3696} 2686}
3697 2687
3698impl<'a> AstNode<'a> for StaticDef<'a> { 2688impl AstNode for StaticDef {
3699 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2689 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3700 match syntax.kind() { 2690 match syntax.kind() {
3701 STATIC_DEF => Some(StaticDef { syntax }), 2691 STATIC_DEF => Some(StaticDef::from_repr(syntax.into_repr())),
3702 _ => None, 2692 _ => None,
3703 } 2693 }
3704 } 2694 }
3705 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2695 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2696 fn to_owned(&self) -> TreePtr<StaticDef> { TreePtr::cast(self.syntax.to_owned()) }
3706} 2697}
3707 2698
3708impl<R: TreeRoot<RaTypes>> StaticDefNode<R> {
3709 pub fn borrowed(&self) -> StaticDef {
3710 StaticDefNode { syntax: self.syntax.borrowed() }
3711 }
3712 pub fn owned(&self) -> StaticDefNode {
3713 StaticDefNode { syntax: self.syntax.owned() }
3714 }
3715}
3716 2699
3717 2700impl ast::VisibilityOwner for StaticDef {}
3718impl<'a> ast::VisibilityOwner<'a> for StaticDef<'a> {} 2701impl ast::NameOwner for StaticDef {}
3719impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} 2702impl ast::TypeParamsOwner for StaticDef {}
3720impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {} 2703impl ast::AttrsOwner for StaticDef {}
3721impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} 2704impl ast::DocCommentsOwner for StaticDef {}
3722impl<'a> ast::DocCommentsOwner<'a> for StaticDef<'a> {} 2705impl StaticDef {}
3723impl<'a> StaticDef<'a> {}
3724 2706
3725// Stmt 2707// Stmt
2708#[derive(Debug, PartialEq, Eq, Hash)]
2709#[repr(transparent)]
2710pub struct Stmt {
2711 pub(crate) syntax: SyntaxNode,
2712}
2713unsafe impl TransparentNewType for Stmt {
2714 type Repr = rowan::SyntaxNode<RaTypes>;
2715}
2716
3726#[derive(Debug, Clone, Copy, PartialEq, Eq)] 2717#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3727pub enum Stmt<'a> { 2718pub enum StmtKind<'a> {
3728 ExprStmt(ExprStmt<'a>), 2719 ExprStmt(&'a ExprStmt),
3729 LetStmt(LetStmt<'a>), 2720 LetStmt(&'a LetStmt),
3730} 2721}
3731 2722
3732impl<'a> AstNode<'a> for Stmt<'a> { 2723impl AstNode for Stmt {
3733 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2724 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3734 match syntax.kind() { 2725 match syntax.kind() {
3735 EXPR_STMT => Some(Stmt::ExprStmt(ExprStmt { syntax })), 2726 | EXPR_STMT
3736 LET_STMT => Some(Stmt::LetStmt(LetStmt { syntax })), 2727 | LET_STMT => Some(Stmt::from_repr(syntax.into_repr())),
3737 _ => None, 2728 _ => None,
3738 } 2729 }
3739 } 2730 }
3740 fn syntax(self) -> SyntaxNodeRef<'a> { 2731 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3741 match self { 2732 fn to_owned(&self) -> TreePtr<Stmt> { TreePtr::cast(self.syntax.to_owned()) }
3742 Stmt::ExprStmt(inner) => inner.syntax(), 2733}
3743 Stmt::LetStmt(inner) => inner.syntax(), 2734
2735impl Stmt {
2736 pub fn kind(&self) -> StmtKind {
2737 match self.syntax.kind() {
2738 EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(&self.syntax).unwrap()),
2739 LET_STMT => StmtKind::LetStmt(LetStmt::cast(&self.syntax).unwrap()),
2740 _ => unreachable!(),
3744 } 2741 }
3745 } 2742 }
3746} 2743}
3747 2744
3748impl<'a> Stmt<'a> {} 2745impl Stmt {}
3749 2746
3750// String 2747// String
3751#[derive(Debug, Clone, Copy,)] 2748#[derive(Debug, PartialEq, Eq, Hash)]
3752pub struct StringNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2749#[repr(transparent)]
3753 pub(crate) syntax: SyntaxNode<R>, 2750pub struct String {
3754} 2751 pub(crate) syntax: SyntaxNode,
3755pub type String<'a> = StringNode<RefRoot<'a>>;
3756
3757impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StringNode<R1>> for StringNode<R2> {
3758 fn eq(&self, other: &StringNode<R1>) -> bool { self.syntax == other.syntax }
3759} 2752}
3760impl<R: TreeRoot<RaTypes>> Eq for StringNode<R> {} 2753unsafe impl TransparentNewType for String {
3761impl<R: TreeRoot<RaTypes>> Hash for StringNode<R> { 2754 type Repr = rowan::SyntaxNode<RaTypes>;
3762 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3763} 2755}
3764 2756
3765impl<'a> AstNode<'a> for String<'a> { 2757impl AstNode for String {
3766 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2758 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3767 match syntax.kind() { 2759 match syntax.kind() {
3768 STRING => Some(String { syntax }), 2760 STRING => Some(String::from_repr(syntax.into_repr())),
3769 _ => None, 2761 _ => None,
3770 } 2762 }
3771 } 2763 }
3772 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2764 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3773} 2765 fn to_owned(&self) -> TreePtr<String> { TreePtr::cast(self.syntax.to_owned()) }
3774
3775impl<R: TreeRoot<RaTypes>> StringNode<R> {
3776 pub fn borrowed(&self) -> String {
3777 StringNode { syntax: self.syntax.borrowed() }
3778 }
3779 pub fn owned(&self) -> StringNode {
3780 StringNode { syntax: self.syntax.owned() }
3781 }
3782} 2766}
3783 2767
3784 2768
3785impl<'a> String<'a> {} 2769impl String {}
3786 2770
3787// StructDef 2771// StructDef
3788#[derive(Debug, Clone, Copy,)] 2772#[derive(Debug, PartialEq, Eq, Hash)]
3789pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2773#[repr(transparent)]
3790 pub(crate) syntax: SyntaxNode<R>, 2774pub struct StructDef {
2775 pub(crate) syntax: SyntaxNode,
3791} 2776}
3792pub type StructDef<'a> = StructDefNode<RefRoot<'a>>; 2777unsafe impl TransparentNewType for StructDef {
3793 2778 type Repr = rowan::SyntaxNode<RaTypes>;
3794impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructDefNode<R1>> for StructDefNode<R2> {
3795 fn eq(&self, other: &StructDefNode<R1>) -> bool { self.syntax == other.syntax }
3796}
3797impl<R: TreeRoot<RaTypes>> Eq for StructDefNode<R> {}
3798impl<R: TreeRoot<RaTypes>> Hash for StructDefNode<R> {
3799 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3800} 2779}
3801 2780
3802impl<'a> AstNode<'a> for StructDef<'a> { 2781impl AstNode for StructDef {
3803 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2782 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3804 match syntax.kind() { 2783 match syntax.kind() {
3805 STRUCT_DEF => Some(StructDef { syntax }), 2784 STRUCT_DEF => Some(StructDef::from_repr(syntax.into_repr())),
3806 _ => None, 2785 _ => None,
3807 } 2786 }
3808 } 2787 }
3809 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2788 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3810} 2789 fn to_owned(&self) -> TreePtr<StructDef> { TreePtr::cast(self.syntax.to_owned()) }
3811
3812impl<R: TreeRoot<RaTypes>> StructDefNode<R> {
3813 pub fn borrowed(&self) -> StructDef {
3814 StructDefNode { syntax: self.syntax.borrowed() }
3815 }
3816 pub fn owned(&self) -> StructDefNode {
3817 StructDefNode { syntax: self.syntax.owned() }
3818 }
3819} 2790}
3820 2791
3821 2792
3822impl<'a> ast::VisibilityOwner<'a> for StructDef<'a> {} 2793impl ast::VisibilityOwner for StructDef {}
3823impl<'a> ast::NameOwner<'a> for StructDef<'a> {} 2794impl ast::NameOwner for StructDef {}
3824impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {} 2795impl ast::TypeParamsOwner for StructDef {}
3825impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} 2796impl ast::AttrsOwner for StructDef {}
3826impl<'a> ast::DocCommentsOwner<'a> for StructDef<'a> {} 2797impl ast::DocCommentsOwner for StructDef {}
3827impl<'a> StructDef<'a> {} 2798impl StructDef {}
3828 2799
3829// StructLit 2800// StructLit
3830#[derive(Debug, Clone, Copy,)] 2801#[derive(Debug, PartialEq, Eq, Hash)]
3831pub struct StructLitNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2802#[repr(transparent)]
3832 pub(crate) syntax: SyntaxNode<R>, 2803pub struct StructLit {
2804 pub(crate) syntax: SyntaxNode,
3833} 2805}
3834pub type StructLit<'a> = StructLitNode<RefRoot<'a>>; 2806unsafe impl TransparentNewType for StructLit {
3835 2807 type Repr = rowan::SyntaxNode<RaTypes>;
3836impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructLitNode<R1>> for StructLitNode<R2> {
3837 fn eq(&self, other: &StructLitNode<R1>) -> bool { self.syntax == other.syntax }
3838}
3839impl<R: TreeRoot<RaTypes>> Eq for StructLitNode<R> {}
3840impl<R: TreeRoot<RaTypes>> Hash for StructLitNode<R> {
3841 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3842} 2808}
3843 2809
3844impl<'a> AstNode<'a> for StructLit<'a> { 2810impl AstNode for StructLit {
3845 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2811 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3846 match syntax.kind() { 2812 match syntax.kind() {
3847 STRUCT_LIT => Some(StructLit { syntax }), 2813 STRUCT_LIT => Some(StructLit::from_repr(syntax.into_repr())),
3848 _ => None, 2814 _ => None,
3849 } 2815 }
3850 } 2816 }
3851 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2817 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3852} 2818 fn to_owned(&self) -> TreePtr<StructLit> { TreePtr::cast(self.syntax.to_owned()) }
3853
3854impl<R: TreeRoot<RaTypes>> StructLitNode<R> {
3855 pub fn borrowed(&self) -> StructLit {
3856 StructLitNode { syntax: self.syntax.borrowed() }
3857 }
3858 pub fn owned(&self) -> StructLitNode {
3859 StructLitNode { syntax: self.syntax.owned() }
3860 }
3861} 2819}
3862 2820
3863 2821
3864impl<'a> StructLit<'a> { 2822impl StructLit {
3865 pub fn path(self) -> Option<Path<'a>> { 2823 pub fn path(&self) -> Option<&Path> {
3866 super::child_opt(self) 2824 super::child_opt(self)
3867 } 2825 }
3868 2826
3869 pub fn named_field_list(self) -> Option<NamedFieldList<'a>> { 2827 pub fn named_field_list(&self) -> Option<&NamedFieldList> {
3870 super::child_opt(self) 2828 super::child_opt(self)
3871 } 2829 }
3872 2830
3873 pub fn spread(self) -> Option<Expr<'a>> { 2831 pub fn spread(&self) -> Option<&Expr> {
3874 super::child_opt(self) 2832 super::child_opt(self)
3875 } 2833 }
3876} 2834}
3877 2835
3878// StructPat 2836// StructPat
3879#[derive(Debug, Clone, Copy,)] 2837#[derive(Debug, PartialEq, Eq, Hash)]
3880pub struct StructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2838#[repr(transparent)]
3881 pub(crate) syntax: SyntaxNode<R>, 2839pub struct StructPat {
3882} 2840 pub(crate) syntax: SyntaxNode,
3883pub type StructPat<'a> = StructPatNode<RefRoot<'a>>;
3884
3885impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructPatNode<R1>> for StructPatNode<R2> {
3886 fn eq(&self, other: &StructPatNode<R1>) -> bool { self.syntax == other.syntax }
3887} 2841}
3888impl<R: TreeRoot<RaTypes>> Eq for StructPatNode<R> {} 2842unsafe impl TransparentNewType for StructPat {
3889impl<R: TreeRoot<RaTypes>> Hash for StructPatNode<R> { 2843 type Repr = rowan::SyntaxNode<RaTypes>;
3890 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3891} 2844}
3892 2845
3893impl<'a> AstNode<'a> for StructPat<'a> { 2846impl AstNode for StructPat {
3894 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2847 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3895 match syntax.kind() { 2848 match syntax.kind() {
3896 STRUCT_PAT => Some(StructPat { syntax }), 2849 STRUCT_PAT => Some(StructPat::from_repr(syntax.into_repr())),
3897 _ => None, 2850 _ => None,
3898 } 2851 }
3899 } 2852 }
3900 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2853 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2854 fn to_owned(&self) -> TreePtr<StructPat> { TreePtr::cast(self.syntax.to_owned()) }
3901} 2855}
3902 2856
3903impl<R: TreeRoot<RaTypes>> StructPatNode<R> {
3904 pub fn borrowed(&self) -> StructPat {
3905 StructPatNode { syntax: self.syntax.borrowed() }
3906 }
3907 pub fn owned(&self) -> StructPatNode {
3908 StructPatNode { syntax: self.syntax.owned() }
3909 }
3910}
3911 2857
3912 2858impl StructPat {}
3913impl<'a> StructPat<'a> {}
3914 2859
3915// TokenTree 2860// TokenTree
3916#[derive(Debug, Clone, Copy,)] 2861#[derive(Debug, PartialEq, Eq, Hash)]
3917pub struct TokenTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2862#[repr(transparent)]
3918 pub(crate) syntax: SyntaxNode<R>, 2863pub struct TokenTree {
3919} 2864 pub(crate) syntax: SyntaxNode,
3920pub type TokenTree<'a> = TokenTreeNode<RefRoot<'a>>;
3921
3922impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TokenTreeNode<R1>> for TokenTreeNode<R2> {
3923 fn eq(&self, other: &TokenTreeNode<R1>) -> bool { self.syntax == other.syntax }
3924} 2865}
3925impl<R: TreeRoot<RaTypes>> Eq for TokenTreeNode<R> {} 2866unsafe impl TransparentNewType for TokenTree {
3926impl<R: TreeRoot<RaTypes>> Hash for TokenTreeNode<R> { 2867 type Repr = rowan::SyntaxNode<RaTypes>;
3927 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3928} 2868}
3929 2869
3930impl<'a> AstNode<'a> for TokenTree<'a> { 2870impl AstNode for TokenTree {
3931 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2871 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3932 match syntax.kind() { 2872 match syntax.kind() {
3933 TOKEN_TREE => Some(TokenTree { syntax }), 2873 TOKEN_TREE => Some(TokenTree::from_repr(syntax.into_repr())),
3934 _ => None, 2874 _ => None,
3935 } 2875 }
3936 } 2876 }
3937 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2877 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3938} 2878 fn to_owned(&self) -> TreePtr<TokenTree> { TreePtr::cast(self.syntax.to_owned()) }
3939
3940impl<R: TreeRoot<RaTypes>> TokenTreeNode<R> {
3941 pub fn borrowed(&self) -> TokenTree {
3942 TokenTreeNode { syntax: self.syntax.borrowed() }
3943 }
3944 pub fn owned(&self) -> TokenTreeNode {
3945 TokenTreeNode { syntax: self.syntax.owned() }
3946 }
3947} 2879}
3948 2880
3949 2881
3950impl<'a> TokenTree<'a> {} 2882impl TokenTree {}
3951 2883
3952// TraitDef 2884// TraitDef
3953#[derive(Debug, Clone, Copy,)] 2885#[derive(Debug, PartialEq, Eq, Hash)]
3954pub struct TraitDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2886#[repr(transparent)]
3955 pub(crate) syntax: SyntaxNode<R>, 2887pub struct TraitDef {
2888 pub(crate) syntax: SyntaxNode,
3956} 2889}
3957pub type TraitDef<'a> = TraitDefNode<RefRoot<'a>>; 2890unsafe impl TransparentNewType for TraitDef {
3958 2891 type Repr = rowan::SyntaxNode<RaTypes>;
3959impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TraitDefNode<R1>> for TraitDefNode<R2> {
3960 fn eq(&self, other: &TraitDefNode<R1>) -> bool { self.syntax == other.syntax }
3961}
3962impl<R: TreeRoot<RaTypes>> Eq for TraitDefNode<R> {}
3963impl<R: TreeRoot<RaTypes>> Hash for TraitDefNode<R> {
3964 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3965} 2892}
3966 2893
3967impl<'a> AstNode<'a> for TraitDef<'a> { 2894impl AstNode for TraitDef {
3968 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2895 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3969 match syntax.kind() { 2896 match syntax.kind() {
3970 TRAIT_DEF => Some(TraitDef { syntax }), 2897 TRAIT_DEF => Some(TraitDef::from_repr(syntax.into_repr())),
3971 _ => None, 2898 _ => None,
3972 } 2899 }
3973 } 2900 }
3974 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2901 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3975} 2902 fn to_owned(&self) -> TreePtr<TraitDef> { TreePtr::cast(self.syntax.to_owned()) }
3976
3977impl<R: TreeRoot<RaTypes>> TraitDefNode<R> {
3978 pub fn borrowed(&self) -> TraitDef {
3979 TraitDefNode { syntax: self.syntax.borrowed() }
3980 }
3981 pub fn owned(&self) -> TraitDefNode {
3982 TraitDefNode { syntax: self.syntax.owned() }
3983 }
3984} 2903}
3985 2904
3986 2905
3987impl<'a> ast::VisibilityOwner<'a> for TraitDef<'a> {} 2906impl ast::VisibilityOwner for TraitDef {}
3988impl<'a> ast::NameOwner<'a> for TraitDef<'a> {} 2907impl ast::NameOwner for TraitDef {}
3989impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {} 2908impl ast::AttrsOwner for TraitDef {}
3990impl<'a> ast::DocCommentsOwner<'a> for TraitDef<'a> {} 2909impl ast::DocCommentsOwner for TraitDef {}
3991impl<'a> TraitDef<'a> {} 2910impl TraitDef {}
3992 2911
3993// TryExpr 2912// TryExpr
3994#[derive(Debug, Clone, Copy,)] 2913#[derive(Debug, PartialEq, Eq, Hash)]
3995pub struct TryExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2914#[repr(transparent)]
3996 pub(crate) syntax: SyntaxNode<R>, 2915pub struct TryExpr {
2916 pub(crate) syntax: SyntaxNode,
3997} 2917}
3998pub type TryExpr<'a> = TryExprNode<RefRoot<'a>>; 2918unsafe impl TransparentNewType for TryExpr {
3999 2919 type Repr = rowan::SyntaxNode<RaTypes>;
4000impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TryExprNode<R1>> for TryExprNode<R2> {
4001 fn eq(&self, other: &TryExprNode<R1>) -> bool { self.syntax == other.syntax }
4002}
4003impl<R: TreeRoot<RaTypes>> Eq for TryExprNode<R> {}
4004impl<R: TreeRoot<RaTypes>> Hash for TryExprNode<R> {
4005 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4006} 2920}
4007 2921
4008impl<'a> AstNode<'a> for TryExpr<'a> { 2922impl AstNode for TryExpr {
4009 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2923 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4010 match syntax.kind() { 2924 match syntax.kind() {
4011 TRY_EXPR => Some(TryExpr { syntax }), 2925 TRY_EXPR => Some(TryExpr::from_repr(syntax.into_repr())),
4012 _ => None, 2926 _ => None,
4013 } 2927 }
4014 } 2928 }
4015 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2929 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2930 fn to_owned(&self) -> TreePtr<TryExpr> { TreePtr::cast(self.syntax.to_owned()) }
4016} 2931}
4017 2932
4018impl<R: TreeRoot<RaTypes>> TryExprNode<R> {
4019 pub fn borrowed(&self) -> TryExpr {
4020 TryExprNode { syntax: self.syntax.borrowed() }
4021 }
4022 pub fn owned(&self) -> TryExprNode {
4023 TryExprNode { syntax: self.syntax.owned() }
4024 }
4025}
4026 2933
4027 2934impl TryExpr {
4028impl<'a> TryExpr<'a> { 2935 pub fn expr(&self) -> Option<&Expr> {
4029 pub fn expr(self) -> Option<Expr<'a>> {
4030 super::child_opt(self) 2936 super::child_opt(self)
4031 } 2937 }
4032} 2938}
4033 2939
4034// TupleExpr 2940// TupleExpr
4035#[derive(Debug, Clone, Copy,)] 2941#[derive(Debug, PartialEq, Eq, Hash)]
4036pub struct TupleExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2942#[repr(transparent)]
4037 pub(crate) syntax: SyntaxNode<R>, 2943pub struct TupleExpr {
4038} 2944 pub(crate) syntax: SyntaxNode,
4039pub type TupleExpr<'a> = TupleExprNode<RefRoot<'a>>;
4040
4041impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleExprNode<R1>> for TupleExprNode<R2> {
4042 fn eq(&self, other: &TupleExprNode<R1>) -> bool { self.syntax == other.syntax }
4043} 2945}
4044impl<R: TreeRoot<RaTypes>> Eq for TupleExprNode<R> {} 2946unsafe impl TransparentNewType for TupleExpr {
4045impl<R: TreeRoot<RaTypes>> Hash for TupleExprNode<R> { 2947 type Repr = rowan::SyntaxNode<RaTypes>;
4046 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4047} 2948}
4048 2949
4049impl<'a> AstNode<'a> for TupleExpr<'a> { 2950impl AstNode for TupleExpr {
4050 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2951 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4051 match syntax.kind() { 2952 match syntax.kind() {
4052 TUPLE_EXPR => Some(TupleExpr { syntax }), 2953 TUPLE_EXPR => Some(TupleExpr::from_repr(syntax.into_repr())),
4053 _ => None, 2954 _ => None,
4054 } 2955 }
4055 } 2956 }
4056 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2957 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4057} 2958 fn to_owned(&self) -> TreePtr<TupleExpr> { TreePtr::cast(self.syntax.to_owned()) }
4058
4059impl<R: TreeRoot<RaTypes>> TupleExprNode<R> {
4060 pub fn borrowed(&self) -> TupleExpr {
4061 TupleExprNode { syntax: self.syntax.borrowed() }
4062 }
4063 pub fn owned(&self) -> TupleExprNode {
4064 TupleExprNode { syntax: self.syntax.owned() }
4065 }
4066} 2959}
4067 2960
4068 2961
4069impl<'a> TupleExpr<'a> {} 2962impl TupleExpr {}
4070 2963
4071// TuplePat 2964// TuplePat
4072#[derive(Debug, Clone, Copy,)] 2965#[derive(Debug, PartialEq, Eq, Hash)]
4073pub struct TuplePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2966#[repr(transparent)]
4074 pub(crate) syntax: SyntaxNode<R>, 2967pub struct TuplePat {
2968 pub(crate) syntax: SyntaxNode,
4075} 2969}
4076pub type TuplePat<'a> = TuplePatNode<RefRoot<'a>>; 2970unsafe impl TransparentNewType for TuplePat {
4077 2971 type Repr = rowan::SyntaxNode<RaTypes>;
4078impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TuplePatNode<R1>> for TuplePatNode<R2> {
4079 fn eq(&self, other: &TuplePatNode<R1>) -> bool { self.syntax == other.syntax }
4080}
4081impl<R: TreeRoot<RaTypes>> Eq for TuplePatNode<R> {}
4082impl<R: TreeRoot<RaTypes>> Hash for TuplePatNode<R> {
4083 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4084} 2972}
4085 2973
4086impl<'a> AstNode<'a> for TuplePat<'a> { 2974impl AstNode for TuplePat {
4087 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2975 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4088 match syntax.kind() { 2976 match syntax.kind() {
4089 TUPLE_PAT => Some(TuplePat { syntax }), 2977 TUPLE_PAT => Some(TuplePat::from_repr(syntax.into_repr())),
4090 _ => None, 2978 _ => None,
4091 } 2979 }
4092 } 2980 }
4093 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2981 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4094} 2982 fn to_owned(&self) -> TreePtr<TuplePat> { TreePtr::cast(self.syntax.to_owned()) }
4095
4096impl<R: TreeRoot<RaTypes>> TuplePatNode<R> {
4097 pub fn borrowed(&self) -> TuplePat {
4098 TuplePatNode { syntax: self.syntax.borrowed() }
4099 }
4100 pub fn owned(&self) -> TuplePatNode {
4101 TuplePatNode { syntax: self.syntax.owned() }
4102 }
4103} 2983}
4104 2984
4105 2985
4106impl<'a> TuplePat<'a> {} 2986impl TuplePat {}
4107 2987
4108// TupleStructPat 2988// TupleStructPat
4109#[derive(Debug, Clone, Copy,)] 2989#[derive(Debug, PartialEq, Eq, Hash)]
4110pub struct TupleStructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 2990#[repr(transparent)]
4111 pub(crate) syntax: SyntaxNode<R>, 2991pub struct TupleStructPat {
2992 pub(crate) syntax: SyntaxNode,
4112} 2993}
4113pub type TupleStructPat<'a> = TupleStructPatNode<RefRoot<'a>>; 2994unsafe impl TransparentNewType for TupleStructPat {
4114 2995 type Repr = rowan::SyntaxNode<RaTypes>;
4115impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleStructPatNode<R1>> for TupleStructPatNode<R2> {
4116 fn eq(&self, other: &TupleStructPatNode<R1>) -> bool { self.syntax == other.syntax }
4117}
4118impl<R: TreeRoot<RaTypes>> Eq for TupleStructPatNode<R> {}
4119impl<R: TreeRoot<RaTypes>> Hash for TupleStructPatNode<R> {
4120 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4121} 2996}
4122 2997
4123impl<'a> AstNode<'a> for TupleStructPat<'a> { 2998impl AstNode for TupleStructPat {
4124 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 2999 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4125 match syntax.kind() { 3000 match syntax.kind() {
4126 TUPLE_STRUCT_PAT => Some(TupleStructPat { syntax }), 3001 TUPLE_STRUCT_PAT => Some(TupleStructPat::from_repr(syntax.into_repr())),
4127 _ => None, 3002 _ => None,
4128 } 3003 }
4129 } 3004 }
4130 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3005 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4131} 3006 fn to_owned(&self) -> TreePtr<TupleStructPat> { TreePtr::cast(self.syntax.to_owned()) }
4132
4133impl<R: TreeRoot<RaTypes>> TupleStructPatNode<R> {
4134 pub fn borrowed(&self) -> TupleStructPat {
4135 TupleStructPatNode { syntax: self.syntax.borrowed() }
4136 }
4137 pub fn owned(&self) -> TupleStructPatNode {
4138 TupleStructPatNode { syntax: self.syntax.owned() }
4139 }
4140} 3007}
4141 3008
4142 3009
4143impl<'a> TupleStructPat<'a> { 3010impl TupleStructPat {
4144 pub fn args(self) -> impl Iterator<Item = Pat<'a>> + 'a { 3011 pub fn args(&self) -> impl Iterator<Item = &Pat> {
4145 super::children(self) 3012 super::children(self)
4146 } 3013 }
4147 3014
4148 pub fn path(self) -> Option<Path<'a>> { 3015 pub fn path(&self) -> Option<&Path> {
4149 super::child_opt(self) 3016 super::child_opt(self)
4150 } 3017 }
4151} 3018}
4152 3019
4153// TupleType 3020// TupleType
4154#[derive(Debug, Clone, Copy,)] 3021#[derive(Debug, PartialEq, Eq, Hash)]
4155pub struct TupleTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3022#[repr(transparent)]
4156 pub(crate) syntax: SyntaxNode<R>, 3023pub struct TupleType {
4157} 3024 pub(crate) syntax: SyntaxNode,
4158pub type TupleType<'a> = TupleTypeNode<RefRoot<'a>>;
4159
4160impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleTypeNode<R1>> for TupleTypeNode<R2> {
4161 fn eq(&self, other: &TupleTypeNode<R1>) -> bool { self.syntax == other.syntax }
4162} 3025}
4163impl<R: TreeRoot<RaTypes>> Eq for TupleTypeNode<R> {} 3026unsafe impl TransparentNewType for TupleType {
4164impl<R: TreeRoot<RaTypes>> Hash for TupleTypeNode<R> { 3027 type Repr = rowan::SyntaxNode<RaTypes>;
4165 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4166} 3028}
4167 3029
4168impl<'a> AstNode<'a> for TupleType<'a> { 3030impl AstNode for TupleType {
4169 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3031 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4170 match syntax.kind() { 3032 match syntax.kind() {
4171 TUPLE_TYPE => Some(TupleType { syntax }), 3033 TUPLE_TYPE => Some(TupleType::from_repr(syntax.into_repr())),
4172 _ => None, 3034 _ => None,
4173 } 3035 }
4174 } 3036 }
4175 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3037 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3038 fn to_owned(&self) -> TreePtr<TupleType> { TreePtr::cast(self.syntax.to_owned()) }
4176} 3039}
4177 3040
4178impl<R: TreeRoot<RaTypes>> TupleTypeNode<R> {
4179 pub fn borrowed(&self) -> TupleType {
4180 TupleTypeNode { syntax: self.syntax.borrowed() }
4181 }
4182 pub fn owned(&self) -> TupleTypeNode {
4183 TupleTypeNode { syntax: self.syntax.owned() }
4184 }
4185}
4186 3041
4187 3042impl TupleType {
4188impl<'a> TupleType<'a> { 3043 pub fn fields(&self) -> impl Iterator<Item = &TypeRef> {
4189 pub fn fields(self) -> impl Iterator<Item = TypeRef<'a>> + 'a {
4190 super::children(self) 3044 super::children(self)
4191 } 3045 }
4192} 3046}
4193 3047
4194// TypeDef 3048// TypeDef
4195#[derive(Debug, Clone, Copy,)] 3049#[derive(Debug, PartialEq, Eq, Hash)]
4196pub struct TypeDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3050#[repr(transparent)]
4197 pub(crate) syntax: SyntaxNode<R>, 3051pub struct TypeDef {
4198} 3052 pub(crate) syntax: SyntaxNode,
4199pub type TypeDef<'a> = TypeDefNode<RefRoot<'a>>;
4200
4201impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeDefNode<R1>> for TypeDefNode<R2> {
4202 fn eq(&self, other: &TypeDefNode<R1>) -> bool { self.syntax == other.syntax }
4203} 3053}
4204impl<R: TreeRoot<RaTypes>> Eq for TypeDefNode<R> {} 3054unsafe impl TransparentNewType for TypeDef {
4205impl<R: TreeRoot<RaTypes>> Hash for TypeDefNode<R> { 3055 type Repr = rowan::SyntaxNode<RaTypes>;
4206 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4207} 3056}
4208 3057
4209impl<'a> AstNode<'a> for TypeDef<'a> { 3058impl AstNode for TypeDef {
4210 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3059 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4211 match syntax.kind() { 3060 match syntax.kind() {
4212 TYPE_DEF => Some(TypeDef { syntax }), 3061 TYPE_DEF => Some(TypeDef::from_repr(syntax.into_repr())),
4213 _ => None, 3062 _ => None,
4214 } 3063 }
4215 } 3064 }
4216 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3065 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4217} 3066 fn to_owned(&self) -> TreePtr<TypeDef> { TreePtr::cast(self.syntax.to_owned()) }
4218
4219impl<R: TreeRoot<RaTypes>> TypeDefNode<R> {
4220 pub fn borrowed(&self) -> TypeDef {
4221 TypeDefNode { syntax: self.syntax.borrowed() }
4222 }
4223 pub fn owned(&self) -> TypeDefNode {
4224 TypeDefNode { syntax: self.syntax.owned() }
4225 }
4226} 3067}
4227 3068
4228 3069
4229impl<'a> ast::VisibilityOwner<'a> for TypeDef<'a> {} 3070impl ast::VisibilityOwner for TypeDef {}
4230impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} 3071impl ast::NameOwner for TypeDef {}
4231impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {} 3072impl ast::TypeParamsOwner for TypeDef {}
4232impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} 3073impl ast::AttrsOwner for TypeDef {}
4233impl<'a> ast::DocCommentsOwner<'a> for TypeDef<'a> {} 3074impl ast::DocCommentsOwner for TypeDef {}
4234impl<'a> TypeDef<'a> {} 3075impl TypeDef {}
4235 3076
4236// TypeParam 3077// TypeParam
4237#[derive(Debug, Clone, Copy,)] 3078#[derive(Debug, PartialEq, Eq, Hash)]
4238pub struct TypeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3079#[repr(transparent)]
4239 pub(crate) syntax: SyntaxNode<R>, 3080pub struct TypeParam {
3081 pub(crate) syntax: SyntaxNode,
4240} 3082}
4241pub type TypeParam<'a> = TypeParamNode<RefRoot<'a>>; 3083unsafe impl TransparentNewType for TypeParam {
4242 3084 type Repr = rowan::SyntaxNode<RaTypes>;
4243impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeParamNode<R1>> for TypeParamNode<R2> {
4244 fn eq(&self, other: &TypeParamNode<R1>) -> bool { self.syntax == other.syntax }
4245}
4246impl<R: TreeRoot<RaTypes>> Eq for TypeParamNode<R> {}
4247impl<R: TreeRoot<RaTypes>> Hash for TypeParamNode<R> {
4248 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4249} 3085}
4250 3086
4251impl<'a> AstNode<'a> for TypeParam<'a> { 3087impl AstNode for TypeParam {
4252 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3088 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4253 match syntax.kind() { 3089 match syntax.kind() {
4254 TYPE_PARAM => Some(TypeParam { syntax }), 3090 TYPE_PARAM => Some(TypeParam::from_repr(syntax.into_repr())),
4255 _ => None, 3091 _ => None,
4256 } 3092 }
4257 } 3093 }
4258 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3094 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4259} 3095 fn to_owned(&self) -> TreePtr<TypeParam> { TreePtr::cast(self.syntax.to_owned()) }
4260
4261impl<R: TreeRoot<RaTypes>> TypeParamNode<R> {
4262 pub fn borrowed(&self) -> TypeParam {
4263 TypeParamNode { syntax: self.syntax.borrowed() }
4264 }
4265 pub fn owned(&self) -> TypeParamNode {
4266 TypeParamNode { syntax: self.syntax.owned() }
4267 }
4268} 3096}
4269 3097
4270 3098
4271impl<'a> ast::NameOwner<'a> for TypeParam<'a> {} 3099impl ast::NameOwner for TypeParam {}
4272impl<'a> TypeParam<'a> {} 3100impl TypeParam {}
4273 3101
4274// TypeParamList 3102// TypeParamList
4275#[derive(Debug, Clone, Copy,)] 3103#[derive(Debug, PartialEq, Eq, Hash)]
4276pub struct TypeParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3104#[repr(transparent)]
4277 pub(crate) syntax: SyntaxNode<R>, 3105pub struct TypeParamList {
3106 pub(crate) syntax: SyntaxNode,
4278} 3107}
4279pub type TypeParamList<'a> = TypeParamListNode<RefRoot<'a>>; 3108unsafe impl TransparentNewType for TypeParamList {
4280 3109 type Repr = rowan::SyntaxNode<RaTypes>;
4281impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeParamListNode<R1>> for TypeParamListNode<R2> {
4282 fn eq(&self, other: &TypeParamListNode<R1>) -> bool { self.syntax == other.syntax }
4283}
4284impl<R: TreeRoot<RaTypes>> Eq for TypeParamListNode<R> {}
4285impl<R: TreeRoot<RaTypes>> Hash for TypeParamListNode<R> {
4286 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4287} 3110}
4288 3111
4289impl<'a> AstNode<'a> for TypeParamList<'a> { 3112impl AstNode for TypeParamList {
4290 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3113 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4291 match syntax.kind() { 3114 match syntax.kind() {
4292 TYPE_PARAM_LIST => Some(TypeParamList { syntax }), 3115 TYPE_PARAM_LIST => Some(TypeParamList::from_repr(syntax.into_repr())),
4293 _ => None, 3116 _ => None,
4294 } 3117 }
4295 } 3118 }
4296 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3119 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3120 fn to_owned(&self) -> TreePtr<TypeParamList> { TreePtr::cast(self.syntax.to_owned()) }
4297} 3121}
4298 3122
4299impl<R: TreeRoot<RaTypes>> TypeParamListNode<R> {
4300 pub fn borrowed(&self) -> TypeParamList {
4301 TypeParamListNode { syntax: self.syntax.borrowed() }
4302 }
4303 pub fn owned(&self) -> TypeParamListNode {
4304 TypeParamListNode { syntax: self.syntax.owned() }
4305 }
4306}
4307 3123
4308 3124impl TypeParamList {
4309impl<'a> TypeParamList<'a> { 3125 pub fn type_params(&self) -> impl Iterator<Item = &TypeParam> {
4310 pub fn type_params(self) -> impl Iterator<Item = TypeParam<'a>> + 'a {
4311 super::children(self) 3126 super::children(self)
4312 } 3127 }
4313 3128
4314 pub fn lifetime_params(self) -> impl Iterator<Item = LifetimeParam<'a>> + 'a { 3129 pub fn lifetime_params(&self) -> impl Iterator<Item = &LifetimeParam> {
4315 super::children(self) 3130 super::children(self)
4316 } 3131 }
4317} 3132}
4318 3133
4319// TypeRef 3134// TypeRef
4320#[derive(Debug, Clone, Copy, PartialEq, Eq)] 3135#[derive(Debug, PartialEq, Eq, Hash)]
4321pub enum TypeRef<'a> { 3136#[repr(transparent)]
4322 ParenType(ParenType<'a>), 3137pub struct TypeRef {
4323 TupleType(TupleType<'a>), 3138 pub(crate) syntax: SyntaxNode,
4324 NeverType(NeverType<'a>), 3139}
4325 PathType(PathType<'a>), 3140unsafe impl TransparentNewType for TypeRef {
4326 PointerType(PointerType<'a>), 3141 type Repr = rowan::SyntaxNode<RaTypes>;
4327 ArrayType(ArrayType<'a>),
4328 SliceType(SliceType<'a>),
4329 ReferenceType(ReferenceType<'a>),
4330 PlaceholderType(PlaceholderType<'a>),
4331 FnPointerType(FnPointerType<'a>),
4332 ForType(ForType<'a>),
4333 ImplTraitType(ImplTraitType<'a>),
4334 DynTraitType(DynTraitType<'a>),
4335}
4336
4337impl<'a> AstNode<'a> for TypeRef<'a> {
4338 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
4339 match syntax.kind() {
4340 PAREN_TYPE => Some(TypeRef::ParenType(ParenType { syntax })),
4341 TUPLE_TYPE => Some(TypeRef::TupleType(TupleType { syntax })),
4342 NEVER_TYPE => Some(TypeRef::NeverType(NeverType { syntax })),
4343 PATH_TYPE => Some(TypeRef::PathType(PathType { syntax })),
4344 POINTER_TYPE => Some(TypeRef::PointerType(PointerType { syntax })),
4345 ARRAY_TYPE => Some(TypeRef::ArrayType(ArrayType { syntax })),
4346 SLICE_TYPE => Some(TypeRef::SliceType(SliceType { syntax })),
4347 REFERENCE_TYPE => Some(TypeRef::ReferenceType(ReferenceType { syntax })),
4348 PLACEHOLDER_TYPE => Some(TypeRef::PlaceholderType(PlaceholderType { syntax })),
4349 FN_POINTER_TYPE => Some(TypeRef::FnPointerType(FnPointerType { syntax })),
4350 FOR_TYPE => Some(TypeRef::ForType(ForType { syntax })),
4351 IMPL_TRAIT_TYPE => Some(TypeRef::ImplTraitType(ImplTraitType { syntax })),
4352 DYN_TRAIT_TYPE => Some(TypeRef::DynTraitType(DynTraitType { syntax })),
4353 _ => None,
4354 }
4355 }
4356 fn syntax(self) -> SyntaxNodeRef<'a> {
4357 match self {
4358 TypeRef::ParenType(inner) => inner.syntax(),
4359 TypeRef::TupleType(inner) => inner.syntax(),
4360 TypeRef::NeverType(inner) => inner.syntax(),
4361 TypeRef::PathType(inner) => inner.syntax(),
4362 TypeRef::PointerType(inner) => inner.syntax(),
4363 TypeRef::ArrayType(inner) => inner.syntax(),
4364 TypeRef::SliceType(inner) => inner.syntax(),
4365 TypeRef::ReferenceType(inner) => inner.syntax(),
4366 TypeRef::PlaceholderType(inner) => inner.syntax(),
4367 TypeRef::FnPointerType(inner) => inner.syntax(),
4368 TypeRef::ForType(inner) => inner.syntax(),
4369 TypeRef::ImplTraitType(inner) => inner.syntax(),
4370 TypeRef::DynTraitType(inner) => inner.syntax(),
4371 }
4372 }
4373} 3142}
4374 3143
4375impl<'a> TypeRef<'a> {} 3144#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3145pub enum TypeRefKind<'a> {
3146 ParenType(&'a ParenType),
3147 TupleType(&'a TupleType),
3148 NeverType(&'a NeverType),
3149 PathType(&'a PathType),
3150 PointerType(&'a PointerType),
3151 ArrayType(&'a ArrayType),
3152 SliceType(&'a SliceType),
3153 ReferenceType(&'a ReferenceType),
3154 PlaceholderType(&'a PlaceholderType),
3155 FnPointerType(&'a FnPointerType),
3156 ForType(&'a ForType),
3157 ImplTraitType(&'a ImplTraitType),
3158 DynTraitType(&'a DynTraitType),
3159}
3160
3161impl AstNode for TypeRef {
3162 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3163 match syntax.kind() {
3164 | PAREN_TYPE
3165 | TUPLE_TYPE
3166 | NEVER_TYPE
3167 | PATH_TYPE
3168 | POINTER_TYPE
3169 | ARRAY_TYPE
3170 | SLICE_TYPE
3171 | REFERENCE_TYPE
3172 | PLACEHOLDER_TYPE
3173 | FN_POINTER_TYPE
3174 | FOR_TYPE
3175 | IMPL_TRAIT_TYPE
3176 | DYN_TRAIT_TYPE => Some(TypeRef::from_repr(syntax.into_repr())),
3177 _ => None,
3178 }
3179 }
3180 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3181 fn to_owned(&self) -> TreePtr<TypeRef> { TreePtr::cast(self.syntax.to_owned()) }
3182}
3183
3184impl TypeRef {
3185 pub fn kind(&self) -> TypeRefKind {
3186 match self.syntax.kind() {
3187 PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(&self.syntax).unwrap()),
3188 TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(&self.syntax).unwrap()),
3189 NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(&self.syntax).unwrap()),
3190 PATH_TYPE => TypeRefKind::PathType(PathType::cast(&self.syntax).unwrap()),
3191 POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(&self.syntax).unwrap()),
3192 ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(&self.syntax).unwrap()),
3193 SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(&self.syntax).unwrap()),
3194 REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(&self.syntax).unwrap()),
3195 PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(&self.syntax).unwrap()),
3196 FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(&self.syntax).unwrap()),
3197 FOR_TYPE => TypeRefKind::ForType(ForType::cast(&self.syntax).unwrap()),
3198 IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(&self.syntax).unwrap()),
3199 DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(&self.syntax).unwrap()),
3200 _ => unreachable!(),
3201 }
3202 }
3203}
3204
3205impl TypeRef {}
4376 3206
4377// UseItem 3207// UseItem
4378#[derive(Debug, Clone, Copy,)] 3208#[derive(Debug, PartialEq, Eq, Hash)]
4379pub struct UseItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3209#[repr(transparent)]
4380 pub(crate) syntax: SyntaxNode<R>, 3210pub struct UseItem {
3211 pub(crate) syntax: SyntaxNode,
4381} 3212}
4382pub type UseItem<'a> = UseItemNode<RefRoot<'a>>; 3213unsafe impl TransparentNewType for UseItem {
4383 3214 type Repr = rowan::SyntaxNode<RaTypes>;
4384impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseItemNode<R1>> for UseItemNode<R2> {
4385 fn eq(&self, other: &UseItemNode<R1>) -> bool { self.syntax == other.syntax }
4386}
4387impl<R: TreeRoot<RaTypes>> Eq for UseItemNode<R> {}
4388impl<R: TreeRoot<RaTypes>> Hash for UseItemNode<R> {
4389 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4390} 3215}
4391 3216
4392impl<'a> AstNode<'a> for UseItem<'a> { 3217impl AstNode for UseItem {
4393 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3218 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4394 match syntax.kind() { 3219 match syntax.kind() {
4395 USE_ITEM => Some(UseItem { syntax }), 3220 USE_ITEM => Some(UseItem::from_repr(syntax.into_repr())),
4396 _ => None, 3221 _ => None,
4397 } 3222 }
4398 } 3223 }
4399 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3224 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4400} 3225 fn to_owned(&self) -> TreePtr<UseItem> { TreePtr::cast(self.syntax.to_owned()) }
4401
4402impl<R: TreeRoot<RaTypes>> UseItemNode<R> {
4403 pub fn borrowed(&self) -> UseItem {
4404 UseItemNode { syntax: self.syntax.borrowed() }
4405 }
4406 pub fn owned(&self) -> UseItemNode {
4407 UseItemNode { syntax: self.syntax.owned() }
4408 }
4409} 3226}
4410 3227
4411 3228
4412impl<'a> UseItem<'a> { 3229impl UseItem {
4413 pub fn use_tree(self) -> Option<UseTree<'a>> { 3230 pub fn use_tree(&self) -> Option<&UseTree> {
4414 super::child_opt(self) 3231 super::child_opt(self)
4415 } 3232 }
4416} 3233}
4417 3234
4418// UseTree 3235// UseTree
4419#[derive(Debug, Clone, Copy,)] 3236#[derive(Debug, PartialEq, Eq, Hash)]
4420pub struct UseTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3237#[repr(transparent)]
4421 pub(crate) syntax: SyntaxNode<R>, 3238pub struct UseTree {
3239 pub(crate) syntax: SyntaxNode,
4422} 3240}
4423pub type UseTree<'a> = UseTreeNode<RefRoot<'a>>; 3241unsafe impl TransparentNewType for UseTree {
4424 3242 type Repr = rowan::SyntaxNode<RaTypes>;
4425impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseTreeNode<R1>> for UseTreeNode<R2> {
4426 fn eq(&self, other: &UseTreeNode<R1>) -> bool { self.syntax == other.syntax }
4427}
4428impl<R: TreeRoot<RaTypes>> Eq for UseTreeNode<R> {}
4429impl<R: TreeRoot<RaTypes>> Hash for UseTreeNode<R> {
4430 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4431} 3243}
4432 3244
4433impl<'a> AstNode<'a> for UseTree<'a> { 3245impl AstNode for UseTree {
4434 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3246 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4435 match syntax.kind() { 3247 match syntax.kind() {
4436 USE_TREE => Some(UseTree { syntax }), 3248 USE_TREE => Some(UseTree::from_repr(syntax.into_repr())),
4437 _ => None, 3249 _ => None,
4438 } 3250 }
4439 } 3251 }
4440 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3252 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3253 fn to_owned(&self) -> TreePtr<UseTree> { TreePtr::cast(self.syntax.to_owned()) }
4441} 3254}
4442 3255
4443impl<R: TreeRoot<RaTypes>> UseTreeNode<R> {
4444 pub fn borrowed(&self) -> UseTree {
4445 UseTreeNode { syntax: self.syntax.borrowed() }
4446 }
4447 pub fn owned(&self) -> UseTreeNode {
4448 UseTreeNode { syntax: self.syntax.owned() }
4449 }
4450}
4451 3256
4452 3257impl UseTree {
4453impl<'a> UseTree<'a> { 3258 pub fn path(&self) -> Option<&Path> {
4454 pub fn path(self) -> Option<Path<'a>> {
4455 super::child_opt(self) 3259 super::child_opt(self)
4456 } 3260 }
4457 3261
4458 pub fn use_tree_list(self) -> Option<UseTreeList<'a>> { 3262 pub fn use_tree_list(&self) -> Option<&UseTreeList> {
4459 super::child_opt(self) 3263 super::child_opt(self)
4460 } 3264 }
4461} 3265}
4462 3266
4463// UseTreeList 3267// UseTreeList
4464#[derive(Debug, Clone, Copy,)] 3268#[derive(Debug, PartialEq, Eq, Hash)]
4465pub struct UseTreeListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3269#[repr(transparent)]
4466 pub(crate) syntax: SyntaxNode<R>, 3270pub struct UseTreeList {
4467} 3271 pub(crate) syntax: SyntaxNode,
4468pub type UseTreeList<'a> = UseTreeListNode<RefRoot<'a>>;
4469
4470impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseTreeListNode<R1>> for UseTreeListNode<R2> {
4471 fn eq(&self, other: &UseTreeListNode<R1>) -> bool { self.syntax == other.syntax }
4472} 3272}
4473impl<R: TreeRoot<RaTypes>> Eq for UseTreeListNode<R> {} 3273unsafe impl TransparentNewType for UseTreeList {
4474impl<R: TreeRoot<RaTypes>> Hash for UseTreeListNode<R> { 3274 type Repr = rowan::SyntaxNode<RaTypes>;
4475 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4476} 3275}
4477 3276
4478impl<'a> AstNode<'a> for UseTreeList<'a> { 3277impl AstNode for UseTreeList {
4479 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3278 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4480 match syntax.kind() { 3279 match syntax.kind() {
4481 USE_TREE_LIST => Some(UseTreeList { syntax }), 3280 USE_TREE_LIST => Some(UseTreeList::from_repr(syntax.into_repr())),
4482 _ => None, 3281 _ => None,
4483 } 3282 }
4484 } 3283 }
4485 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3284 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4486} 3285 fn to_owned(&self) -> TreePtr<UseTreeList> { TreePtr::cast(self.syntax.to_owned()) }
4487
4488impl<R: TreeRoot<RaTypes>> UseTreeListNode<R> {
4489 pub fn borrowed(&self) -> UseTreeList {
4490 UseTreeListNode { syntax: self.syntax.borrowed() }
4491 }
4492 pub fn owned(&self) -> UseTreeListNode {
4493 UseTreeListNode { syntax: self.syntax.owned() }
4494 }
4495} 3286}
4496 3287
4497 3288
4498impl<'a> UseTreeList<'a> { 3289impl UseTreeList {
4499 pub fn use_trees(self) -> impl Iterator<Item = UseTree<'a>> + 'a { 3290 pub fn use_trees(&self) -> impl Iterator<Item = &UseTree> {
4500 super::children(self) 3291 super::children(self)
4501 } 3292 }
4502} 3293}
4503 3294
4504// Visibility 3295// Visibility
4505#[derive(Debug, Clone, Copy,)] 3296#[derive(Debug, PartialEq, Eq, Hash)]
4506pub struct VisibilityNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3297#[repr(transparent)]
4507 pub(crate) syntax: SyntaxNode<R>, 3298pub struct Visibility {
3299 pub(crate) syntax: SyntaxNode,
4508} 3300}
4509pub type Visibility<'a> = VisibilityNode<RefRoot<'a>>; 3301unsafe impl TransparentNewType for Visibility {
4510 3302 type Repr = rowan::SyntaxNode<RaTypes>;
4511impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<VisibilityNode<R1>> for VisibilityNode<R2> {
4512 fn eq(&self, other: &VisibilityNode<R1>) -> bool { self.syntax == other.syntax }
4513}
4514impl<R: TreeRoot<RaTypes>> Eq for VisibilityNode<R> {}
4515impl<R: TreeRoot<RaTypes>> Hash for VisibilityNode<R> {
4516 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4517} 3303}
4518 3304
4519impl<'a> AstNode<'a> for Visibility<'a> { 3305impl AstNode for Visibility {
4520 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3306 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4521 match syntax.kind() { 3307 match syntax.kind() {
4522 VISIBILITY => Some(Visibility { syntax }), 3308 VISIBILITY => Some(Visibility::from_repr(syntax.into_repr())),
4523 _ => None, 3309 _ => None,
4524 } 3310 }
4525 } 3311 }
4526 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3312 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4527} 3313 fn to_owned(&self) -> TreePtr<Visibility> { TreePtr::cast(self.syntax.to_owned()) }
4528
4529impl<R: TreeRoot<RaTypes>> VisibilityNode<R> {
4530 pub fn borrowed(&self) -> Visibility {
4531 VisibilityNode { syntax: self.syntax.borrowed() }
4532 }
4533 pub fn owned(&self) -> VisibilityNode {
4534 VisibilityNode { syntax: self.syntax.owned() }
4535 }
4536} 3314}
4537 3315
4538 3316
4539impl<'a> Visibility<'a> {} 3317impl Visibility {}
4540 3318
4541// WhereClause 3319// WhereClause
4542#[derive(Debug, Clone, Copy,)] 3320#[derive(Debug, PartialEq, Eq, Hash)]
4543pub struct WhereClauseNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3321#[repr(transparent)]
4544 pub(crate) syntax: SyntaxNode<R>, 3322pub struct WhereClause {
3323 pub(crate) syntax: SyntaxNode,
4545} 3324}
4546pub type WhereClause<'a> = WhereClauseNode<RefRoot<'a>>; 3325unsafe impl TransparentNewType for WhereClause {
4547 3326 type Repr = rowan::SyntaxNode<RaTypes>;
4548impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhereClauseNode<R1>> for WhereClauseNode<R2> {
4549 fn eq(&self, other: &WhereClauseNode<R1>) -> bool { self.syntax == other.syntax }
4550}
4551impl<R: TreeRoot<RaTypes>> Eq for WhereClauseNode<R> {}
4552impl<R: TreeRoot<RaTypes>> Hash for WhereClauseNode<R> {
4553 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4554} 3327}
4555 3328
4556impl<'a> AstNode<'a> for WhereClause<'a> { 3329impl AstNode for WhereClause {
4557 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3330 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4558 match syntax.kind() { 3331 match syntax.kind() {
4559 WHERE_CLAUSE => Some(WhereClause { syntax }), 3332 WHERE_CLAUSE => Some(WhereClause::from_repr(syntax.into_repr())),
4560 _ => None, 3333 _ => None,
4561 } 3334 }
4562 } 3335 }
4563 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3336 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4564} 3337 fn to_owned(&self) -> TreePtr<WhereClause> { TreePtr::cast(self.syntax.to_owned()) }
4565
4566impl<R: TreeRoot<RaTypes>> WhereClauseNode<R> {
4567 pub fn borrowed(&self) -> WhereClause {
4568 WhereClauseNode { syntax: self.syntax.borrowed() }
4569 }
4570 pub fn owned(&self) -> WhereClauseNode {
4571 WhereClauseNode { syntax: self.syntax.owned() }
4572 }
4573} 3338}
4574 3339
4575 3340
4576impl<'a> WhereClause<'a> {} 3341impl WhereClause {}
4577 3342
4578// WhileExpr 3343// WhileExpr
4579#[derive(Debug, Clone, Copy,)] 3344#[derive(Debug, PartialEq, Eq, Hash)]
4580pub struct WhileExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3345#[repr(transparent)]
4581 pub(crate) syntax: SyntaxNode<R>, 3346pub struct WhileExpr {
4582} 3347 pub(crate) syntax: SyntaxNode,
4583pub type WhileExpr<'a> = WhileExprNode<RefRoot<'a>>;
4584
4585impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhileExprNode<R1>> for WhileExprNode<R2> {
4586 fn eq(&self, other: &WhileExprNode<R1>) -> bool { self.syntax == other.syntax }
4587} 3348}
4588impl<R: TreeRoot<RaTypes>> Eq for WhileExprNode<R> {} 3349unsafe impl TransparentNewType for WhileExpr {
4589impl<R: TreeRoot<RaTypes>> Hash for WhileExprNode<R> { 3350 type Repr = rowan::SyntaxNode<RaTypes>;
4590 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4591} 3351}
4592 3352
4593impl<'a> AstNode<'a> for WhileExpr<'a> { 3353impl AstNode for WhileExpr {
4594 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3354 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4595 match syntax.kind() { 3355 match syntax.kind() {
4596 WHILE_EXPR => Some(WhileExpr { syntax }), 3356 WHILE_EXPR => Some(WhileExpr::from_repr(syntax.into_repr())),
4597 _ => None, 3357 _ => None,
4598 } 3358 }
4599 } 3359 }
4600 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3360 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3361 fn to_owned(&self) -> TreePtr<WhileExpr> { TreePtr::cast(self.syntax.to_owned()) }
4601} 3362}
4602 3363
4603impl<R: TreeRoot<RaTypes>> WhileExprNode<R> {
4604 pub fn borrowed(&self) -> WhileExpr {
4605 WhileExprNode { syntax: self.syntax.borrowed() }
4606 }
4607 pub fn owned(&self) -> WhileExprNode {
4608 WhileExprNode { syntax: self.syntax.owned() }
4609 }
4610}
4611 3364
4612 3365impl ast::LoopBodyOwner for WhileExpr {}
4613impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} 3366impl WhileExpr {
4614impl<'a> WhileExpr<'a> { 3367 pub fn condition(&self) -> Option<&Condition> {
4615 pub fn condition(self) -> Option<Condition<'a>> {
4616 super::child_opt(self) 3368 super::child_opt(self)
4617 } 3369 }
4618} 3370}
4619 3371
4620// Whitespace 3372// Whitespace
4621#[derive(Debug, Clone, Copy,)] 3373#[derive(Debug, PartialEq, Eq, Hash)]
4622pub struct WhitespaceNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3374#[repr(transparent)]
4623 pub(crate) syntax: SyntaxNode<R>, 3375pub struct Whitespace {
4624} 3376 pub(crate) syntax: SyntaxNode,
4625pub type Whitespace<'a> = WhitespaceNode<RefRoot<'a>>;
4626
4627impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhitespaceNode<R1>> for WhitespaceNode<R2> {
4628 fn eq(&self, other: &WhitespaceNode<R1>) -> bool { self.syntax == other.syntax }
4629} 3377}
4630impl<R: TreeRoot<RaTypes>> Eq for WhitespaceNode<R> {} 3378unsafe impl TransparentNewType for Whitespace {
4631impl<R: TreeRoot<RaTypes>> Hash for WhitespaceNode<R> { 3379 type Repr = rowan::SyntaxNode<RaTypes>;
4632 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
4633} 3380}
4634 3381
4635impl<'a> AstNode<'a> for Whitespace<'a> { 3382impl AstNode for Whitespace {
4636 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 3383 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
4637 match syntax.kind() { 3384 match syntax.kind() {
4638 WHITESPACE => Some(Whitespace { syntax }), 3385 WHITESPACE => Some(Whitespace::from_repr(syntax.into_repr())),
4639 _ => None, 3386 _ => None,
4640 } 3387 }
4641 } 3388 }
4642 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 3389 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4643} 3390 fn to_owned(&self) -> TreePtr<Whitespace> { TreePtr::cast(self.syntax.to_owned()) }
4644
4645impl<R: TreeRoot<RaTypes>> WhitespaceNode<R> {
4646 pub fn borrowed(&self) -> Whitespace {
4647 WhitespaceNode { syntax: self.syntax.borrowed() }
4648 }
4649 pub fn owned(&self) -> WhitespaceNode {
4650 WhitespaceNode { syntax: self.syntax.owned() }
4651 }
4652} 3391}
4653 3392
4654 3393
4655impl<'a> Whitespace<'a> {} 3394impl Whitespace {}
4656 3395