aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs2596
-rw-r--r--crates/ra_syntax/src/ast/generated.rs.tera101
-rw-r--r--crates/ra_syntax/src/grammar.ron160
3 files changed, 1488 insertions, 1369 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index f322e1d84..016668380 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1,25 +1,14 @@
1// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run 1// Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`
2// Do not edit manually
3
4//! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes
5//! are generic over ownership: `X<'a>` things are `Copy` references, `XNode`
6//! are Arc-based. You can switch between the two variants using `.owned` and
7//! `.borrowed` functions. Most of the code works with borowed mode, and only
8//! this mode has all AST accessors.
9
10#![cfg_attr(rustfmt, rustfmt_skip)]
11 2
12use crate::{ 3use crate::{
13 SyntaxNode, SyntaxKind::{self, *}, 4 ast::{self, AstChildren, AstNode},
14 ast::{self, AstNode}, 5 SyntaxKind::{self, *},
6 SyntaxNode,
15}; 7};
16
17// Alias
18#[derive(Debug, Clone, PartialEq, Eq, Hash)] 8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
19pub struct Alias { 9pub struct Alias {
20 pub(crate) syntax: SyntaxNode, 10 pub(crate) syntax: SyntaxNode,
21} 11}
22
23impl AstNode for Alias { 12impl AstNode for Alias {
24 fn can_cast(kind: SyntaxKind) -> bool { 13 fn can_cast(kind: SyntaxKind) -> bool {
25 match kind { 14 match kind {
@@ -28,21 +17,22 @@ impl AstNode for Alias {
28 } 17 }
29 } 18 }
30 fn cast(syntax: SyntaxNode) -> Option<Self> { 19 fn cast(syntax: SyntaxNode) -> Option<Self> {
31 if Self::can_cast(syntax.kind()) { Some(Alias { syntax }) } else { None } 20 if Self::can_cast(syntax.kind()) {
21 Some(Self { syntax })
22 } else {
23 None
24 }
25 }
26 fn syntax(&self) -> &SyntaxNode {
27 &self.syntax
32 } 28 }
33 fn syntax(&self) -> &SyntaxNode { &self.syntax }
34} 29}
35
36
37impl ast::NameOwner for Alias {} 30impl ast::NameOwner for Alias {}
38impl Alias {} 31impl Alias {}
39
40// ArgList
41#[derive(Debug, Clone, PartialEq, Eq, Hash)] 32#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub struct ArgList { 33pub struct ArgList {
43 pub(crate) syntax: SyntaxNode, 34 pub(crate) syntax: SyntaxNode,
44} 35}
45
46impl AstNode for ArgList { 36impl AstNode for ArgList {
47 fn can_cast(kind: SyntaxKind) -> bool { 37 fn can_cast(kind: SyntaxKind) -> bool {
48 match kind { 38 match kind {
@@ -51,24 +41,25 @@ impl AstNode for ArgList {
51 } 41 }
52 } 42 }
53 fn cast(syntax: SyntaxNode) -> Option<Self> { 43 fn cast(syntax: SyntaxNode) -> Option<Self> {
54 if Self::can_cast(syntax.kind()) { Some(ArgList { syntax }) } else { None } 44 if Self::can_cast(syntax.kind()) {
45 Some(Self { syntax })
46 } else {
47 None
48 }
49 }
50 fn syntax(&self) -> &SyntaxNode {
51 &self.syntax
55 } 52 }
56 fn syntax(&self) -> &SyntaxNode { &self.syntax }
57} 53}
58
59
60impl ArgList { 54impl ArgList {
61 pub fn args(&self) -> impl Iterator<Item = Expr> { 55 pub fn args(&self) -> AstChildren<Expr> {
62 super::children(self) 56 AstChildren::new(&self.syntax)
63 } 57 }
64} 58}
65
66// ArrayExpr
67#[derive(Debug, Clone, PartialEq, Eq, Hash)] 59#[derive(Debug, Clone, PartialEq, Eq, Hash)]
68pub struct ArrayExpr { 60pub struct ArrayExpr {
69 pub(crate) syntax: SyntaxNode, 61 pub(crate) syntax: SyntaxNode,
70} 62}
71
72impl AstNode for ArrayExpr { 63impl AstNode for ArrayExpr {
73 fn can_cast(kind: SyntaxKind) -> bool { 64 fn can_cast(kind: SyntaxKind) -> bool {
74 match kind { 65 match kind {
@@ -77,24 +68,25 @@ impl AstNode for ArrayExpr {
77 } 68 }
78 } 69 }
79 fn cast(syntax: SyntaxNode) -> Option<Self> { 70 fn cast(syntax: SyntaxNode) -> Option<Self> {
80 if Self::can_cast(syntax.kind()) { Some(ArrayExpr { syntax }) } else { None } 71 if Self::can_cast(syntax.kind()) {
72 Some(Self { syntax })
73 } else {
74 None
75 }
76 }
77 fn syntax(&self) -> &SyntaxNode {
78 &self.syntax
81 } 79 }
82 fn syntax(&self) -> &SyntaxNode { &self.syntax }
83} 80}
84
85
86impl ArrayExpr { 81impl ArrayExpr {
87 pub fn exprs(&self) -> impl Iterator<Item = Expr> { 82 pub fn exprs(&self) -> AstChildren<Expr> {
88 super::children(self) 83 AstChildren::new(&self.syntax)
89 } 84 }
90} 85}
91
92// ArrayType
93#[derive(Debug, Clone, PartialEq, Eq, Hash)] 86#[derive(Debug, Clone, PartialEq, Eq, Hash)]
94pub struct ArrayType { 87pub struct ArrayType {
95 pub(crate) syntax: SyntaxNode, 88 pub(crate) syntax: SyntaxNode,
96} 89}
97
98impl AstNode for ArrayType { 90impl AstNode for ArrayType {
99 fn can_cast(kind: SyntaxKind) -> bool { 91 fn can_cast(kind: SyntaxKind) -> bool {
100 match kind { 92 match kind {
@@ -103,28 +95,28 @@ impl AstNode for ArrayType {
103 } 95 }
104 } 96 }
105 fn cast(syntax: SyntaxNode) -> Option<Self> { 97 fn cast(syntax: SyntaxNode) -> Option<Self> {
106 if Self::can_cast(syntax.kind()) { Some(ArrayType { syntax }) } else { None } 98 if Self::can_cast(syntax.kind()) {
99 Some(Self { syntax })
100 } else {
101 None
102 }
103 }
104 fn syntax(&self) -> &SyntaxNode {
105 &self.syntax
107 } 106 }
108 fn syntax(&self) -> &SyntaxNode { &self.syntax }
109} 107}
110
111
112impl ArrayType { 108impl ArrayType {
113 pub fn type_ref(&self) -> Option<TypeRef> { 109 pub fn type_ref(&self) -> Option<TypeRef> {
114 super::child_opt(self) 110 AstChildren::new(&self.syntax).next()
115 } 111 }
116
117 pub fn expr(&self) -> Option<Expr> { 112 pub fn expr(&self) -> Option<Expr> {
118 super::child_opt(self) 113 AstChildren::new(&self.syntax).next()
119 } 114 }
120} 115}
121
122// AssocTypeArg
123#[derive(Debug, Clone, PartialEq, Eq, Hash)] 116#[derive(Debug, Clone, PartialEq, Eq, Hash)]
124pub struct AssocTypeArg { 117pub struct AssocTypeArg {
125 pub(crate) syntax: SyntaxNode, 118 pub(crate) syntax: SyntaxNode,
126} 119}
127
128impl AstNode for AssocTypeArg { 120impl AstNode for AssocTypeArg {
129 fn can_cast(kind: SyntaxKind) -> bool { 121 fn can_cast(kind: SyntaxKind) -> bool {
130 match kind { 122 match kind {
@@ -133,28 +125,28 @@ impl AstNode for AssocTypeArg {
133 } 125 }
134 } 126 }
135 fn cast(syntax: SyntaxNode) -> Option<Self> { 127 fn cast(syntax: SyntaxNode) -> Option<Self> {
136 if Self::can_cast(syntax.kind()) { Some(AssocTypeArg { syntax }) } else { None } 128 if Self::can_cast(syntax.kind()) {
129 Some(Self { syntax })
130 } else {
131 None
132 }
133 }
134 fn syntax(&self) -> &SyntaxNode {
135 &self.syntax
137 } 136 }
138 fn syntax(&self) -> &SyntaxNode { &self.syntax }
139} 137}
140
141
142impl AssocTypeArg { 138impl AssocTypeArg {
143 pub fn name_ref(&self) -> Option<NameRef> { 139 pub fn name_ref(&self) -> Option<NameRef> {
144 super::child_opt(self) 140 AstChildren::new(&self.syntax).next()
145 } 141 }
146
147 pub fn type_ref(&self) -> Option<TypeRef> { 142 pub fn type_ref(&self) -> Option<TypeRef> {
148 super::child_opt(self) 143 AstChildren::new(&self.syntax).next()
149 } 144 }
150} 145}
151
152// Attr
153#[derive(Debug, Clone, PartialEq, Eq, Hash)] 146#[derive(Debug, Clone, PartialEq, Eq, Hash)]
154pub struct Attr { 147pub struct Attr {
155 pub(crate) syntax: SyntaxNode, 148 pub(crate) syntax: SyntaxNode,
156} 149}
157
158impl AstNode for Attr { 150impl AstNode for Attr {
159 fn can_cast(kind: SyntaxKind) -> bool { 151 fn can_cast(kind: SyntaxKind) -> bool {
160 match kind { 152 match kind {
@@ -163,24 +155,25 @@ impl AstNode for Attr {
163 } 155 }
164 } 156 }
165 fn cast(syntax: SyntaxNode) -> Option<Self> { 157 fn cast(syntax: SyntaxNode) -> Option<Self> {
166 if Self::can_cast(syntax.kind()) { Some(Attr { syntax }) } else { None } 158 if Self::can_cast(syntax.kind()) {
159 Some(Self { syntax })
160 } else {
161 None
162 }
163 }
164 fn syntax(&self) -> &SyntaxNode {
165 &self.syntax
167 } 166 }
168 fn syntax(&self) -> &SyntaxNode { &self.syntax }
169} 167}
170
171
172impl Attr { 168impl Attr {
173 pub fn value(&self) -> Option<TokenTree> { 169 pub fn value(&self) -> Option<TokenTree> {
174 super::child_opt(self) 170 AstChildren::new(&self.syntax).next()
175 } 171 }
176} 172}
177
178// AwaitExpr
179#[derive(Debug, Clone, PartialEq, Eq, Hash)] 173#[derive(Debug, Clone, PartialEq, Eq, Hash)]
180pub struct AwaitExpr { 174pub struct AwaitExpr {
181 pub(crate) syntax: SyntaxNode, 175 pub(crate) syntax: SyntaxNode,
182} 176}
183
184impl AstNode for AwaitExpr { 177impl AstNode for AwaitExpr {
185 fn can_cast(kind: SyntaxKind) -> bool { 178 fn can_cast(kind: SyntaxKind) -> bool {
186 match kind { 179 match kind {
@@ -189,24 +182,25 @@ impl AstNode for AwaitExpr {
189 } 182 }
190 } 183 }
191 fn cast(syntax: SyntaxNode) -> Option<Self> { 184 fn cast(syntax: SyntaxNode) -> Option<Self> {
192 if Self::can_cast(syntax.kind()) { Some(AwaitExpr { syntax }) } else { None } 185 if Self::can_cast(syntax.kind()) {
186 Some(Self { syntax })
187 } else {
188 None
189 }
190 }
191 fn syntax(&self) -> &SyntaxNode {
192 &self.syntax
193 } 193 }
194 fn syntax(&self) -> &SyntaxNode { &self.syntax }
195} 194}
196
197
198impl AwaitExpr { 195impl AwaitExpr {
199 pub fn expr(&self) -> Option<Expr> { 196 pub fn expr(&self) -> Option<Expr> {
200 super::child_opt(self) 197 AstChildren::new(&self.syntax).next()
201 } 198 }
202} 199}
203
204// BinExpr
205#[derive(Debug, Clone, PartialEq, Eq, Hash)] 200#[derive(Debug, Clone, PartialEq, Eq, Hash)]
206pub struct BinExpr { 201pub struct BinExpr {
207 pub(crate) syntax: SyntaxNode, 202 pub(crate) syntax: SyntaxNode,
208} 203}
209
210impl AstNode for BinExpr { 204impl AstNode for BinExpr {
211 fn can_cast(kind: SyntaxKind) -> bool { 205 fn can_cast(kind: SyntaxKind) -> bool {
212 match kind { 206 match kind {
@@ -215,20 +209,21 @@ impl AstNode for BinExpr {
215 } 209 }
216 } 210 }
217 fn cast(syntax: SyntaxNode) -> Option<Self> { 211 fn cast(syntax: SyntaxNode) -> Option<Self> {
218 if Self::can_cast(syntax.kind()) { Some(BinExpr { syntax }) } else { None } 212 if Self::can_cast(syntax.kind()) {
213 Some(Self { syntax })
214 } else {
215 None
216 }
217 }
218 fn syntax(&self) -> &SyntaxNode {
219 &self.syntax
219 } 220 }
220 fn syntax(&self) -> &SyntaxNode { &self.syntax }
221} 221}
222
223
224impl BinExpr {} 222impl BinExpr {}
225
226// BindPat
227#[derive(Debug, Clone, PartialEq, Eq, Hash)] 223#[derive(Debug, Clone, PartialEq, Eq, Hash)]
228pub struct BindPat { 224pub struct BindPat {
229 pub(crate) syntax: SyntaxNode, 225 pub(crate) syntax: SyntaxNode,
230} 226}
231
232impl AstNode for BindPat { 227impl AstNode for BindPat {
233 fn can_cast(kind: SyntaxKind) -> bool { 228 fn can_cast(kind: SyntaxKind) -> bool {
234 match kind { 229 match kind {
@@ -237,25 +232,26 @@ impl AstNode for BindPat {
237 } 232 }
238 } 233 }
239 fn cast(syntax: SyntaxNode) -> Option<Self> { 234 fn cast(syntax: SyntaxNode) -> Option<Self> {
240 if Self::can_cast(syntax.kind()) { Some(BindPat { syntax }) } else { None } 235 if Self::can_cast(syntax.kind()) {
236 Some(Self { syntax })
237 } else {
238 None
239 }
240 }
241 fn syntax(&self) -> &SyntaxNode {
242 &self.syntax
241 } 243 }
242 fn syntax(&self) -> &SyntaxNode { &self.syntax }
243} 244}
244
245
246impl ast::NameOwner for BindPat {} 245impl ast::NameOwner for BindPat {}
247impl BindPat { 246impl BindPat {
248 pub fn pat(&self) -> Option<Pat> { 247 pub fn pat(&self) -> Option<Pat> {
249 super::child_opt(self) 248 AstChildren::new(&self.syntax).next()
250 } 249 }
251} 250}
252
253// Block
254#[derive(Debug, Clone, PartialEq, Eq, Hash)] 251#[derive(Debug, Clone, PartialEq, Eq, Hash)]
255pub struct Block { 252pub struct Block {
256 pub(crate) syntax: SyntaxNode, 253 pub(crate) syntax: SyntaxNode,
257} 254}
258
259impl AstNode for Block { 255impl AstNode for Block {
260 fn can_cast(kind: SyntaxKind) -> bool { 256 fn can_cast(kind: SyntaxKind) -> bool {
261 match kind { 257 match kind {
@@ -264,29 +260,29 @@ impl AstNode for Block {
264 } 260 }
265 } 261 }
266 fn cast(syntax: SyntaxNode) -> Option<Self> { 262 fn cast(syntax: SyntaxNode) -> Option<Self> {
267 if Self::can_cast(syntax.kind()) { Some(Block { syntax }) } else { None } 263 if Self::can_cast(syntax.kind()) {
264 Some(Self { syntax })
265 } else {
266 None
267 }
268 }
269 fn syntax(&self) -> &SyntaxNode {
270 &self.syntax
268 } 271 }
269 fn syntax(&self) -> &SyntaxNode { &self.syntax }
270} 272}
271
272
273impl ast::AttrsOwner for Block {} 273impl ast::AttrsOwner for Block {}
274impl Block { 274impl Block {
275 pub fn statements(&self) -> impl Iterator<Item = Stmt> { 275 pub fn statements(&self) -> AstChildren<Stmt> {
276 super::children(self) 276 AstChildren::new(&self.syntax)
277 } 277 }
278
279 pub fn expr(&self) -> Option<Expr> { 278 pub fn expr(&self) -> Option<Expr> {
280 super::child_opt(self) 279 AstChildren::new(&self.syntax).next()
281 } 280 }
282} 281}
283
284// BlockExpr
285#[derive(Debug, Clone, PartialEq, Eq, Hash)] 282#[derive(Debug, Clone, PartialEq, Eq, Hash)]
286pub struct BlockExpr { 283pub struct BlockExpr {
287 pub(crate) syntax: SyntaxNode, 284 pub(crate) syntax: SyntaxNode,
288} 285}
289
290impl AstNode for BlockExpr { 286impl AstNode for BlockExpr {
291 fn can_cast(kind: SyntaxKind) -> bool { 287 fn can_cast(kind: SyntaxKind) -> bool {
292 match kind { 288 match kind {
@@ -295,24 +291,25 @@ impl AstNode for BlockExpr {
295 } 291 }
296 } 292 }
297 fn cast(syntax: SyntaxNode) -> Option<Self> { 293 fn cast(syntax: SyntaxNode) -> Option<Self> {
298 if Self::can_cast(syntax.kind()) { Some(BlockExpr { syntax }) } else { None } 294 if Self::can_cast(syntax.kind()) {
295 Some(Self { syntax })
296 } else {
297 None
298 }
299 }
300 fn syntax(&self) -> &SyntaxNode {
301 &self.syntax
299 } 302 }
300 fn syntax(&self) -> &SyntaxNode { &self.syntax }
301} 303}
302
303
304impl BlockExpr { 304impl BlockExpr {
305 pub fn block(&self) -> Option<Block> { 305 pub fn block(&self) -> Option<Block> {
306 super::child_opt(self) 306 AstChildren::new(&self.syntax).next()
307 } 307 }
308} 308}
309
310// BreakExpr
311#[derive(Debug, Clone, PartialEq, Eq, Hash)] 309#[derive(Debug, Clone, PartialEq, Eq, Hash)]
312pub struct BreakExpr { 310pub struct BreakExpr {
313 pub(crate) syntax: SyntaxNode, 311 pub(crate) syntax: SyntaxNode,
314} 312}
315
316impl AstNode for BreakExpr { 313impl AstNode for BreakExpr {
317 fn can_cast(kind: SyntaxKind) -> bool { 314 fn can_cast(kind: SyntaxKind) -> bool {
318 match kind { 315 match kind {
@@ -321,24 +318,25 @@ impl AstNode for BreakExpr {
321 } 318 }
322 } 319 }
323 fn cast(syntax: SyntaxNode) -> Option<Self> { 320 fn cast(syntax: SyntaxNode) -> Option<Self> {
324 if Self::can_cast(syntax.kind()) { Some(BreakExpr { syntax }) } else { None } 321 if Self::can_cast(syntax.kind()) {
322 Some(Self { syntax })
323 } else {
324 None
325 }
326 }
327 fn syntax(&self) -> &SyntaxNode {
328 &self.syntax
325 } 329 }
326 fn syntax(&self) -> &SyntaxNode { &self.syntax }
327} 330}
328
329
330impl BreakExpr { 331impl BreakExpr {
331 pub fn expr(&self) -> Option<Expr> { 332 pub fn expr(&self) -> Option<Expr> {
332 super::child_opt(self) 333 AstChildren::new(&self.syntax).next()
333 } 334 }
334} 335}
335
336// CallExpr
337#[derive(Debug, Clone, PartialEq, Eq, Hash)] 336#[derive(Debug, Clone, PartialEq, Eq, Hash)]
338pub struct CallExpr { 337pub struct CallExpr {
339 pub(crate) syntax: SyntaxNode, 338 pub(crate) syntax: SyntaxNode,
340} 339}
341
342impl AstNode for CallExpr { 340impl AstNode for CallExpr {
343 fn can_cast(kind: SyntaxKind) -> bool { 341 fn can_cast(kind: SyntaxKind) -> bool {
344 match kind { 342 match kind {
@@ -347,25 +345,26 @@ impl AstNode for CallExpr {
347 } 345 }
348 } 346 }
349 fn cast(syntax: SyntaxNode) -> Option<Self> { 347 fn cast(syntax: SyntaxNode) -> Option<Self> {
350 if Self::can_cast(syntax.kind()) { Some(CallExpr { syntax }) } else { None } 348 if Self::can_cast(syntax.kind()) {
349 Some(Self { syntax })
350 } else {
351 None
352 }
353 }
354 fn syntax(&self) -> &SyntaxNode {
355 &self.syntax
351 } 356 }
352 fn syntax(&self) -> &SyntaxNode { &self.syntax }
353} 357}
354
355
356impl ast::ArgListOwner for CallExpr {} 358impl ast::ArgListOwner for CallExpr {}
357impl CallExpr { 359impl CallExpr {
358 pub fn expr(&self) -> Option<Expr> { 360 pub fn expr(&self) -> Option<Expr> {
359 super::child_opt(self) 361 AstChildren::new(&self.syntax).next()
360 } 362 }
361} 363}
362
363// CastExpr
364#[derive(Debug, Clone, PartialEq, Eq, Hash)] 364#[derive(Debug, Clone, PartialEq, Eq, Hash)]
365pub struct CastExpr { 365pub struct CastExpr {
366 pub(crate) syntax: SyntaxNode, 366 pub(crate) syntax: SyntaxNode,
367} 367}
368
369impl AstNode for CastExpr { 368impl AstNode for CastExpr {
370 fn can_cast(kind: SyntaxKind) -> bool { 369 fn can_cast(kind: SyntaxKind) -> bool {
371 match kind { 370 match kind {
@@ -374,28 +373,28 @@ impl AstNode for CastExpr {
374 } 373 }
375 } 374 }
376 fn cast(syntax: SyntaxNode) -> Option<Self> { 375 fn cast(syntax: SyntaxNode) -> Option<Self> {
377 if Self::can_cast(syntax.kind()) { Some(CastExpr { syntax }) } else { None } 376 if Self::can_cast(syntax.kind()) {
377 Some(Self { syntax })
378 } else {
379 None
380 }
381 }
382 fn syntax(&self) -> &SyntaxNode {
383 &self.syntax
378 } 384 }
379 fn syntax(&self) -> &SyntaxNode { &self.syntax }
380} 385}
381
382
383impl CastExpr { 386impl CastExpr {
384 pub fn expr(&self) -> Option<Expr> { 387 pub fn expr(&self) -> Option<Expr> {
385 super::child_opt(self) 388 AstChildren::new(&self.syntax).next()
386 } 389 }
387
388 pub fn type_ref(&self) -> Option<TypeRef> { 390 pub fn type_ref(&self) -> Option<TypeRef> {
389 super::child_opt(self) 391 AstChildren::new(&self.syntax).next()
390 } 392 }
391} 393}
392
393// Condition
394#[derive(Debug, Clone, PartialEq, Eq, Hash)] 394#[derive(Debug, Clone, PartialEq, Eq, Hash)]
395pub struct Condition { 395pub struct Condition {
396 pub(crate) syntax: SyntaxNode, 396 pub(crate) syntax: SyntaxNode,
397} 397}
398
399impl AstNode for Condition { 398impl AstNode for Condition {
400 fn can_cast(kind: SyntaxKind) -> bool { 399 fn can_cast(kind: SyntaxKind) -> bool {
401 match kind { 400 match kind {
@@ -404,28 +403,28 @@ impl AstNode for Condition {
404 } 403 }
405 } 404 }
406 fn cast(syntax: SyntaxNode) -> Option<Self> { 405 fn cast(syntax: SyntaxNode) -> Option<Self> {
407 if Self::can_cast(syntax.kind()) { Some(Condition { syntax }) } else { None } 406 if Self::can_cast(syntax.kind()) {
407 Some(Self { syntax })
408 } else {
409 None
410 }
411 }
412 fn syntax(&self) -> &SyntaxNode {
413 &self.syntax
408 } 414 }
409 fn syntax(&self) -> &SyntaxNode { &self.syntax }
410} 415}
411
412
413impl Condition { 416impl Condition {
414 pub fn pat(&self) -> Option<Pat> { 417 pub fn pat(&self) -> Option<Pat> {
415 super::child_opt(self) 418 AstChildren::new(&self.syntax).next()
416 } 419 }
417
418 pub fn expr(&self) -> Option<Expr> { 420 pub fn expr(&self) -> Option<Expr> {
419 super::child_opt(self) 421 AstChildren::new(&self.syntax).next()
420 } 422 }
421} 423}
422
423// ConstDef
424#[derive(Debug, Clone, PartialEq, Eq, Hash)] 424#[derive(Debug, Clone, PartialEq, Eq, Hash)]
425pub struct ConstDef { 425pub struct ConstDef {
426 pub(crate) syntax: SyntaxNode, 426 pub(crate) syntax: SyntaxNode,
427} 427}
428
429impl AstNode for ConstDef { 428impl AstNode for ConstDef {
430 fn can_cast(kind: SyntaxKind) -> bool { 429 fn can_cast(kind: SyntaxKind) -> bool {
431 match kind { 430 match kind {
@@ -434,12 +433,16 @@ impl AstNode for ConstDef {
434 } 433 }
435 } 434 }
436 fn cast(syntax: SyntaxNode) -> Option<Self> { 435 fn cast(syntax: SyntaxNode) -> Option<Self> {
437 if Self::can_cast(syntax.kind()) { Some(ConstDef { syntax }) } else { None } 436 if Self::can_cast(syntax.kind()) {
437 Some(Self { syntax })
438 } else {
439 None
440 }
441 }
442 fn syntax(&self) -> &SyntaxNode {
443 &self.syntax
438 } 444 }
439 fn syntax(&self) -> &SyntaxNode { &self.syntax }
440} 445}
441
442
443impl ast::VisibilityOwner for ConstDef {} 446impl ast::VisibilityOwner for ConstDef {}
444impl ast::NameOwner for ConstDef {} 447impl ast::NameOwner for ConstDef {}
445impl ast::TypeParamsOwner for ConstDef {} 448impl ast::TypeParamsOwner for ConstDef {}
@@ -448,16 +451,13 @@ impl ast::DocCommentsOwner for ConstDef {}
448impl ast::TypeAscriptionOwner for ConstDef {} 451impl ast::TypeAscriptionOwner for ConstDef {}
449impl ConstDef { 452impl ConstDef {
450 pub fn body(&self) -> Option<Expr> { 453 pub fn body(&self) -> Option<Expr> {
451 super::child_opt(self) 454 AstChildren::new(&self.syntax).next()
452 } 455 }
453} 456}
454
455// ContinueExpr
456#[derive(Debug, Clone, PartialEq, Eq, Hash)] 457#[derive(Debug, Clone, PartialEq, Eq, Hash)]
457pub struct ContinueExpr { 458pub struct ContinueExpr {
458 pub(crate) syntax: SyntaxNode, 459 pub(crate) syntax: SyntaxNode,
459} 460}
460
461impl AstNode for ContinueExpr { 461impl AstNode for ContinueExpr {
462 fn can_cast(kind: SyntaxKind) -> bool { 462 fn can_cast(kind: SyntaxKind) -> bool {
463 match kind { 463 match kind {
@@ -466,20 +466,21 @@ impl AstNode for ContinueExpr {
466 } 466 }
467 } 467 }
468 fn cast(syntax: SyntaxNode) -> Option<Self> { 468 fn cast(syntax: SyntaxNode) -> Option<Self> {
469 if Self::can_cast(syntax.kind()) { Some(ContinueExpr { syntax }) } else { None } 469 if Self::can_cast(syntax.kind()) {
470 Some(Self { syntax })
471 } else {
472 None
473 }
474 }
475 fn syntax(&self) -> &SyntaxNode {
476 &self.syntax
470 } 477 }
471 fn syntax(&self) -> &SyntaxNode { &self.syntax }
472} 478}
473
474
475impl ContinueExpr {} 479impl ContinueExpr {}
476
477// DynTraitType
478#[derive(Debug, Clone, PartialEq, Eq, Hash)] 480#[derive(Debug, Clone, PartialEq, Eq, Hash)]
479pub struct DynTraitType { 481pub struct DynTraitType {
480 pub(crate) syntax: SyntaxNode, 482 pub(crate) syntax: SyntaxNode,
481} 483}
482
483impl AstNode for DynTraitType { 484impl AstNode for DynTraitType {
484 fn can_cast(kind: SyntaxKind) -> bool { 485 fn can_cast(kind: SyntaxKind) -> bool {
485 match kind { 486 match kind {
@@ -488,21 +489,22 @@ impl AstNode for DynTraitType {
488 } 489 }
489 } 490 }
490 fn cast(syntax: SyntaxNode) -> Option<Self> { 491 fn cast(syntax: SyntaxNode) -> Option<Self> {
491 if Self::can_cast(syntax.kind()) { Some(DynTraitType { syntax }) } else { None } 492 if Self::can_cast(syntax.kind()) {
493 Some(Self { syntax })
494 } else {
495 None
496 }
497 }
498 fn syntax(&self) -> &SyntaxNode {
499 &self.syntax
492 } 500 }
493 fn syntax(&self) -> &SyntaxNode { &self.syntax }
494} 501}
495
496
497impl ast::TypeBoundsOwner for DynTraitType {} 502impl ast::TypeBoundsOwner for DynTraitType {}
498impl DynTraitType {} 503impl DynTraitType {}
499
500// EnumDef
501#[derive(Debug, Clone, PartialEq, Eq, Hash)] 504#[derive(Debug, Clone, PartialEq, Eq, Hash)]
502pub struct EnumDef { 505pub struct EnumDef {
503 pub(crate) syntax: SyntaxNode, 506 pub(crate) syntax: SyntaxNode,
504} 507}
505
506impl AstNode for EnumDef { 508impl AstNode for EnumDef {
507 fn can_cast(kind: SyntaxKind) -> bool { 509 fn can_cast(kind: SyntaxKind) -> bool {
508 match kind { 510 match kind {
@@ -511,12 +513,16 @@ impl AstNode for EnumDef {
511 } 513 }
512 } 514 }
513 fn cast(syntax: SyntaxNode) -> Option<Self> { 515 fn cast(syntax: SyntaxNode) -> Option<Self> {
514 if Self::can_cast(syntax.kind()) { Some(EnumDef { syntax }) } else { None } 516 if Self::can_cast(syntax.kind()) {
517 Some(Self { syntax })
518 } else {
519 None
520 }
521 }
522 fn syntax(&self) -> &SyntaxNode {
523 &self.syntax
515 } 524 }
516 fn syntax(&self) -> &SyntaxNode { &self.syntax }
517} 525}
518
519
520impl ast::VisibilityOwner for EnumDef {} 526impl ast::VisibilityOwner for EnumDef {}
521impl ast::NameOwner for EnumDef {} 527impl ast::NameOwner for EnumDef {}
522impl ast::TypeParamsOwner for EnumDef {} 528impl ast::TypeParamsOwner for EnumDef {}
@@ -524,16 +530,13 @@ impl ast::AttrsOwner for EnumDef {}
524impl ast::DocCommentsOwner for EnumDef {} 530impl ast::DocCommentsOwner for EnumDef {}
525impl EnumDef { 531impl EnumDef {
526 pub fn variant_list(&self) -> Option<EnumVariantList> { 532 pub fn variant_list(&self) -> Option<EnumVariantList> {
527 super::child_opt(self) 533 AstChildren::new(&self.syntax).next()
528 } 534 }
529} 535}
530
531// EnumVariant
532#[derive(Debug, Clone, PartialEq, Eq, Hash)] 536#[derive(Debug, Clone, PartialEq, Eq, Hash)]
533pub struct EnumVariant { 537pub struct EnumVariant {
534 pub(crate) syntax: SyntaxNode, 538 pub(crate) syntax: SyntaxNode,
535} 539}
536
537impl AstNode for EnumVariant { 540impl AstNode for EnumVariant {
538 fn can_cast(kind: SyntaxKind) -> bool { 541 fn can_cast(kind: SyntaxKind) -> bool {
539 match kind { 542 match kind {
@@ -542,27 +545,28 @@ impl AstNode for EnumVariant {
542 } 545 }
543 } 546 }
544 fn cast(syntax: SyntaxNode) -> Option<Self> { 547 fn cast(syntax: SyntaxNode) -> Option<Self> {
545 if Self::can_cast(syntax.kind()) { Some(EnumVariant { syntax }) } else { None } 548 if Self::can_cast(syntax.kind()) {
549 Some(Self { syntax })
550 } else {
551 None
552 }
553 }
554 fn syntax(&self) -> &SyntaxNode {
555 &self.syntax
546 } 556 }
547 fn syntax(&self) -> &SyntaxNode { &self.syntax }
548} 557}
549
550
551impl ast::NameOwner for EnumVariant {} 558impl ast::NameOwner for EnumVariant {}
552impl ast::DocCommentsOwner for EnumVariant {} 559impl ast::DocCommentsOwner for EnumVariant {}
553impl ast::AttrsOwner for EnumVariant {} 560impl ast::AttrsOwner for EnumVariant {}
554impl EnumVariant { 561impl EnumVariant {
555 pub fn expr(&self) -> Option<Expr> { 562 pub fn expr(&self) -> Option<Expr> {
556 super::child_opt(self) 563 AstChildren::new(&self.syntax).next()
557 } 564 }
558} 565}
559
560// EnumVariantList
561#[derive(Debug, Clone, PartialEq, Eq, Hash)] 566#[derive(Debug, Clone, PartialEq, Eq, Hash)]
562pub struct EnumVariantList { 567pub struct EnumVariantList {
563 pub(crate) syntax: SyntaxNode, 568 pub(crate) syntax: SyntaxNode,
564} 569}
565
566impl AstNode for EnumVariantList { 570impl AstNode for EnumVariantList {
567 fn can_cast(kind: SyntaxKind) -> bool { 571 fn can_cast(kind: SyntaxKind) -> bool {
568 match kind { 572 match kind {
@@ -571,39 +575,49 @@ impl AstNode for EnumVariantList {
571 } 575 }
572 } 576 }
573 fn cast(syntax: SyntaxNode) -> Option<Self> { 577 fn cast(syntax: SyntaxNode) -> Option<Self> {
574 if Self::can_cast(syntax.kind()) { Some(EnumVariantList { syntax }) } else { None } 578 if Self::can_cast(syntax.kind()) {
579 Some(Self { syntax })
580 } else {
581 None
582 }
583 }
584 fn syntax(&self) -> &SyntaxNode {
585 &self.syntax
575 } 586 }
576 fn syntax(&self) -> &SyntaxNode { &self.syntax }
577} 587}
578
579
580impl EnumVariantList { 588impl EnumVariantList {
581 pub fn variants(&self) -> impl Iterator<Item = EnumVariant> { 589 pub fn variants(&self) -> AstChildren<EnumVariant> {
582 super::children(self) 590 AstChildren::new(&self.syntax)
583 } 591 }
584} 592}
585
586// Expr
587#[derive(Debug, Clone, PartialEq, Eq, Hash)] 593#[derive(Debug, Clone, PartialEq, Eq, Hash)]
588pub struct Expr { 594pub struct Expr {
589 pub(crate) syntax: SyntaxNode, 595 pub(crate) syntax: SyntaxNode,
590} 596}
591
592impl AstNode for Expr { 597impl AstNode for Expr {
593 fn can_cast(kind: SyntaxKind) -> bool { 598 fn can_cast(kind: SyntaxKind) -> bool {
594 match kind { 599 match kind {
595 | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true, 600 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
601 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
602 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR
603 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
604 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => {
605 true
606 }
596 _ => false, 607 _ => false,
597 } 608 }
598 } 609 }
599 fn cast(syntax: SyntaxNode) -> Option<Self> { 610 fn cast(syntax: SyntaxNode) -> Option<Self> {
600 if Self::can_cast(syntax.kind()) { Some(Expr { syntax }) } else { None } 611 if Self::can_cast(syntax.kind()) {
612 Some(Self { syntax })
613 } else {
614 None
615 }
616 }
617 fn syntax(&self) -> &SyntaxNode {
618 &self.syntax
601 } 619 }
602 fn syntax(&self) -> &SyntaxNode { &self.syntax }
603} 620}
604
605
606#[derive(Debug, Clone, PartialEq, Eq)]
607pub enum ExprKind { 621pub enum ExprKind {
608 TupleExpr(TupleExpr), 622 TupleExpr(TupleExpr),
609 ArrayExpr(ArrayExpr), 623 ArrayExpr(ArrayExpr),
@@ -637,141 +651,198 @@ pub enum ExprKind {
637 MacroCall(MacroCall), 651 MacroCall(MacroCall),
638} 652}
639impl From<TupleExpr> for Expr { 653impl From<TupleExpr> for Expr {
640 fn from(n: TupleExpr) -> Expr { Expr { syntax: n.syntax } } 654 fn from(node: TupleExpr) -> Expr {
655 Expr { syntax: node.syntax }
656 }
641} 657}
642impl From<ArrayExpr> for Expr { 658impl From<ArrayExpr> for Expr {
643 fn from(n: ArrayExpr) -> Expr { Expr { syntax: n.syntax } } 659 fn from(node: ArrayExpr) -> Expr {
660 Expr { syntax: node.syntax }
661 }
644} 662}
645impl From<ParenExpr> for Expr { 663impl From<ParenExpr> for Expr {
646 fn from(n: ParenExpr) -> Expr { Expr { syntax: n.syntax } } 664 fn from(node: ParenExpr) -> Expr {
665 Expr { syntax: node.syntax }
666 }
647} 667}
648impl From<PathExpr> for Expr { 668impl From<PathExpr> for Expr {
649 fn from(n: PathExpr) -> Expr { Expr { syntax: n.syntax } } 669 fn from(node: PathExpr) -> Expr {
670 Expr { syntax: node.syntax }
671 }
650} 672}
651impl From<LambdaExpr> for Expr { 673impl From<LambdaExpr> for Expr {
652 fn from(n: LambdaExpr) -> Expr { Expr { syntax: n.syntax } } 674 fn from(node: LambdaExpr) -> Expr {
675 Expr { syntax: node.syntax }
676 }
653} 677}
654impl From<IfExpr> for Expr { 678impl From<IfExpr> for Expr {
655 fn from(n: IfExpr) -> Expr { Expr { syntax: n.syntax } } 679 fn from(node: IfExpr) -> Expr {
680 Expr { syntax: node.syntax }
681 }
656} 682}
657impl From<LoopExpr> for Expr { 683impl From<LoopExpr> for Expr {
658 fn from(n: LoopExpr) -> Expr { Expr { syntax: n.syntax } } 684 fn from(node: LoopExpr) -> Expr {
685 Expr { syntax: node.syntax }
686 }
659} 687}
660impl From<ForExpr> for Expr { 688impl From<ForExpr> for Expr {
661 fn from(n: ForExpr) -> Expr { Expr { syntax: n.syntax } } 689 fn from(node: ForExpr) -> Expr {
690 Expr { syntax: node.syntax }
691 }
662} 692}
663impl From<WhileExpr> for Expr { 693impl From<WhileExpr> for Expr {
664 fn from(n: WhileExpr) -> Expr { Expr { syntax: n.syntax } } 694 fn from(node: WhileExpr) -> Expr {
695 Expr { syntax: node.syntax }
696 }
665} 697}
666impl From<ContinueExpr> for Expr { 698impl From<ContinueExpr> for Expr {
667 fn from(n: ContinueExpr) -> Expr { Expr { syntax: n.syntax } } 699 fn from(node: ContinueExpr) -> Expr {
700 Expr { syntax: node.syntax }
701 }
668} 702}
669impl From<BreakExpr> for Expr { 703impl From<BreakExpr> for Expr {
670 fn from(n: BreakExpr) -> Expr { Expr { syntax: n.syntax } } 704 fn from(node: BreakExpr) -> Expr {
705 Expr { syntax: node.syntax }
706 }
671} 707}
672impl From<Label> for Expr { 708impl From<Label> for Expr {
673 fn from(n: Label) -> Expr { Expr { syntax: n.syntax } } 709 fn from(node: Label) -> Expr {
710 Expr { syntax: node.syntax }
711 }
674} 712}
675impl From<BlockExpr> for Expr { 713impl From<BlockExpr> for Expr {
676 fn from(n: BlockExpr) -> Expr { Expr { syntax: n.syntax } } 714 fn from(node: BlockExpr) -> Expr {
715 Expr { syntax: node.syntax }
716 }
677} 717}
678impl From<ReturnExpr> for Expr { 718impl From<ReturnExpr> for Expr {
679 fn from(n: ReturnExpr) -> Expr { Expr { syntax: n.syntax } } 719 fn from(node: ReturnExpr) -> Expr {
720 Expr { syntax: node.syntax }
721 }
680} 722}
681impl From<MatchExpr> for Expr { 723impl From<MatchExpr> for Expr {
682 fn from(n: MatchExpr) -> Expr { Expr { syntax: n.syntax } } 724 fn from(node: MatchExpr) -> Expr {
725 Expr { syntax: node.syntax }
726 }
683} 727}
684impl From<StructLit> for Expr { 728impl From<StructLit> for Expr {
685 fn from(n: StructLit) -> Expr { Expr { syntax: n.syntax } } 729 fn from(node: StructLit) -> Expr {
730 Expr { syntax: node.syntax }
731 }
686} 732}
687impl From<CallExpr> for Expr { 733impl From<CallExpr> for Expr {
688 fn from(n: CallExpr) -> Expr { Expr { syntax: n.syntax } } 734 fn from(node: CallExpr) -> Expr {
735 Expr { syntax: node.syntax }
736 }
689} 737}
690impl From<IndexExpr> for Expr { 738impl From<IndexExpr> for Expr {
691 fn from(n: IndexExpr) -> Expr { Expr { syntax: n.syntax } } 739 fn from(node: IndexExpr) -> Expr {
740 Expr { syntax: node.syntax }
741 }
692} 742}
693impl From<MethodCallExpr> for Expr { 743impl From<MethodCallExpr> for Expr {
694 fn from(n: MethodCallExpr) -> Expr { Expr { syntax: n.syntax } } 744 fn from(node: MethodCallExpr) -> Expr {
745 Expr { syntax: node.syntax }
746 }
695} 747}
696impl From<FieldExpr> for Expr { 748impl From<FieldExpr> for Expr {
697 fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } } 749 fn from(node: FieldExpr) -> Expr {
750 Expr { syntax: node.syntax }
751 }
698} 752}
699impl From<AwaitExpr> for Expr { 753impl From<AwaitExpr> for Expr {
700 fn from(n: AwaitExpr) -> Expr { Expr { syntax: n.syntax } } 754 fn from(node: AwaitExpr) -> Expr {
755 Expr { syntax: node.syntax }
756 }
701} 757}
702impl From<TryExpr> for Expr { 758impl From<TryExpr> for Expr {
703 fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } } 759 fn from(node: TryExpr) -> Expr {
760 Expr { syntax: node.syntax }
761 }
704} 762}
705impl From<TryBlockExpr> for Expr { 763impl From<TryBlockExpr> for Expr {
706 fn from(n: TryBlockExpr) -> Expr { Expr { syntax: n.syntax } } 764 fn from(node: TryBlockExpr) -> Expr {
765 Expr { syntax: node.syntax }
766 }
707} 767}
708impl From<CastExpr> for Expr { 768impl From<CastExpr> for Expr {
709 fn from(n: CastExpr) -> Expr { Expr { syntax: n.syntax } } 769 fn from(node: CastExpr) -> Expr {
770 Expr { syntax: node.syntax }
771 }
710} 772}
711impl From<RefExpr> for Expr { 773impl From<RefExpr> for Expr {
712 fn from(n: RefExpr) -> Expr { Expr { syntax: n.syntax } } 774 fn from(node: RefExpr) -> Expr {
775 Expr { syntax: node.syntax }
776 }
713} 777}
714impl From<PrefixExpr> for Expr { 778impl From<PrefixExpr> for Expr {
715 fn from(n: PrefixExpr) -> Expr { Expr { syntax: n.syntax } } 779 fn from(node: PrefixExpr) -> Expr {
780 Expr { syntax: node.syntax }
781 }
716} 782}
717impl From<RangeExpr> for Expr { 783impl From<RangeExpr> for Expr {
718 fn from(n: RangeExpr) -> Expr { Expr { syntax: n.syntax } } 784 fn from(node: RangeExpr) -> Expr {
785 Expr { syntax: node.syntax }
786 }
719} 787}
720impl From<BinExpr> for Expr { 788impl From<BinExpr> for Expr {
721 fn from(n: BinExpr) -> Expr { Expr { syntax: n.syntax } } 789 fn from(node: BinExpr) -> Expr {
790 Expr { syntax: node.syntax }
791 }
722} 792}
723impl From<Literal> for Expr { 793impl From<Literal> for Expr {
724 fn from(n: Literal) -> Expr { Expr { syntax: n.syntax } } 794 fn from(node: Literal) -> Expr {
795 Expr { syntax: node.syntax }
796 }
725} 797}
726impl From<MacroCall> for Expr { 798impl From<MacroCall> for Expr {
727 fn from(n: MacroCall) -> Expr { Expr { syntax: n.syntax } } 799 fn from(node: MacroCall) -> Expr {
800 Expr { syntax: node.syntax }
801 }
728} 802}
729impl Expr { 803impl Expr {
730 pub fn kind(&self) -> ExprKind { 804 pub fn kind(&self) -> ExprKind {
731 match self.syntax.kind() { 805 let syntax = self.syntax.clone();
732 TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(self.syntax.clone()).unwrap()), 806 match syntax.kind() {
733 ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(self.syntax.clone()).unwrap()), 807 TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr { syntax }),
734 PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(self.syntax.clone()).unwrap()), 808 ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr { syntax }),
735 PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(self.syntax.clone()).unwrap()), 809 PAREN_EXPR => ExprKind::ParenExpr(ParenExpr { syntax }),
736 LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(self.syntax.clone()).unwrap()), 810 PATH_EXPR => ExprKind::PathExpr(PathExpr { syntax }),
737 IF_EXPR => ExprKind::IfExpr(IfExpr::cast(self.syntax.clone()).unwrap()), 811 LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr { syntax }),
738 LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(self.syntax.clone()).unwrap()), 812 IF_EXPR => ExprKind::IfExpr(IfExpr { syntax }),
739 FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(self.syntax.clone()).unwrap()), 813 LOOP_EXPR => ExprKind::LoopExpr(LoopExpr { syntax }),
740 WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(self.syntax.clone()).unwrap()), 814 FOR_EXPR => ExprKind::ForExpr(ForExpr { syntax }),
741 CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(self.syntax.clone()).unwrap()), 815 WHILE_EXPR => ExprKind::WhileExpr(WhileExpr { syntax }),
742 BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(self.syntax.clone()).unwrap()), 816 CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr { syntax }),
743 LABEL => ExprKind::Label(Label::cast(self.syntax.clone()).unwrap()), 817 BREAK_EXPR => ExprKind::BreakExpr(BreakExpr { syntax }),
744 BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(self.syntax.clone()).unwrap()), 818 LABEL => ExprKind::Label(Label { syntax }),
745 RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(self.syntax.clone()).unwrap()), 819 BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr { syntax }),
746 MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(self.syntax.clone()).unwrap()), 820 RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr { syntax }),
747 STRUCT_LIT => ExprKind::StructLit(StructLit::cast(self.syntax.clone()).unwrap()), 821 MATCH_EXPR => ExprKind::MatchExpr(MatchExpr { syntax }),
748 CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(self.syntax.clone()).unwrap()), 822 STRUCT_LIT => ExprKind::StructLit(StructLit { syntax }),
749 INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(self.syntax.clone()).unwrap()), 823 CALL_EXPR => ExprKind::CallExpr(CallExpr { syntax }),
750 METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(self.syntax.clone()).unwrap()), 824 INDEX_EXPR => ExprKind::IndexExpr(IndexExpr { syntax }),
751 FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(self.syntax.clone()).unwrap()), 825 METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr { syntax }),
752 AWAIT_EXPR => ExprKind::AwaitExpr(AwaitExpr::cast(self.syntax.clone()).unwrap()), 826 FIELD_EXPR => ExprKind::FieldExpr(FieldExpr { syntax }),
753 TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(self.syntax.clone()).unwrap()), 827 AWAIT_EXPR => ExprKind::AwaitExpr(AwaitExpr { syntax }),
754 TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr::cast(self.syntax.clone()).unwrap()), 828 TRY_EXPR => ExprKind::TryExpr(TryExpr { syntax }),
755 CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(self.syntax.clone()).unwrap()), 829 TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr { syntax }),
756 REF_EXPR => ExprKind::RefExpr(RefExpr::cast(self.syntax.clone()).unwrap()), 830 CAST_EXPR => ExprKind::CastExpr(CastExpr { syntax }),
757 PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(self.syntax.clone()).unwrap()), 831 REF_EXPR => ExprKind::RefExpr(RefExpr { syntax }),
758 RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(self.syntax.clone()).unwrap()), 832 PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr { syntax }),
759 BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(self.syntax.clone()).unwrap()), 833 RANGE_EXPR => ExprKind::RangeExpr(RangeExpr { syntax }),
760 LITERAL => ExprKind::Literal(Literal::cast(self.syntax.clone()).unwrap()), 834 BIN_EXPR => ExprKind::BinExpr(BinExpr { syntax }),
761 MACRO_CALL => ExprKind::MacroCall(MacroCall::cast(self.syntax.clone()).unwrap()), 835 LITERAL => ExprKind::Literal(Literal { syntax }),
836 MACRO_CALL => ExprKind::MacroCall(MacroCall { syntax }),
762 _ => unreachable!(), 837 _ => unreachable!(),
763 } 838 }
764 } 839 }
765} 840}
766
767impl Expr {} 841impl Expr {}
768
769// ExprStmt
770#[derive(Debug, Clone, PartialEq, Eq, Hash)] 842#[derive(Debug, Clone, PartialEq, Eq, Hash)]
771pub struct ExprStmt { 843pub struct ExprStmt {
772 pub(crate) syntax: SyntaxNode, 844 pub(crate) syntax: SyntaxNode,
773} 845}
774
775impl AstNode for ExprStmt { 846impl AstNode for ExprStmt {
776 fn can_cast(kind: SyntaxKind) -> bool { 847 fn can_cast(kind: SyntaxKind) -> bool {
777 match kind { 848 match kind {
@@ -780,24 +851,25 @@ impl AstNode for ExprStmt {
780 } 851 }
781 } 852 }
782 fn cast(syntax: SyntaxNode) -> Option<Self> { 853 fn cast(syntax: SyntaxNode) -> Option<Self> {
783 if Self::can_cast(syntax.kind()) { Some(ExprStmt { syntax }) } else { None } 854 if Self::can_cast(syntax.kind()) {
855 Some(Self { syntax })
856 } else {
857 None
858 }
859 }
860 fn syntax(&self) -> &SyntaxNode {
861 &self.syntax
784 } 862 }
785 fn syntax(&self) -> &SyntaxNode { &self.syntax }
786} 863}
787
788
789impl ExprStmt { 864impl ExprStmt {
790 pub fn expr(&self) -> Option<Expr> { 865 pub fn expr(&self) -> Option<Expr> {
791 super::child_opt(self) 866 AstChildren::new(&self.syntax).next()
792 } 867 }
793} 868}
794
795// ExternCrateItem
796#[derive(Debug, Clone, PartialEq, Eq, Hash)] 869#[derive(Debug, Clone, PartialEq, Eq, Hash)]
797pub struct ExternCrateItem { 870pub struct ExternCrateItem {
798 pub(crate) syntax: SyntaxNode, 871 pub(crate) syntax: SyntaxNode,
799} 872}
800
801impl AstNode for ExternCrateItem { 873impl AstNode for ExternCrateItem {
802 fn can_cast(kind: SyntaxKind) -> bool { 874 fn can_cast(kind: SyntaxKind) -> bool {
803 match kind { 875 match kind {
@@ -806,28 +878,28 @@ impl AstNode for ExternCrateItem {
806 } 878 }
807 } 879 }
808 fn cast(syntax: SyntaxNode) -> Option<Self> { 880 fn cast(syntax: SyntaxNode) -> Option<Self> {
809 if Self::can_cast(syntax.kind()) { Some(ExternCrateItem { syntax }) } else { None } 881 if Self::can_cast(syntax.kind()) {
882 Some(Self { syntax })
883 } else {
884 None
885 }
886 }
887 fn syntax(&self) -> &SyntaxNode {
888 &self.syntax
810 } 889 }
811 fn syntax(&self) -> &SyntaxNode { &self.syntax }
812} 890}
813
814
815impl ExternCrateItem { 891impl ExternCrateItem {
816 pub fn name_ref(&self) -> Option<NameRef> { 892 pub fn name_ref(&self) -> Option<NameRef> {
817 super::child_opt(self) 893 AstChildren::new(&self.syntax).next()
818 } 894 }
819
820 pub fn alias(&self) -> Option<Alias> { 895 pub fn alias(&self) -> Option<Alias> {
821 super::child_opt(self) 896 AstChildren::new(&self.syntax).next()
822 } 897 }
823} 898}
824
825// FieldExpr
826#[derive(Debug, Clone, PartialEq, Eq, Hash)] 899#[derive(Debug, Clone, PartialEq, Eq, Hash)]
827pub struct FieldExpr { 900pub struct FieldExpr {
828 pub(crate) syntax: SyntaxNode, 901 pub(crate) syntax: SyntaxNode,
829} 902}
830
831impl AstNode for FieldExpr { 903impl AstNode for FieldExpr {
832 fn can_cast(kind: SyntaxKind) -> bool { 904 fn can_cast(kind: SyntaxKind) -> bool {
833 match kind { 905 match kind {
@@ -836,28 +908,28 @@ impl AstNode for FieldExpr {
836 } 908 }
837 } 909 }
838 fn cast(syntax: SyntaxNode) -> Option<Self> { 910 fn cast(syntax: SyntaxNode) -> Option<Self> {
839 if Self::can_cast(syntax.kind()) { Some(FieldExpr { syntax }) } else { None } 911 if Self::can_cast(syntax.kind()) {
912 Some(Self { syntax })
913 } else {
914 None
915 }
916 }
917 fn syntax(&self) -> &SyntaxNode {
918 &self.syntax
840 } 919 }
841 fn syntax(&self) -> &SyntaxNode { &self.syntax }
842} 920}
843
844
845impl FieldExpr { 921impl FieldExpr {
846 pub fn expr(&self) -> Option<Expr> { 922 pub fn expr(&self) -> Option<Expr> {
847 super::child_opt(self) 923 AstChildren::new(&self.syntax).next()
848 } 924 }
849
850 pub fn name_ref(&self) -> Option<NameRef> { 925 pub fn name_ref(&self) -> Option<NameRef> {
851 super::child_opt(self) 926 AstChildren::new(&self.syntax).next()
852 } 927 }
853} 928}
854
855// FieldPat
856#[derive(Debug, Clone, PartialEq, Eq, Hash)] 929#[derive(Debug, Clone, PartialEq, Eq, Hash)]
857pub struct FieldPat { 930pub struct FieldPat {
858 pub(crate) syntax: SyntaxNode, 931 pub(crate) syntax: SyntaxNode,
859} 932}
860
861impl AstNode for FieldPat { 933impl AstNode for FieldPat {
862 fn can_cast(kind: SyntaxKind) -> bool { 934 fn can_cast(kind: SyntaxKind) -> bool {
863 match kind { 935 match kind {
@@ -866,25 +938,26 @@ impl AstNode for FieldPat {
866 } 938 }
867 } 939 }
868 fn cast(syntax: SyntaxNode) -> Option<Self> { 940 fn cast(syntax: SyntaxNode) -> Option<Self> {
869 if Self::can_cast(syntax.kind()) { Some(FieldPat { syntax }) } else { None } 941 if Self::can_cast(syntax.kind()) {
942 Some(Self { syntax })
943 } else {
944 None
945 }
946 }
947 fn syntax(&self) -> &SyntaxNode {
948 &self.syntax
870 } 949 }
871 fn syntax(&self) -> &SyntaxNode { &self.syntax }
872} 950}
873
874
875impl ast::NameOwner for FieldPat {} 951impl ast::NameOwner for FieldPat {}
876impl FieldPat { 952impl FieldPat {
877 pub fn pat(&self) -> Option<Pat> { 953 pub fn pat(&self) -> Option<Pat> {
878 super::child_opt(self) 954 AstChildren::new(&self.syntax).next()
879 } 955 }
880} 956}
881
882// FieldPatList
883#[derive(Debug, Clone, PartialEq, Eq, Hash)] 957#[derive(Debug, Clone, PartialEq, Eq, Hash)]
884pub struct FieldPatList { 958pub struct FieldPatList {
885 pub(crate) syntax: SyntaxNode, 959 pub(crate) syntax: SyntaxNode,
886} 960}
887
888impl AstNode for FieldPatList { 961impl AstNode for FieldPatList {
889 fn can_cast(kind: SyntaxKind) -> bool { 962 fn can_cast(kind: SyntaxKind) -> bool {
890 match kind { 963 match kind {
@@ -893,28 +966,28 @@ impl AstNode for FieldPatList {
893 } 966 }
894 } 967 }
895 fn cast(syntax: SyntaxNode) -> Option<Self> { 968 fn cast(syntax: SyntaxNode) -> Option<Self> {
896 if Self::can_cast(syntax.kind()) { Some(FieldPatList { syntax }) } else { None } 969 if Self::can_cast(syntax.kind()) {
970 Some(Self { syntax })
971 } else {
972 None
973 }
974 }
975 fn syntax(&self) -> &SyntaxNode {
976 &self.syntax
897 } 977 }
898 fn syntax(&self) -> &SyntaxNode { &self.syntax }
899} 978}
900
901
902impl FieldPatList { 979impl FieldPatList {
903 pub fn field_pats(&self) -> impl Iterator<Item = FieldPat> { 980 pub fn field_pats(&self) -> AstChildren<FieldPat> {
904 super::children(self) 981 AstChildren::new(&self.syntax)
905 } 982 }
906 983 pub fn bind_pats(&self) -> AstChildren<BindPat> {
907 pub fn bind_pats(&self) -> impl Iterator<Item = BindPat> { 984 AstChildren::new(&self.syntax)
908 super::children(self)
909 } 985 }
910} 986}
911
912// FnDef
913#[derive(Debug, Clone, PartialEq, Eq, Hash)] 987#[derive(Debug, Clone, PartialEq, Eq, Hash)]
914pub struct FnDef { 988pub struct FnDef {
915 pub(crate) syntax: SyntaxNode, 989 pub(crate) syntax: SyntaxNode,
916} 990}
917
918impl AstNode for FnDef { 991impl AstNode for FnDef {
919 fn can_cast(kind: SyntaxKind) -> bool { 992 fn can_cast(kind: SyntaxKind) -> bool {
920 match kind { 993 match kind {
@@ -923,12 +996,16 @@ impl AstNode for FnDef {
923 } 996 }
924 } 997 }
925 fn cast(syntax: SyntaxNode) -> Option<Self> { 998 fn cast(syntax: SyntaxNode) -> Option<Self> {
926 if Self::can_cast(syntax.kind()) { Some(FnDef { syntax }) } else { None } 999 if Self::can_cast(syntax.kind()) {
1000 Some(Self { syntax })
1001 } else {
1002 None
1003 }
1004 }
1005 fn syntax(&self) -> &SyntaxNode {
1006 &self.syntax
927 } 1007 }
928 fn syntax(&self) -> &SyntaxNode { &self.syntax }
929} 1008}
930
931
932impl ast::VisibilityOwner for FnDef {} 1009impl ast::VisibilityOwner for FnDef {}
933impl ast::NameOwner for FnDef {} 1010impl ast::NameOwner for FnDef {}
934impl ast::TypeParamsOwner for FnDef {} 1011impl ast::TypeParamsOwner for FnDef {}
@@ -936,24 +1013,19 @@ impl ast::AttrsOwner for FnDef {}
936impl ast::DocCommentsOwner for FnDef {} 1013impl ast::DocCommentsOwner for FnDef {}
937impl FnDef { 1014impl FnDef {
938 pub fn param_list(&self) -> Option<ParamList> { 1015 pub fn param_list(&self) -> Option<ParamList> {
939 super::child_opt(self) 1016 AstChildren::new(&self.syntax).next()
940 } 1017 }
941
942 pub fn body(&self) -> Option<Block> { 1018 pub fn body(&self) -> Option<Block> {
943 super::child_opt(self) 1019 AstChildren::new(&self.syntax).next()
944 } 1020 }
945
946 pub fn ret_type(&self) -> Option<RetType> { 1021 pub fn ret_type(&self) -> Option<RetType> {
947 super::child_opt(self) 1022 AstChildren::new(&self.syntax).next()
948 } 1023 }
949} 1024}
950
951// FnPointerType
952#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1025#[derive(Debug, Clone, PartialEq, Eq, Hash)]
953pub struct FnPointerType { 1026pub struct FnPointerType {
954 pub(crate) syntax: SyntaxNode, 1027 pub(crate) syntax: SyntaxNode,
955} 1028}
956
957impl AstNode for FnPointerType { 1029impl AstNode for FnPointerType {
958 fn can_cast(kind: SyntaxKind) -> bool { 1030 fn can_cast(kind: SyntaxKind) -> bool {
959 match kind { 1031 match kind {
@@ -962,28 +1034,28 @@ impl AstNode for FnPointerType {
962 } 1034 }
963 } 1035 }
964 fn cast(syntax: SyntaxNode) -> Option<Self> { 1036 fn cast(syntax: SyntaxNode) -> Option<Self> {
965 if Self::can_cast(syntax.kind()) { Some(FnPointerType { syntax }) } else { None } 1037 if Self::can_cast(syntax.kind()) {
1038 Some(Self { syntax })
1039 } else {
1040 None
1041 }
1042 }
1043 fn syntax(&self) -> &SyntaxNode {
1044 &self.syntax
966 } 1045 }
967 fn syntax(&self) -> &SyntaxNode { &self.syntax }
968} 1046}
969
970
971impl FnPointerType { 1047impl FnPointerType {
972 pub fn param_list(&self) -> Option<ParamList> { 1048 pub fn param_list(&self) -> Option<ParamList> {
973 super::child_opt(self) 1049 AstChildren::new(&self.syntax).next()
974 } 1050 }
975
976 pub fn ret_type(&self) -> Option<RetType> { 1051 pub fn ret_type(&self) -> Option<RetType> {
977 super::child_opt(self) 1052 AstChildren::new(&self.syntax).next()
978 } 1053 }
979} 1054}
980
981// ForExpr
982#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1055#[derive(Debug, Clone, PartialEq, Eq, Hash)]
983pub struct ForExpr { 1056pub struct ForExpr {
984 pub(crate) syntax: SyntaxNode, 1057 pub(crate) syntax: SyntaxNode,
985} 1058}
986
987impl AstNode for ForExpr { 1059impl AstNode for ForExpr {
988 fn can_cast(kind: SyntaxKind) -> bool { 1060 fn can_cast(kind: SyntaxKind) -> bool {
989 match kind { 1061 match kind {
@@ -992,29 +1064,29 @@ impl AstNode for ForExpr {
992 } 1064 }
993 } 1065 }
994 fn cast(syntax: SyntaxNode) -> Option<Self> { 1066 fn cast(syntax: SyntaxNode) -> Option<Self> {
995 if Self::can_cast(syntax.kind()) { Some(ForExpr { syntax }) } else { None } 1067 if Self::can_cast(syntax.kind()) {
1068 Some(Self { syntax })
1069 } else {
1070 None
1071 }
1072 }
1073 fn syntax(&self) -> &SyntaxNode {
1074 &self.syntax
996 } 1075 }
997 fn syntax(&self) -> &SyntaxNode { &self.syntax }
998} 1076}
999
1000
1001impl ast::LoopBodyOwner for ForExpr {} 1077impl ast::LoopBodyOwner for ForExpr {}
1002impl ForExpr { 1078impl ForExpr {
1003 pub fn pat(&self) -> Option<Pat> { 1079 pub fn pat(&self) -> Option<Pat> {
1004 super::child_opt(self) 1080 AstChildren::new(&self.syntax).next()
1005 } 1081 }
1006
1007 pub fn iterable(&self) -> Option<Expr> { 1082 pub fn iterable(&self) -> Option<Expr> {
1008 super::child_opt(self) 1083 AstChildren::new(&self.syntax).next()
1009 } 1084 }
1010} 1085}
1011
1012// ForType
1013#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1086#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1014pub struct ForType { 1087pub struct ForType {
1015 pub(crate) syntax: SyntaxNode, 1088 pub(crate) syntax: SyntaxNode,
1016} 1089}
1017
1018impl AstNode for ForType { 1090impl AstNode for ForType {
1019 fn can_cast(kind: SyntaxKind) -> bool { 1091 fn can_cast(kind: SyntaxKind) -> bool {
1020 match kind { 1092 match kind {
@@ -1023,24 +1095,25 @@ impl AstNode for ForType {
1023 } 1095 }
1024 } 1096 }
1025 fn cast(syntax: SyntaxNode) -> Option<Self> { 1097 fn cast(syntax: SyntaxNode) -> Option<Self> {
1026 if Self::can_cast(syntax.kind()) { Some(ForType { syntax }) } else { None } 1098 if Self::can_cast(syntax.kind()) {
1099 Some(Self { syntax })
1100 } else {
1101 None
1102 }
1103 }
1104 fn syntax(&self) -> &SyntaxNode {
1105 &self.syntax
1027 } 1106 }
1028 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1029} 1107}
1030
1031
1032impl ForType { 1108impl ForType {
1033 pub fn type_ref(&self) -> Option<TypeRef> { 1109 pub fn type_ref(&self) -> Option<TypeRef> {
1034 super::child_opt(self) 1110 AstChildren::new(&self.syntax).next()
1035 } 1111 }
1036} 1112}
1037
1038// IfExpr
1039#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1113#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1040pub struct IfExpr { 1114pub struct IfExpr {
1041 pub(crate) syntax: SyntaxNode, 1115 pub(crate) syntax: SyntaxNode,
1042} 1116}
1043
1044impl AstNode for IfExpr { 1117impl AstNode for IfExpr {
1045 fn can_cast(kind: SyntaxKind) -> bool { 1118 fn can_cast(kind: SyntaxKind) -> bool {
1046 match kind { 1119 match kind {
@@ -1049,24 +1122,25 @@ impl AstNode for IfExpr {
1049 } 1122 }
1050 } 1123 }
1051 fn cast(syntax: SyntaxNode) -> Option<Self> { 1124 fn cast(syntax: SyntaxNode) -> Option<Self> {
1052 if Self::can_cast(syntax.kind()) { Some(IfExpr { syntax }) } else { None } 1125 if Self::can_cast(syntax.kind()) {
1126 Some(Self { syntax })
1127 } else {
1128 None
1129 }
1130 }
1131 fn syntax(&self) -> &SyntaxNode {
1132 &self.syntax
1053 } 1133 }
1054 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1055} 1134}
1056
1057
1058impl IfExpr { 1135impl IfExpr {
1059 pub fn condition(&self) -> Option<Condition> { 1136 pub fn condition(&self) -> Option<Condition> {
1060 super::child_opt(self) 1137 AstChildren::new(&self.syntax).next()
1061 } 1138 }
1062} 1139}
1063
1064// ImplBlock
1065#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1140#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1066pub struct ImplBlock { 1141pub struct ImplBlock {
1067 pub(crate) syntax: SyntaxNode, 1142 pub(crate) syntax: SyntaxNode,
1068} 1143}
1069
1070impl AstNode for ImplBlock { 1144impl AstNode for ImplBlock {
1071 fn can_cast(kind: SyntaxKind) -> bool { 1145 fn can_cast(kind: SyntaxKind) -> bool {
1072 match kind { 1146 match kind {
@@ -1075,74 +1149,81 @@ impl AstNode for ImplBlock {
1075 } 1149 }
1076 } 1150 }
1077 fn cast(syntax: SyntaxNode) -> Option<Self> { 1151 fn cast(syntax: SyntaxNode) -> Option<Self> {
1078 if Self::can_cast(syntax.kind()) { Some(ImplBlock { syntax }) } else { None } 1152 if Self::can_cast(syntax.kind()) {
1153 Some(Self { syntax })
1154 } else {
1155 None
1156 }
1157 }
1158 fn syntax(&self) -> &SyntaxNode {
1159 &self.syntax
1079 } 1160 }
1080 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1081} 1161}
1082
1083
1084impl ast::TypeParamsOwner for ImplBlock {} 1162impl ast::TypeParamsOwner for ImplBlock {}
1085impl ast::AttrsOwner for ImplBlock {} 1163impl ast::AttrsOwner for ImplBlock {}
1086impl ImplBlock { 1164impl ImplBlock {
1087 pub fn item_list(&self) -> Option<ItemList> { 1165 pub fn item_list(&self) -> Option<ItemList> {
1088 super::child_opt(self) 1166 AstChildren::new(&self.syntax).next()
1089 } 1167 }
1090} 1168}
1091
1092// ImplItem
1093#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1169#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1094pub struct ImplItem { 1170pub struct ImplItem {
1095 pub(crate) syntax: SyntaxNode, 1171 pub(crate) syntax: SyntaxNode,
1096} 1172}
1097
1098impl AstNode for ImplItem { 1173impl AstNode for ImplItem {
1099 fn can_cast(kind: SyntaxKind) -> bool { 1174 fn can_cast(kind: SyntaxKind) -> bool {
1100 match kind { 1175 match kind {
1101 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, 1176 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1102 _ => false, 1177 _ => false,
1103 } 1178 }
1104 } 1179 }
1105 fn cast(syntax: SyntaxNode) -> Option<Self> { 1180 fn cast(syntax: SyntaxNode) -> Option<Self> {
1106 if Self::can_cast(syntax.kind()) { Some(ImplItem { syntax }) } else { None } 1181 if Self::can_cast(syntax.kind()) {
1182 Some(Self { syntax })
1183 } else {
1184 None
1185 }
1186 }
1187 fn syntax(&self) -> &SyntaxNode {
1188 &self.syntax
1107 } 1189 }
1108 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1109} 1190}
1110
1111
1112#[derive(Debug, Clone, PartialEq, Eq)]
1113pub enum ImplItemKind { 1191pub enum ImplItemKind {
1114 FnDef(FnDef), 1192 FnDef(FnDef),
1115 TypeAliasDef(TypeAliasDef), 1193 TypeAliasDef(TypeAliasDef),
1116 ConstDef(ConstDef), 1194 ConstDef(ConstDef),
1117} 1195}
1118impl From<FnDef> for ImplItem { 1196impl From<FnDef> for ImplItem {
1119 fn from(n: FnDef) -> ImplItem { ImplItem { syntax: n.syntax } } 1197 fn from(node: FnDef) -> ImplItem {
1198 ImplItem { syntax: node.syntax }
1199 }
1120} 1200}
1121impl From<TypeAliasDef> for ImplItem { 1201impl From<TypeAliasDef> for ImplItem {
1122 fn from(n: TypeAliasDef) -> ImplItem { ImplItem { syntax: n.syntax } } 1202 fn from(node: TypeAliasDef) -> ImplItem {
1203 ImplItem { syntax: node.syntax }
1204 }
1123} 1205}
1124impl From<ConstDef> for ImplItem { 1206impl From<ConstDef> for ImplItem {
1125 fn from(n: ConstDef) -> ImplItem { ImplItem { syntax: n.syntax } } 1207 fn from(node: ConstDef) -> ImplItem {
1208 ImplItem { syntax: node.syntax }
1209 }
1126} 1210}
1127impl ImplItem { 1211impl ImplItem {
1128 pub fn kind(&self) -> ImplItemKind { 1212 pub fn kind(&self) -> ImplItemKind {
1129 match self.syntax.kind() { 1213 let syntax = self.syntax.clone();
1130 FN_DEF => ImplItemKind::FnDef(FnDef::cast(self.syntax.clone()).unwrap()), 1214 match syntax.kind() {
1131 TYPE_ALIAS_DEF => ImplItemKind::TypeAliasDef(TypeAliasDef::cast(self.syntax.clone()).unwrap()), 1215 FN_DEF => ImplItemKind::FnDef(FnDef { syntax }),
1132 CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(self.syntax.clone()).unwrap()), 1216 TYPE_ALIAS_DEF => ImplItemKind::TypeAliasDef(TypeAliasDef { syntax }),
1217 CONST_DEF => ImplItemKind::ConstDef(ConstDef { syntax }),
1133 _ => unreachable!(), 1218 _ => unreachable!(),
1134 } 1219 }
1135 } 1220 }
1136} 1221}
1137
1138impl ImplItem {} 1222impl ImplItem {}
1139
1140// ImplTraitType
1141#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1223#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1142pub struct ImplTraitType { 1224pub struct ImplTraitType {
1143 pub(crate) syntax: SyntaxNode, 1225 pub(crate) syntax: SyntaxNode,
1144} 1226}
1145
1146impl AstNode for ImplTraitType { 1227impl AstNode for ImplTraitType {
1147 fn can_cast(kind: SyntaxKind) -> bool { 1228 fn can_cast(kind: SyntaxKind) -> bool {
1148 match kind { 1229 match kind {
@@ -1151,21 +1232,22 @@ impl AstNode for ImplTraitType {
1151 } 1232 }
1152 } 1233 }
1153 fn cast(syntax: SyntaxNode) -> Option<Self> { 1234 fn cast(syntax: SyntaxNode) -> Option<Self> {
1154 if Self::can_cast(syntax.kind()) { Some(ImplTraitType { syntax }) } else { None } 1235 if Self::can_cast(syntax.kind()) {
1236 Some(Self { syntax })
1237 } else {
1238 None
1239 }
1240 }
1241 fn syntax(&self) -> &SyntaxNode {
1242 &self.syntax
1155 } 1243 }
1156 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1157} 1244}
1158
1159
1160impl ast::TypeBoundsOwner for ImplTraitType {} 1245impl ast::TypeBoundsOwner for ImplTraitType {}
1161impl ImplTraitType {} 1246impl ImplTraitType {}
1162
1163// IndexExpr
1164#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1247#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1165pub struct IndexExpr { 1248pub struct IndexExpr {
1166 pub(crate) syntax: SyntaxNode, 1249 pub(crate) syntax: SyntaxNode,
1167} 1250}
1168
1169impl AstNode for IndexExpr { 1251impl AstNode for IndexExpr {
1170 fn can_cast(kind: SyntaxKind) -> bool { 1252 fn can_cast(kind: SyntaxKind) -> bool {
1171 match kind { 1253 match kind {
@@ -1174,20 +1256,21 @@ impl AstNode for IndexExpr {
1174 } 1256 }
1175 } 1257 }
1176 fn cast(syntax: SyntaxNode) -> Option<Self> { 1258 fn cast(syntax: SyntaxNode) -> Option<Self> {
1177 if Self::can_cast(syntax.kind()) { Some(IndexExpr { syntax }) } else { None } 1259 if Self::can_cast(syntax.kind()) {
1260 Some(Self { syntax })
1261 } else {
1262 None
1263 }
1264 }
1265 fn syntax(&self) -> &SyntaxNode {
1266 &self.syntax
1178 } 1267 }
1179 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1180} 1268}
1181
1182
1183impl IndexExpr {} 1269impl IndexExpr {}
1184
1185// ItemList
1186#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1270#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1187pub struct ItemList { 1271pub struct ItemList {
1188 pub(crate) syntax: SyntaxNode, 1272 pub(crate) syntax: SyntaxNode,
1189} 1273}
1190
1191impl AstNode for ItemList { 1274impl AstNode for ItemList {
1192 fn can_cast(kind: SyntaxKind) -> bool { 1275 fn can_cast(kind: SyntaxKind) -> bool {
1193 match kind { 1276 match kind {
@@ -1196,26 +1279,27 @@ impl AstNode for ItemList {
1196 } 1279 }
1197 } 1280 }
1198 fn cast(syntax: SyntaxNode) -> Option<Self> { 1281 fn cast(syntax: SyntaxNode) -> Option<Self> {
1199 if Self::can_cast(syntax.kind()) { Some(ItemList { syntax }) } else { None } 1282 if Self::can_cast(syntax.kind()) {
1283 Some(Self { syntax })
1284 } else {
1285 None
1286 }
1287 }
1288 fn syntax(&self) -> &SyntaxNode {
1289 &self.syntax
1200 } 1290 }
1201 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1202} 1291}
1203
1204
1205impl ast::FnDefOwner for ItemList {} 1292impl ast::FnDefOwner for ItemList {}
1206impl ast::ModuleItemOwner for ItemList {} 1293impl ast::ModuleItemOwner for ItemList {}
1207impl ItemList { 1294impl ItemList {
1208 pub fn impl_items(&self) -> impl Iterator<Item = ImplItem> { 1295 pub fn impl_items(&self) -> AstChildren<ImplItem> {
1209 super::children(self) 1296 AstChildren::new(&self.syntax)
1210 } 1297 }
1211} 1298}
1212
1213// Label
1214#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1299#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1215pub struct Label { 1300pub struct Label {
1216 pub(crate) syntax: SyntaxNode, 1301 pub(crate) syntax: SyntaxNode,
1217} 1302}
1218
1219impl AstNode for Label { 1303impl AstNode for Label {
1220 fn can_cast(kind: SyntaxKind) -> bool { 1304 fn can_cast(kind: SyntaxKind) -> bool {
1221 match kind { 1305 match kind {
@@ -1224,20 +1308,21 @@ impl AstNode for Label {
1224 } 1308 }
1225 } 1309 }
1226 fn cast(syntax: SyntaxNode) -> Option<Self> { 1310 fn cast(syntax: SyntaxNode) -> Option<Self> {
1227 if Self::can_cast(syntax.kind()) { Some(Label { syntax }) } else { None } 1311 if Self::can_cast(syntax.kind()) {
1312 Some(Self { syntax })
1313 } else {
1314 None
1315 }
1316 }
1317 fn syntax(&self) -> &SyntaxNode {
1318 &self.syntax
1228 } 1319 }
1229 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1230} 1320}
1231
1232
1233impl Label {} 1321impl Label {}
1234
1235// LambdaExpr
1236#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1322#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1237pub struct LambdaExpr { 1323pub struct LambdaExpr {
1238 pub(crate) syntax: SyntaxNode, 1324 pub(crate) syntax: SyntaxNode,
1239} 1325}
1240
1241impl AstNode for LambdaExpr { 1326impl AstNode for LambdaExpr {
1242 fn can_cast(kind: SyntaxKind) -> bool { 1327 fn can_cast(kind: SyntaxKind) -> bool {
1243 match kind { 1328 match kind {
@@ -1246,28 +1331,28 @@ impl AstNode for LambdaExpr {
1246 } 1331 }
1247 } 1332 }
1248 fn cast(syntax: SyntaxNode) -> Option<Self> { 1333 fn cast(syntax: SyntaxNode) -> Option<Self> {
1249 if Self::can_cast(syntax.kind()) { Some(LambdaExpr { syntax }) } else { None } 1334 if Self::can_cast(syntax.kind()) {
1335 Some(Self { syntax })
1336 } else {
1337 None
1338 }
1339 }
1340 fn syntax(&self) -> &SyntaxNode {
1341 &self.syntax
1250 } 1342 }
1251 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1252} 1343}
1253
1254
1255impl LambdaExpr { 1344impl LambdaExpr {
1256 pub fn param_list(&self) -> Option<ParamList> { 1345 pub fn param_list(&self) -> Option<ParamList> {
1257 super::child_opt(self) 1346 AstChildren::new(&self.syntax).next()
1258 } 1347 }
1259
1260 pub fn body(&self) -> Option<Expr> { 1348 pub fn body(&self) -> Option<Expr> {
1261 super::child_opt(self) 1349 AstChildren::new(&self.syntax).next()
1262 } 1350 }
1263} 1351}
1264
1265// LetStmt
1266#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1352#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1267pub struct LetStmt { 1353pub struct LetStmt {
1268 pub(crate) syntax: SyntaxNode, 1354 pub(crate) syntax: SyntaxNode,
1269} 1355}
1270
1271impl AstNode for LetStmt { 1356impl AstNode for LetStmt {
1272 fn can_cast(kind: SyntaxKind) -> bool { 1357 fn can_cast(kind: SyntaxKind) -> bool {
1273 match kind { 1358 match kind {
@@ -1276,29 +1361,29 @@ impl AstNode for LetStmt {
1276 } 1361 }
1277 } 1362 }
1278 fn cast(syntax: SyntaxNode) -> Option<Self> { 1363 fn cast(syntax: SyntaxNode) -> Option<Self> {
1279 if Self::can_cast(syntax.kind()) { Some(LetStmt { syntax }) } else { None } 1364 if Self::can_cast(syntax.kind()) {
1365 Some(Self { syntax })
1366 } else {
1367 None
1368 }
1369 }
1370 fn syntax(&self) -> &SyntaxNode {
1371 &self.syntax
1280 } 1372 }
1281 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1282} 1373}
1283
1284
1285impl ast::TypeAscriptionOwner for LetStmt {} 1374impl ast::TypeAscriptionOwner for LetStmt {}
1286impl LetStmt { 1375impl LetStmt {
1287 pub fn pat(&self) -> Option<Pat> { 1376 pub fn pat(&self) -> Option<Pat> {
1288 super::child_opt(self) 1377 AstChildren::new(&self.syntax).next()
1289 } 1378 }
1290
1291 pub fn initializer(&self) -> Option<Expr> { 1379 pub fn initializer(&self) -> Option<Expr> {
1292 super::child_opt(self) 1380 AstChildren::new(&self.syntax).next()
1293 } 1381 }
1294} 1382}
1295
1296// LifetimeArg
1297#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1383#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1298pub struct LifetimeArg { 1384pub struct LifetimeArg {
1299 pub(crate) syntax: SyntaxNode, 1385 pub(crate) syntax: SyntaxNode,
1300} 1386}
1301
1302impl AstNode for LifetimeArg { 1387impl AstNode for LifetimeArg {
1303 fn can_cast(kind: SyntaxKind) -> bool { 1388 fn can_cast(kind: SyntaxKind) -> bool {
1304 match kind { 1389 match kind {
@@ -1307,20 +1392,21 @@ impl AstNode for LifetimeArg {
1307 } 1392 }
1308 } 1393 }
1309 fn cast(syntax: SyntaxNode) -> Option<Self> { 1394 fn cast(syntax: SyntaxNode) -> Option<Self> {
1310 if Self::can_cast(syntax.kind()) { Some(LifetimeArg { syntax }) } else { None } 1395 if Self::can_cast(syntax.kind()) {
1396 Some(Self { syntax })
1397 } else {
1398 None
1399 }
1400 }
1401 fn syntax(&self) -> &SyntaxNode {
1402 &self.syntax
1311 } 1403 }
1312 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1313} 1404}
1314
1315
1316impl LifetimeArg {} 1405impl LifetimeArg {}
1317
1318// LifetimeParam
1319#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1406#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1320pub struct LifetimeParam { 1407pub struct LifetimeParam {
1321 pub(crate) syntax: SyntaxNode, 1408 pub(crate) syntax: SyntaxNode,
1322} 1409}
1323
1324impl AstNode for LifetimeParam { 1410impl AstNode for LifetimeParam {
1325 fn can_cast(kind: SyntaxKind) -> bool { 1411 fn can_cast(kind: SyntaxKind) -> bool {
1326 match kind { 1412 match kind {
@@ -1329,21 +1415,22 @@ impl AstNode for LifetimeParam {
1329 } 1415 }
1330 } 1416 }
1331 fn cast(syntax: SyntaxNode) -> Option<Self> { 1417 fn cast(syntax: SyntaxNode) -> Option<Self> {
1332 if Self::can_cast(syntax.kind()) { Some(LifetimeParam { syntax }) } else { None } 1418 if Self::can_cast(syntax.kind()) {
1419 Some(Self { syntax })
1420 } else {
1421 None
1422 }
1423 }
1424 fn syntax(&self) -> &SyntaxNode {
1425 &self.syntax
1333 } 1426 }
1334 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1335} 1427}
1336
1337
1338impl ast::AttrsOwner for LifetimeParam {} 1428impl ast::AttrsOwner for LifetimeParam {}
1339impl LifetimeParam {} 1429impl LifetimeParam {}
1340
1341// Literal
1342#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1430#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1343pub struct Literal { 1431pub struct Literal {
1344 pub(crate) syntax: SyntaxNode, 1432 pub(crate) syntax: SyntaxNode,
1345} 1433}
1346
1347impl AstNode for Literal { 1434impl AstNode for Literal {
1348 fn can_cast(kind: SyntaxKind) -> bool { 1435 fn can_cast(kind: SyntaxKind) -> bool {
1349 match kind { 1436 match kind {
@@ -1352,20 +1439,21 @@ impl AstNode for Literal {
1352 } 1439 }
1353 } 1440 }
1354 fn cast(syntax: SyntaxNode) -> Option<Self> { 1441 fn cast(syntax: SyntaxNode) -> Option<Self> {
1355 if Self::can_cast(syntax.kind()) { Some(Literal { syntax }) } else { None } 1442 if Self::can_cast(syntax.kind()) {
1443 Some(Self { syntax })
1444 } else {
1445 None
1446 }
1447 }
1448 fn syntax(&self) -> &SyntaxNode {
1449 &self.syntax
1356 } 1450 }
1357 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1358} 1451}
1359
1360
1361impl Literal {} 1452impl Literal {}
1362
1363// LiteralPat
1364#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1453#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1365pub struct LiteralPat { 1454pub struct LiteralPat {
1366 pub(crate) syntax: SyntaxNode, 1455 pub(crate) syntax: SyntaxNode,
1367} 1456}
1368
1369impl AstNode for LiteralPat { 1457impl AstNode for LiteralPat {
1370 fn can_cast(kind: SyntaxKind) -> bool { 1458 fn can_cast(kind: SyntaxKind) -> bool {
1371 match kind { 1459 match kind {
@@ -1374,24 +1462,25 @@ impl AstNode for LiteralPat {
1374 } 1462 }
1375 } 1463 }
1376 fn cast(syntax: SyntaxNode) -> Option<Self> { 1464 fn cast(syntax: SyntaxNode) -> Option<Self> {
1377 if Self::can_cast(syntax.kind()) { Some(LiteralPat { syntax }) } else { None } 1465 if Self::can_cast(syntax.kind()) {
1466 Some(Self { syntax })
1467 } else {
1468 None
1469 }
1470 }
1471 fn syntax(&self) -> &SyntaxNode {
1472 &self.syntax
1378 } 1473 }
1379 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1380} 1474}
1381
1382
1383impl LiteralPat { 1475impl LiteralPat {
1384 pub fn literal(&self) -> Option<Literal> { 1476 pub fn literal(&self) -> Option<Literal> {
1385 super::child_opt(self) 1477 AstChildren::new(&self.syntax).next()
1386 } 1478 }
1387} 1479}
1388
1389// LoopExpr
1390#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1480#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1391pub struct LoopExpr { 1481pub struct LoopExpr {
1392 pub(crate) syntax: SyntaxNode, 1482 pub(crate) syntax: SyntaxNode,
1393} 1483}
1394
1395impl AstNode for LoopExpr { 1484impl AstNode for LoopExpr {
1396 fn can_cast(kind: SyntaxKind) -> bool { 1485 fn can_cast(kind: SyntaxKind) -> bool {
1397 match kind { 1486 match kind {
@@ -1400,21 +1489,22 @@ impl AstNode for LoopExpr {
1400 } 1489 }
1401 } 1490 }
1402 fn cast(syntax: SyntaxNode) -> Option<Self> { 1491 fn cast(syntax: SyntaxNode) -> Option<Self> {
1403 if Self::can_cast(syntax.kind()) { Some(LoopExpr { syntax }) } else { None } 1492 if Self::can_cast(syntax.kind()) {
1493 Some(Self { syntax })
1494 } else {
1495 None
1496 }
1497 }
1498 fn syntax(&self) -> &SyntaxNode {
1499 &self.syntax
1404 } 1500 }
1405 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1406} 1501}
1407
1408
1409impl ast::LoopBodyOwner for LoopExpr {} 1502impl ast::LoopBodyOwner for LoopExpr {}
1410impl LoopExpr {} 1503impl LoopExpr {}
1411
1412// MacroCall
1413#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1504#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1414pub struct MacroCall { 1505pub struct MacroCall {
1415 pub(crate) syntax: SyntaxNode, 1506 pub(crate) syntax: SyntaxNode,
1416} 1507}
1417
1418impl AstNode for MacroCall { 1508impl AstNode for MacroCall {
1419 fn can_cast(kind: SyntaxKind) -> bool { 1509 fn can_cast(kind: SyntaxKind) -> bool {
1420 match kind { 1510 match kind {
@@ -1423,31 +1513,31 @@ impl AstNode for MacroCall {
1423 } 1513 }
1424 } 1514 }
1425 fn cast(syntax: SyntaxNode) -> Option<Self> { 1515 fn cast(syntax: SyntaxNode) -> Option<Self> {
1426 if Self::can_cast(syntax.kind()) { Some(MacroCall { syntax }) } else { None } 1516 if Self::can_cast(syntax.kind()) {
1517 Some(Self { syntax })
1518 } else {
1519 None
1520 }
1521 }
1522 fn syntax(&self) -> &SyntaxNode {
1523 &self.syntax
1427 } 1524 }
1428 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1429} 1525}
1430
1431
1432impl ast::NameOwner for MacroCall {} 1526impl ast::NameOwner for MacroCall {}
1433impl ast::AttrsOwner for MacroCall {} 1527impl ast::AttrsOwner for MacroCall {}
1434impl ast::DocCommentsOwner for MacroCall {} 1528impl ast::DocCommentsOwner for MacroCall {}
1435impl MacroCall { 1529impl MacroCall {
1436 pub fn token_tree(&self) -> Option<TokenTree> { 1530 pub fn token_tree(&self) -> Option<TokenTree> {
1437 super::child_opt(self) 1531 AstChildren::new(&self.syntax).next()
1438 } 1532 }
1439
1440 pub fn path(&self) -> Option<Path> { 1533 pub fn path(&self) -> Option<Path> {
1441 super::child_opt(self) 1534 AstChildren::new(&self.syntax).next()
1442 } 1535 }
1443} 1536}
1444
1445// MacroItems
1446#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1537#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1447pub struct MacroItems { 1538pub struct MacroItems {
1448 pub(crate) syntax: SyntaxNode, 1539 pub(crate) syntax: SyntaxNode,
1449} 1540}
1450
1451impl AstNode for MacroItems { 1541impl AstNode for MacroItems {
1452 fn can_cast(kind: SyntaxKind) -> bool { 1542 fn can_cast(kind: SyntaxKind) -> bool {
1453 match kind { 1543 match kind {
@@ -1456,22 +1546,23 @@ impl AstNode for MacroItems {
1456 } 1546 }
1457 } 1547 }
1458 fn cast(syntax: SyntaxNode) -> Option<Self> { 1548 fn cast(syntax: SyntaxNode) -> Option<Self> {
1459 if Self::can_cast(syntax.kind()) { Some(MacroItems { syntax }) } else { None } 1549 if Self::can_cast(syntax.kind()) {
1550 Some(Self { syntax })
1551 } else {
1552 None
1553 }
1554 }
1555 fn syntax(&self) -> &SyntaxNode {
1556 &self.syntax
1460 } 1557 }
1461 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1462} 1558}
1463
1464
1465impl ast::ModuleItemOwner for MacroItems {} 1559impl ast::ModuleItemOwner for MacroItems {}
1466impl ast::FnDefOwner for MacroItems {} 1560impl ast::FnDefOwner for MacroItems {}
1467impl MacroItems {} 1561impl MacroItems {}
1468
1469// MacroStmts
1470#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1562#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1471pub struct MacroStmts { 1563pub struct MacroStmts {
1472 pub(crate) syntax: SyntaxNode, 1564 pub(crate) syntax: SyntaxNode,
1473} 1565}
1474
1475impl AstNode for MacroStmts { 1566impl AstNode for MacroStmts {
1476 fn can_cast(kind: SyntaxKind) -> bool { 1567 fn can_cast(kind: SyntaxKind) -> bool {
1477 match kind { 1568 match kind {
@@ -1480,28 +1571,28 @@ impl AstNode for MacroStmts {
1480 } 1571 }
1481 } 1572 }
1482 fn cast(syntax: SyntaxNode) -> Option<Self> { 1573 fn cast(syntax: SyntaxNode) -> Option<Self> {
1483 if Self::can_cast(syntax.kind()) { Some(MacroStmts { syntax }) } else { None } 1574 if Self::can_cast(syntax.kind()) {
1575 Some(Self { syntax })
1576 } else {
1577 None
1578 }
1579 }
1580 fn syntax(&self) -> &SyntaxNode {
1581 &self.syntax
1484 } 1582 }
1485 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1486} 1583}
1487
1488
1489impl MacroStmts { 1584impl MacroStmts {
1490 pub fn statements(&self) -> impl Iterator<Item = Stmt> { 1585 pub fn statements(&self) -> AstChildren<Stmt> {
1491 super::children(self) 1586 AstChildren::new(&self.syntax)
1492 } 1587 }
1493
1494 pub fn expr(&self) -> Option<Expr> { 1588 pub fn expr(&self) -> Option<Expr> {
1495 super::child_opt(self) 1589 AstChildren::new(&self.syntax).next()
1496 } 1590 }
1497} 1591}
1498
1499// MatchArm
1500#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1592#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1501pub struct MatchArm { 1593pub struct MatchArm {
1502 pub(crate) syntax: SyntaxNode, 1594 pub(crate) syntax: SyntaxNode,
1503} 1595}
1504
1505impl AstNode for MatchArm { 1596impl AstNode for MatchArm {
1506 fn can_cast(kind: SyntaxKind) -> bool { 1597 fn can_cast(kind: SyntaxKind) -> bool {
1507 match kind { 1598 match kind {
@@ -1510,33 +1601,32 @@ impl AstNode for MatchArm {
1510 } 1601 }
1511 } 1602 }
1512 fn cast(syntax: SyntaxNode) -> Option<Self> { 1603 fn cast(syntax: SyntaxNode) -> Option<Self> {
1513 if Self::can_cast(syntax.kind()) { Some(MatchArm { syntax }) } else { None } 1604 if Self::can_cast(syntax.kind()) {
1605 Some(Self { syntax })
1606 } else {
1607 None
1608 }
1609 }
1610 fn syntax(&self) -> &SyntaxNode {
1611 &self.syntax
1514 } 1612 }
1515 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1516} 1613}
1517
1518
1519impl ast::AttrsOwner for MatchArm {} 1614impl ast::AttrsOwner for MatchArm {}
1520impl MatchArm { 1615impl MatchArm {
1521 pub fn pats(&self) -> impl Iterator<Item = Pat> { 1616 pub fn pats(&self) -> AstChildren<Pat> {
1522 super::children(self) 1617 AstChildren::new(&self.syntax)
1523 } 1618 }
1524
1525 pub fn guard(&self) -> Option<MatchGuard> { 1619 pub fn guard(&self) -> Option<MatchGuard> {
1526 super::child_opt(self) 1620 AstChildren::new(&self.syntax).next()
1527 } 1621 }
1528
1529 pub fn expr(&self) -> Option<Expr> { 1622 pub fn expr(&self) -> Option<Expr> {
1530 super::child_opt(self) 1623 AstChildren::new(&self.syntax).next()
1531 } 1624 }
1532} 1625}
1533
1534// MatchArmList
1535#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1626#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1536pub struct MatchArmList { 1627pub struct MatchArmList {
1537 pub(crate) syntax: SyntaxNode, 1628 pub(crate) syntax: SyntaxNode,
1538} 1629}
1539
1540impl AstNode for MatchArmList { 1630impl AstNode for MatchArmList {
1541 fn can_cast(kind: SyntaxKind) -> bool { 1631 fn can_cast(kind: SyntaxKind) -> bool {
1542 match kind { 1632 match kind {
@@ -1545,25 +1635,26 @@ impl AstNode for MatchArmList {
1545 } 1635 }
1546 } 1636 }
1547 fn cast(syntax: SyntaxNode) -> Option<Self> { 1637 fn cast(syntax: SyntaxNode) -> Option<Self> {
1548 if Self::can_cast(syntax.kind()) { Some(MatchArmList { syntax }) } else { None } 1638 if Self::can_cast(syntax.kind()) {
1639 Some(Self { syntax })
1640 } else {
1641 None
1642 }
1643 }
1644 fn syntax(&self) -> &SyntaxNode {
1645 &self.syntax
1549 } 1646 }
1550 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1551} 1647}
1552
1553
1554impl ast::AttrsOwner for MatchArmList {} 1648impl ast::AttrsOwner for MatchArmList {}
1555impl MatchArmList { 1649impl MatchArmList {
1556 pub fn arms(&self) -> impl Iterator<Item = MatchArm> { 1650 pub fn arms(&self) -> AstChildren<MatchArm> {
1557 super::children(self) 1651 AstChildren::new(&self.syntax)
1558 } 1652 }
1559} 1653}
1560
1561// MatchExpr
1562#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1654#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1563pub struct MatchExpr { 1655pub struct MatchExpr {
1564 pub(crate) syntax: SyntaxNode, 1656 pub(crate) syntax: SyntaxNode,
1565} 1657}
1566
1567impl AstNode for MatchExpr { 1658impl AstNode for MatchExpr {
1568 fn can_cast(kind: SyntaxKind) -> bool { 1659 fn can_cast(kind: SyntaxKind) -> bool {
1569 match kind { 1660 match kind {
@@ -1572,28 +1663,28 @@ impl AstNode for MatchExpr {
1572 } 1663 }
1573 } 1664 }
1574 fn cast(syntax: SyntaxNode) -> Option<Self> { 1665 fn cast(syntax: SyntaxNode) -> Option<Self> {
1575 if Self::can_cast(syntax.kind()) { Some(MatchExpr { syntax }) } else { None } 1666 if Self::can_cast(syntax.kind()) {
1667 Some(Self { syntax })
1668 } else {
1669 None
1670 }
1671 }
1672 fn syntax(&self) -> &SyntaxNode {
1673 &self.syntax
1576 } 1674 }
1577 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1578} 1675}
1579
1580
1581impl MatchExpr { 1676impl MatchExpr {
1582 pub fn expr(&self) -> Option<Expr> { 1677 pub fn expr(&self) -> Option<Expr> {
1583 super::child_opt(self) 1678 AstChildren::new(&self.syntax).next()
1584 } 1679 }
1585
1586 pub fn match_arm_list(&self) -> Option<MatchArmList> { 1680 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1587 super::child_opt(self) 1681 AstChildren::new(&self.syntax).next()
1588 } 1682 }
1589} 1683}
1590
1591// MatchGuard
1592#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1684#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1593pub struct MatchGuard { 1685pub struct MatchGuard {
1594 pub(crate) syntax: SyntaxNode, 1686 pub(crate) syntax: SyntaxNode,
1595} 1687}
1596
1597impl AstNode for MatchGuard { 1688impl AstNode for MatchGuard {
1598 fn can_cast(kind: SyntaxKind) -> bool { 1689 fn can_cast(kind: SyntaxKind) -> bool {
1599 match kind { 1690 match kind {
@@ -1602,24 +1693,25 @@ impl AstNode for MatchGuard {
1602 } 1693 }
1603 } 1694 }
1604 fn cast(syntax: SyntaxNode) -> Option<Self> { 1695 fn cast(syntax: SyntaxNode) -> Option<Self> {
1605 if Self::can_cast(syntax.kind()) { Some(MatchGuard { syntax }) } else { None } 1696 if Self::can_cast(syntax.kind()) {
1697 Some(Self { syntax })
1698 } else {
1699 None
1700 }
1701 }
1702 fn syntax(&self) -> &SyntaxNode {
1703 &self.syntax
1606 } 1704 }
1607 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1608} 1705}
1609
1610
1611impl MatchGuard { 1706impl MatchGuard {
1612 pub fn expr(&self) -> Option<Expr> { 1707 pub fn expr(&self) -> Option<Expr> {
1613 super::child_opt(self) 1708 AstChildren::new(&self.syntax).next()
1614 } 1709 }
1615} 1710}
1616
1617// MethodCallExpr
1618#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1711#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1619pub struct MethodCallExpr { 1712pub struct MethodCallExpr {
1620 pub(crate) syntax: SyntaxNode, 1713 pub(crate) syntax: SyntaxNode,
1621} 1714}
1622
1623impl AstNode for MethodCallExpr { 1715impl AstNode for MethodCallExpr {
1624 fn can_cast(kind: SyntaxKind) -> bool { 1716 fn can_cast(kind: SyntaxKind) -> bool {
1625 match kind { 1717 match kind {
@@ -1628,33 +1720,32 @@ impl AstNode for MethodCallExpr {
1628 } 1720 }
1629 } 1721 }
1630 fn cast(syntax: SyntaxNode) -> Option<Self> { 1722 fn cast(syntax: SyntaxNode) -> Option<Self> {
1631 if Self::can_cast(syntax.kind()) { Some(MethodCallExpr { syntax }) } else { None } 1723 if Self::can_cast(syntax.kind()) {
1724 Some(Self { syntax })
1725 } else {
1726 None
1727 }
1728 }
1729 fn syntax(&self) -> &SyntaxNode {
1730 &self.syntax
1632 } 1731 }
1633 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1634} 1732}
1635
1636
1637impl ast::ArgListOwner for MethodCallExpr {} 1733impl ast::ArgListOwner for MethodCallExpr {}
1638impl MethodCallExpr { 1734impl MethodCallExpr {
1639 pub fn expr(&self) -> Option<Expr> { 1735 pub fn expr(&self) -> Option<Expr> {
1640 super::child_opt(self) 1736 AstChildren::new(&self.syntax).next()
1641 } 1737 }
1642
1643 pub fn name_ref(&self) -> Option<NameRef> { 1738 pub fn name_ref(&self) -> Option<NameRef> {
1644 super::child_opt(self) 1739 AstChildren::new(&self.syntax).next()
1645 } 1740 }
1646
1647 pub fn type_arg_list(&self) -> Option<TypeArgList> { 1741 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1648 super::child_opt(self) 1742 AstChildren::new(&self.syntax).next()
1649 } 1743 }
1650} 1744}
1651
1652// Module
1653#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1745#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1654pub struct Module { 1746pub struct Module {
1655 pub(crate) syntax: SyntaxNode, 1747 pub(crate) syntax: SyntaxNode,
1656} 1748}
1657
1658impl AstNode for Module { 1749impl AstNode for Module {
1659 fn can_cast(kind: SyntaxKind) -> bool { 1750 fn can_cast(kind: SyntaxKind) -> bool {
1660 match kind { 1751 match kind {
@@ -1663,43 +1754,48 @@ impl AstNode for Module {
1663 } 1754 }
1664 } 1755 }
1665 fn cast(syntax: SyntaxNode) -> Option<Self> { 1756 fn cast(syntax: SyntaxNode) -> Option<Self> {
1666 if Self::can_cast(syntax.kind()) { Some(Module { syntax }) } else { None } 1757 if Self::can_cast(syntax.kind()) {
1758 Some(Self { syntax })
1759 } else {
1760 None
1761 }
1762 }
1763 fn syntax(&self) -> &SyntaxNode {
1764 &self.syntax
1667 } 1765 }
1668 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1669} 1766}
1670
1671
1672impl ast::VisibilityOwner for Module {} 1767impl ast::VisibilityOwner for Module {}
1673impl ast::NameOwner for Module {} 1768impl ast::NameOwner for Module {}
1674impl ast::AttrsOwner for Module {} 1769impl ast::AttrsOwner for Module {}
1675impl ast::DocCommentsOwner for Module {} 1770impl ast::DocCommentsOwner for Module {}
1676impl Module { 1771impl Module {
1677 pub fn item_list(&self) -> Option<ItemList> { 1772 pub fn item_list(&self) -> Option<ItemList> {
1678 super::child_opt(self) 1773 AstChildren::new(&self.syntax).next()
1679 } 1774 }
1680} 1775}
1681
1682// ModuleItem
1683#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1776#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1684pub struct ModuleItem { 1777pub struct ModuleItem {
1685 pub(crate) syntax: SyntaxNode, 1778 pub(crate) syntax: SyntaxNode,
1686} 1779}
1687
1688impl AstNode for ModuleItem { 1780impl AstNode for ModuleItem {
1689 fn can_cast(kind: SyntaxKind) -> bool { 1781 fn can_cast(kind: SyntaxKind) -> bool {
1690 match kind { 1782 match kind {
1691 | STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, 1783 STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM
1784 | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1692 _ => false, 1785 _ => false,
1693 } 1786 }
1694 } 1787 }
1695 fn cast(syntax: SyntaxNode) -> Option<Self> { 1788 fn cast(syntax: SyntaxNode) -> Option<Self> {
1696 if Self::can_cast(syntax.kind()) { Some(ModuleItem { syntax }) } else { None } 1789 if Self::can_cast(syntax.kind()) {
1790 Some(Self { syntax })
1791 } else {
1792 None
1793 }
1794 }
1795 fn syntax(&self) -> &SyntaxNode {
1796 &self.syntax
1697 } 1797 }
1698 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1699} 1798}
1700
1701
1702#[derive(Debug, Clone, PartialEq, Eq)]
1703pub enum ModuleItemKind { 1799pub enum ModuleItemKind {
1704 StructDef(StructDef), 1800 StructDef(StructDef),
1705 EnumDef(EnumDef), 1801 EnumDef(EnumDef),
@@ -1714,65 +1810,84 @@ pub enum ModuleItemKind {
1714 Module(Module), 1810 Module(Module),
1715} 1811}
1716impl From<StructDef> for ModuleItem { 1812impl From<StructDef> for ModuleItem {
1717 fn from(n: StructDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1813 fn from(node: StructDef) -> ModuleItem {
1814 ModuleItem { syntax: node.syntax }
1815 }
1718} 1816}
1719impl From<EnumDef> for ModuleItem { 1817impl From<EnumDef> for ModuleItem {
1720 fn from(n: EnumDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1818 fn from(node: EnumDef) -> ModuleItem {
1819 ModuleItem { syntax: node.syntax }
1820 }
1721} 1821}
1722impl From<FnDef> for ModuleItem { 1822impl From<FnDef> for ModuleItem {
1723 fn from(n: FnDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1823 fn from(node: FnDef) -> ModuleItem {
1824 ModuleItem { syntax: node.syntax }
1825 }
1724} 1826}
1725impl From<TraitDef> for ModuleItem { 1827impl From<TraitDef> for ModuleItem {
1726 fn from(n: TraitDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1828 fn from(node: TraitDef) -> ModuleItem {
1829 ModuleItem { syntax: node.syntax }
1830 }
1727} 1831}
1728impl From<TypeAliasDef> for ModuleItem { 1832impl From<TypeAliasDef> for ModuleItem {
1729 fn from(n: TypeAliasDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1833 fn from(node: TypeAliasDef) -> ModuleItem {
1834 ModuleItem { syntax: node.syntax }
1835 }
1730} 1836}
1731impl From<ImplBlock> for ModuleItem { 1837impl From<ImplBlock> for ModuleItem {
1732 fn from(n: ImplBlock) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1838 fn from(node: ImplBlock) -> ModuleItem {
1839 ModuleItem { syntax: node.syntax }
1840 }
1733} 1841}
1734impl From<UseItem> for ModuleItem { 1842impl From<UseItem> for ModuleItem {
1735 fn from(n: UseItem) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1843 fn from(node: UseItem) -> ModuleItem {
1844 ModuleItem { syntax: node.syntax }
1845 }
1736} 1846}
1737impl From<ExternCrateItem> for ModuleItem { 1847impl From<ExternCrateItem> for ModuleItem {
1738 fn from(n: ExternCrateItem) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1848 fn from(node: ExternCrateItem) -> ModuleItem {
1849 ModuleItem { syntax: node.syntax }
1850 }
1739} 1851}
1740impl From<ConstDef> for ModuleItem { 1852impl From<ConstDef> for ModuleItem {
1741 fn from(n: ConstDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1853 fn from(node: ConstDef) -> ModuleItem {
1854 ModuleItem { syntax: node.syntax }
1855 }
1742} 1856}
1743impl From<StaticDef> for ModuleItem { 1857impl From<StaticDef> for ModuleItem {
1744 fn from(n: StaticDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1858 fn from(node: StaticDef) -> ModuleItem {
1859 ModuleItem { syntax: node.syntax }
1860 }
1745} 1861}
1746impl From<Module> for ModuleItem { 1862impl From<Module> for ModuleItem {
1747 fn from(n: Module) -> ModuleItem { ModuleItem { syntax: n.syntax } } 1863 fn from(node: Module) -> ModuleItem {
1864 ModuleItem { syntax: node.syntax }
1865 }
1748} 1866}
1749impl ModuleItem { 1867impl ModuleItem {
1750 pub fn kind(&self) -> ModuleItemKind { 1868 pub fn kind(&self) -> ModuleItemKind {
1751 match self.syntax.kind() { 1869 let syntax = self.syntax.clone();
1752 STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(self.syntax.clone()).unwrap()), 1870 match syntax.kind() {
1753 ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(self.syntax.clone()).unwrap()), 1871 STRUCT_DEF => ModuleItemKind::StructDef(StructDef { syntax }),
1754 FN_DEF => ModuleItemKind::FnDef(FnDef::cast(self.syntax.clone()).unwrap()), 1872 ENUM_DEF => ModuleItemKind::EnumDef(EnumDef { syntax }),
1755 TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(self.syntax.clone()).unwrap()), 1873 FN_DEF => ModuleItemKind::FnDef(FnDef { syntax }),
1756 TYPE_ALIAS_DEF => ModuleItemKind::TypeAliasDef(TypeAliasDef::cast(self.syntax.clone()).unwrap()), 1874 TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef { syntax }),
1757 IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(self.syntax.clone()).unwrap()), 1875 TYPE_ALIAS_DEF => ModuleItemKind::TypeAliasDef(TypeAliasDef { syntax }),
1758 USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(self.syntax.clone()).unwrap()), 1876 IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock { syntax }),
1759 EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(self.syntax.clone()).unwrap()), 1877 USE_ITEM => ModuleItemKind::UseItem(UseItem { syntax }),
1760 CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(self.syntax.clone()).unwrap()), 1878 EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem { syntax }),
1761 STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(self.syntax.clone()).unwrap()), 1879 CONST_DEF => ModuleItemKind::ConstDef(ConstDef { syntax }),
1762 MODULE => ModuleItemKind::Module(Module::cast(self.syntax.clone()).unwrap()), 1880 STATIC_DEF => ModuleItemKind::StaticDef(StaticDef { syntax }),
1881 MODULE => ModuleItemKind::Module(Module { syntax }),
1763 _ => unreachable!(), 1882 _ => unreachable!(),
1764 } 1883 }
1765 } 1884 }
1766} 1885}
1767
1768impl ModuleItem {} 1886impl ModuleItem {}
1769
1770// Name
1771#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1887#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1772pub struct Name { 1888pub struct Name {
1773 pub(crate) syntax: SyntaxNode, 1889 pub(crate) syntax: SyntaxNode,
1774} 1890}
1775
1776impl AstNode for Name { 1891impl AstNode for Name {
1777 fn can_cast(kind: SyntaxKind) -> bool { 1892 fn can_cast(kind: SyntaxKind) -> bool {
1778 match kind { 1893 match kind {
@@ -1781,20 +1896,21 @@ impl AstNode for Name {
1781 } 1896 }
1782 } 1897 }
1783 fn cast(syntax: SyntaxNode) -> Option<Self> { 1898 fn cast(syntax: SyntaxNode) -> Option<Self> {
1784 if Self::can_cast(syntax.kind()) { Some(Name { syntax }) } else { None } 1899 if Self::can_cast(syntax.kind()) {
1900 Some(Self { syntax })
1901 } else {
1902 None
1903 }
1904 }
1905 fn syntax(&self) -> &SyntaxNode {
1906 &self.syntax
1785 } 1907 }
1786 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1787} 1908}
1788
1789
1790impl Name {} 1909impl Name {}
1791
1792// NameRef
1793#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1910#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1794pub struct NameRef { 1911pub struct NameRef {
1795 pub(crate) syntax: SyntaxNode, 1912 pub(crate) syntax: SyntaxNode,
1796} 1913}
1797
1798impl AstNode for NameRef { 1914impl AstNode for NameRef {
1799 fn can_cast(kind: SyntaxKind) -> bool { 1915 fn can_cast(kind: SyntaxKind) -> bool {
1800 match kind { 1916 match kind {
@@ -1803,20 +1919,21 @@ impl AstNode for NameRef {
1803 } 1919 }
1804 } 1920 }
1805 fn cast(syntax: SyntaxNode) -> Option<Self> { 1921 fn cast(syntax: SyntaxNode) -> Option<Self> {
1806 if Self::can_cast(syntax.kind()) { Some(NameRef { syntax }) } else { None } 1922 if Self::can_cast(syntax.kind()) {
1923 Some(Self { syntax })
1924 } else {
1925 None
1926 }
1927 }
1928 fn syntax(&self) -> &SyntaxNode {
1929 &self.syntax
1807 } 1930 }
1808 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1809} 1931}
1810
1811
1812impl NameRef {} 1932impl NameRef {}
1813
1814// NamedField
1815#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1933#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1816pub struct NamedField { 1934pub struct NamedField {
1817 pub(crate) syntax: SyntaxNode, 1935 pub(crate) syntax: SyntaxNode,
1818} 1936}
1819
1820impl AstNode for NamedField { 1937impl AstNode for NamedField {
1821 fn can_cast(kind: SyntaxKind) -> bool { 1938 fn can_cast(kind: SyntaxKind) -> bool {
1822 match kind { 1939 match kind {
@@ -1825,28 +1942,28 @@ impl AstNode for NamedField {
1825 } 1942 }
1826 } 1943 }
1827 fn cast(syntax: SyntaxNode) -> Option<Self> { 1944 fn cast(syntax: SyntaxNode) -> Option<Self> {
1828 if Self::can_cast(syntax.kind()) { Some(NamedField { syntax }) } else { None } 1945 if Self::can_cast(syntax.kind()) {
1946 Some(Self { syntax })
1947 } else {
1948 None
1949 }
1950 }
1951 fn syntax(&self) -> &SyntaxNode {
1952 &self.syntax
1829 } 1953 }
1830 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1831} 1954}
1832
1833
1834impl NamedField { 1955impl NamedField {
1835 pub fn name_ref(&self) -> Option<NameRef> { 1956 pub fn name_ref(&self) -> Option<NameRef> {
1836 super::child_opt(self) 1957 AstChildren::new(&self.syntax).next()
1837 } 1958 }
1838
1839 pub fn expr(&self) -> Option<Expr> { 1959 pub fn expr(&self) -> Option<Expr> {
1840 super::child_opt(self) 1960 AstChildren::new(&self.syntax).next()
1841 } 1961 }
1842} 1962}
1843
1844// NamedFieldDef
1845#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1963#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1846pub struct NamedFieldDef { 1964pub struct NamedFieldDef {
1847 pub(crate) syntax: SyntaxNode, 1965 pub(crate) syntax: SyntaxNode,
1848} 1966}
1849
1850impl AstNode for NamedFieldDef { 1967impl AstNode for NamedFieldDef {
1851 fn can_cast(kind: SyntaxKind) -> bool { 1968 fn can_cast(kind: SyntaxKind) -> bool {
1852 match kind { 1969 match kind {
@@ -1855,25 +1972,26 @@ impl AstNode for NamedFieldDef {
1855 } 1972 }
1856 } 1973 }
1857 fn cast(syntax: SyntaxNode) -> Option<Self> { 1974 fn cast(syntax: SyntaxNode) -> Option<Self> {
1858 if Self::can_cast(syntax.kind()) { Some(NamedFieldDef { syntax }) } else { None } 1975 if Self::can_cast(syntax.kind()) {
1976 Some(Self { syntax })
1977 } else {
1978 None
1979 }
1980 }
1981 fn syntax(&self) -> &SyntaxNode {
1982 &self.syntax
1859 } 1983 }
1860 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1861} 1984}
1862
1863
1864impl ast::VisibilityOwner for NamedFieldDef {} 1985impl ast::VisibilityOwner for NamedFieldDef {}
1865impl ast::NameOwner for NamedFieldDef {} 1986impl ast::NameOwner for NamedFieldDef {}
1866impl ast::AttrsOwner for NamedFieldDef {} 1987impl ast::AttrsOwner for NamedFieldDef {}
1867impl ast::DocCommentsOwner for NamedFieldDef {} 1988impl ast::DocCommentsOwner for NamedFieldDef {}
1868impl ast::TypeAscriptionOwner for NamedFieldDef {} 1989impl ast::TypeAscriptionOwner for NamedFieldDef {}
1869impl NamedFieldDef {} 1990impl NamedFieldDef {}
1870
1871// NamedFieldDefList
1872#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1991#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1873pub struct NamedFieldDefList { 1992pub struct NamedFieldDefList {
1874 pub(crate) syntax: SyntaxNode, 1993 pub(crate) syntax: SyntaxNode,
1875} 1994}
1876
1877impl AstNode for NamedFieldDefList { 1995impl AstNode for NamedFieldDefList {
1878 fn can_cast(kind: SyntaxKind) -> bool { 1996 fn can_cast(kind: SyntaxKind) -> bool {
1879 match kind { 1997 match kind {
@@ -1882,24 +2000,25 @@ impl AstNode for NamedFieldDefList {
1882 } 2000 }
1883 } 2001 }
1884 fn cast(syntax: SyntaxNode) -> Option<Self> { 2002 fn cast(syntax: SyntaxNode) -> Option<Self> {
1885 if Self::can_cast(syntax.kind()) { Some(NamedFieldDefList { syntax }) } else { None } 2003 if Self::can_cast(syntax.kind()) {
2004 Some(Self { syntax })
2005 } else {
2006 None
2007 }
2008 }
2009 fn syntax(&self) -> &SyntaxNode {
2010 &self.syntax
1886 } 2011 }
1887 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1888} 2012}
1889
1890
1891impl NamedFieldDefList { 2013impl NamedFieldDefList {
1892 pub fn fields(&self) -> impl Iterator<Item = NamedFieldDef> { 2014 pub fn fields(&self) -> AstChildren<NamedFieldDef> {
1893 super::children(self) 2015 AstChildren::new(&self.syntax)
1894 } 2016 }
1895} 2017}
1896
1897// NamedFieldList
1898#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2018#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1899pub struct NamedFieldList { 2019pub struct NamedFieldList {
1900 pub(crate) syntax: SyntaxNode, 2020 pub(crate) syntax: SyntaxNode,
1901} 2021}
1902
1903impl AstNode for NamedFieldList { 2022impl AstNode for NamedFieldList {
1904 fn can_cast(kind: SyntaxKind) -> bool { 2023 fn can_cast(kind: SyntaxKind) -> bool {
1905 match kind { 2024 match kind {
@@ -1908,28 +2027,28 @@ impl AstNode for NamedFieldList {
1908 } 2027 }
1909 } 2028 }
1910 fn cast(syntax: SyntaxNode) -> Option<Self> { 2029 fn cast(syntax: SyntaxNode) -> Option<Self> {
1911 if Self::can_cast(syntax.kind()) { Some(NamedFieldList { syntax }) } else { None } 2030 if Self::can_cast(syntax.kind()) {
2031 Some(Self { syntax })
2032 } else {
2033 None
2034 }
2035 }
2036 fn syntax(&self) -> &SyntaxNode {
2037 &self.syntax
1912 } 2038 }
1913 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1914} 2039}
1915
1916
1917impl NamedFieldList { 2040impl NamedFieldList {
1918 pub fn fields(&self) -> impl Iterator<Item = NamedField> { 2041 pub fn fields(&self) -> AstChildren<NamedField> {
1919 super::children(self) 2042 AstChildren::new(&self.syntax)
1920 } 2043 }
1921
1922 pub fn spread(&self) -> Option<Expr> { 2044 pub fn spread(&self) -> Option<Expr> {
1923 super::child_opt(self) 2045 AstChildren::new(&self.syntax).next()
1924 } 2046 }
1925} 2047}
1926
1927// NeverType
1928#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2048#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1929pub struct NeverType { 2049pub struct NeverType {
1930 pub(crate) syntax: SyntaxNode, 2050 pub(crate) syntax: SyntaxNode,
1931} 2051}
1932
1933impl AstNode for NeverType { 2052impl AstNode for NeverType {
1934 fn can_cast(kind: SyntaxKind) -> bool { 2053 fn can_cast(kind: SyntaxKind) -> bool {
1935 match kind { 2054 match kind {
@@ -1938,66 +2057,71 @@ impl AstNode for NeverType {
1938 } 2057 }
1939 } 2058 }
1940 fn cast(syntax: SyntaxNode) -> Option<Self> { 2059 fn cast(syntax: SyntaxNode) -> Option<Self> {
1941 if Self::can_cast(syntax.kind()) { Some(NeverType { syntax }) } else { None } 2060 if Self::can_cast(syntax.kind()) {
2061 Some(Self { syntax })
2062 } else {
2063 None
2064 }
2065 }
2066 fn syntax(&self) -> &SyntaxNode {
2067 &self.syntax
1942 } 2068 }
1943 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1944} 2069}
1945
1946
1947impl NeverType {} 2070impl NeverType {}
1948
1949// NominalDef
1950#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2071#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1951pub struct NominalDef { 2072pub struct NominalDef {
1952 pub(crate) syntax: SyntaxNode, 2073 pub(crate) syntax: SyntaxNode,
1953} 2074}
1954
1955impl AstNode for NominalDef { 2075impl AstNode for NominalDef {
1956 fn can_cast(kind: SyntaxKind) -> bool { 2076 fn can_cast(kind: SyntaxKind) -> bool {
1957 match kind { 2077 match kind {
1958 | STRUCT_DEF | ENUM_DEF => true, 2078 STRUCT_DEF | ENUM_DEF => true,
1959 _ => false, 2079 _ => false,
1960 } 2080 }
1961 } 2081 }
1962 fn cast(syntax: SyntaxNode) -> Option<Self> { 2082 fn cast(syntax: SyntaxNode) -> Option<Self> {
1963 if Self::can_cast(syntax.kind()) { Some(NominalDef { syntax }) } else { None } 2083 if Self::can_cast(syntax.kind()) {
2084 Some(Self { syntax })
2085 } else {
2086 None
2087 }
2088 }
2089 fn syntax(&self) -> &SyntaxNode {
2090 &self.syntax
1964 } 2091 }
1965 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1966} 2092}
1967
1968
1969#[derive(Debug, Clone, PartialEq, Eq)]
1970pub enum NominalDefKind { 2093pub enum NominalDefKind {
1971 StructDef(StructDef), 2094 StructDef(StructDef),
1972 EnumDef(EnumDef), 2095 EnumDef(EnumDef),
1973} 2096}
1974impl From<StructDef> for NominalDef { 2097impl From<StructDef> for NominalDef {
1975 fn from(n: StructDef) -> NominalDef { NominalDef { syntax: n.syntax } } 2098 fn from(node: StructDef) -> NominalDef {
2099 NominalDef { syntax: node.syntax }
2100 }
1976} 2101}
1977impl From<EnumDef> for NominalDef { 2102impl From<EnumDef> for NominalDef {
1978 fn from(n: EnumDef) -> NominalDef { NominalDef { syntax: n.syntax } } 2103 fn from(node: EnumDef) -> NominalDef {
2104 NominalDef { syntax: node.syntax }
2105 }
1979} 2106}
1980impl NominalDef { 2107impl NominalDef {
1981 pub fn kind(&self) -> NominalDefKind { 2108 pub fn kind(&self) -> NominalDefKind {
1982 match self.syntax.kind() { 2109 let syntax = self.syntax.clone();
1983 STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(self.syntax.clone()).unwrap()), 2110 match syntax.kind() {
1984 ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(self.syntax.clone()).unwrap()), 2111 STRUCT_DEF => NominalDefKind::StructDef(StructDef { syntax }),
2112 ENUM_DEF => NominalDefKind::EnumDef(EnumDef { syntax }),
1985 _ => unreachable!(), 2113 _ => unreachable!(),
1986 } 2114 }
1987 } 2115 }
1988} 2116}
1989
1990impl ast::NameOwner for NominalDef {} 2117impl ast::NameOwner for NominalDef {}
1991impl ast::TypeParamsOwner for NominalDef {} 2118impl ast::TypeParamsOwner for NominalDef {}
1992impl ast::AttrsOwner for NominalDef {} 2119impl ast::AttrsOwner for NominalDef {}
1993impl NominalDef {} 2120impl NominalDef {}
1994
1995// Param
1996#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2121#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1997pub struct Param { 2122pub struct Param {
1998 pub(crate) syntax: SyntaxNode, 2123 pub(crate) syntax: SyntaxNode,
1999} 2124}
2000
2001impl AstNode for Param { 2125impl AstNode for Param {
2002 fn can_cast(kind: SyntaxKind) -> bool { 2126 fn can_cast(kind: SyntaxKind) -> bool {
2003 match kind { 2127 match kind {
@@ -2006,26 +2130,27 @@ impl AstNode for Param {
2006 } 2130 }
2007 } 2131 }
2008 fn cast(syntax: SyntaxNode) -> Option<Self> { 2132 fn cast(syntax: SyntaxNode) -> Option<Self> {
2009 if Self::can_cast(syntax.kind()) { Some(Param { syntax }) } else { None } 2133 if Self::can_cast(syntax.kind()) {
2134 Some(Self { syntax })
2135 } else {
2136 None
2137 }
2138 }
2139 fn syntax(&self) -> &SyntaxNode {
2140 &self.syntax
2010 } 2141 }
2011 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2012} 2142}
2013
2014
2015impl ast::TypeAscriptionOwner for Param {} 2143impl ast::TypeAscriptionOwner for Param {}
2016impl ast::AttrsOwner for Param {} 2144impl ast::AttrsOwner for Param {}
2017impl Param { 2145impl Param {
2018 pub fn pat(&self) -> Option<Pat> { 2146 pub fn pat(&self) -> Option<Pat> {
2019 super::child_opt(self) 2147 AstChildren::new(&self.syntax).next()
2020 } 2148 }
2021} 2149}
2022
2023// ParamList
2024#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2150#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2025pub struct ParamList { 2151pub struct ParamList {
2026 pub(crate) syntax: SyntaxNode, 2152 pub(crate) syntax: SyntaxNode,
2027} 2153}
2028
2029impl AstNode for ParamList { 2154impl AstNode for ParamList {
2030 fn can_cast(kind: SyntaxKind) -> bool { 2155 fn can_cast(kind: SyntaxKind) -> bool {
2031 match kind { 2156 match kind {
@@ -2034,28 +2159,28 @@ impl AstNode for ParamList {
2034 } 2159 }
2035 } 2160 }
2036 fn cast(syntax: SyntaxNode) -> Option<Self> { 2161 fn cast(syntax: SyntaxNode) -> Option<Self> {
2037 if Self::can_cast(syntax.kind()) { Some(ParamList { syntax }) } else { None } 2162 if Self::can_cast(syntax.kind()) {
2163 Some(Self { syntax })
2164 } else {
2165 None
2166 }
2167 }
2168 fn syntax(&self) -> &SyntaxNode {
2169 &self.syntax
2038 } 2170 }
2039 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2040} 2171}
2041
2042
2043impl ParamList { 2172impl ParamList {
2044 pub fn params(&self) -> impl Iterator<Item = Param> { 2173 pub fn params(&self) -> AstChildren<Param> {
2045 super::children(self) 2174 AstChildren::new(&self.syntax)
2046 } 2175 }
2047
2048 pub fn self_param(&self) -> Option<SelfParam> { 2176 pub fn self_param(&self) -> Option<SelfParam> {
2049 super::child_opt(self) 2177 AstChildren::new(&self.syntax).next()
2050 } 2178 }
2051} 2179}
2052
2053// ParenExpr
2054#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2180#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2055pub struct ParenExpr { 2181pub struct ParenExpr {
2056 pub(crate) syntax: SyntaxNode, 2182 pub(crate) syntax: SyntaxNode,
2057} 2183}
2058
2059impl AstNode for ParenExpr { 2184impl AstNode for ParenExpr {
2060 fn can_cast(kind: SyntaxKind) -> bool { 2185 fn can_cast(kind: SyntaxKind) -> bool {
2061 match kind { 2186 match kind {
@@ -2064,24 +2189,25 @@ impl AstNode for ParenExpr {
2064 } 2189 }
2065 } 2190 }
2066 fn cast(syntax: SyntaxNode) -> Option<Self> { 2191 fn cast(syntax: SyntaxNode) -> Option<Self> {
2067 if Self::can_cast(syntax.kind()) { Some(ParenExpr { syntax }) } else { None } 2192 if Self::can_cast(syntax.kind()) {
2193 Some(Self { syntax })
2194 } else {
2195 None
2196 }
2197 }
2198 fn syntax(&self) -> &SyntaxNode {
2199 &self.syntax
2068 } 2200 }
2069 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2070} 2201}
2071
2072
2073impl ParenExpr { 2202impl ParenExpr {
2074 pub fn expr(&self) -> Option<Expr> { 2203 pub fn expr(&self) -> Option<Expr> {
2075 super::child_opt(self) 2204 AstChildren::new(&self.syntax).next()
2076 } 2205 }
2077} 2206}
2078
2079// ParenType
2080#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2207#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2081pub struct ParenType { 2208pub struct ParenType {
2082 pub(crate) syntax: SyntaxNode, 2209 pub(crate) syntax: SyntaxNode,
2083} 2210}
2084
2085impl AstNode for ParenType { 2211impl AstNode for ParenType {
2086 fn can_cast(kind: SyntaxKind) -> bool { 2212 fn can_cast(kind: SyntaxKind) -> bool {
2087 match kind { 2213 match kind {
@@ -2090,39 +2216,44 @@ impl AstNode for ParenType {
2090 } 2216 }
2091 } 2217 }
2092 fn cast(syntax: SyntaxNode) -> Option<Self> { 2218 fn cast(syntax: SyntaxNode) -> Option<Self> {
2093 if Self::can_cast(syntax.kind()) { Some(ParenType { syntax }) } else { None } 2219 if Self::can_cast(syntax.kind()) {
2220 Some(Self { syntax })
2221 } else {
2222 None
2223 }
2224 }
2225 fn syntax(&self) -> &SyntaxNode {
2226 &self.syntax
2094 } 2227 }
2095 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2096} 2228}
2097
2098
2099impl ParenType { 2229impl ParenType {
2100 pub fn type_ref(&self) -> Option<TypeRef> { 2230 pub fn type_ref(&self) -> Option<TypeRef> {
2101 super::child_opt(self) 2231 AstChildren::new(&self.syntax).next()
2102 } 2232 }
2103} 2233}
2104
2105// Pat
2106#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2234#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2107pub struct Pat { 2235pub struct Pat {
2108 pub(crate) syntax: SyntaxNode, 2236 pub(crate) syntax: SyntaxNode,
2109} 2237}
2110
2111impl AstNode for Pat { 2238impl AstNode for Pat {
2112 fn can_cast(kind: SyntaxKind) -> bool { 2239 fn can_cast(kind: SyntaxKind) -> bool {
2113 match kind { 2240 match kind {
2114 | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, 2241 REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT
2242 | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2115 _ => false, 2243 _ => false,
2116 } 2244 }
2117 } 2245 }
2118 fn cast(syntax: SyntaxNode) -> Option<Self> { 2246 fn cast(syntax: SyntaxNode) -> Option<Self> {
2119 if Self::can_cast(syntax.kind()) { Some(Pat { syntax }) } else { None } 2247 if Self::can_cast(syntax.kind()) {
2248 Some(Self { syntax })
2249 } else {
2250 None
2251 }
2252 }
2253 fn syntax(&self) -> &SyntaxNode {
2254 &self.syntax
2120 } 2255 }
2121 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2122} 2256}
2123
2124
2125#[derive(Debug, Clone, PartialEq, Eq)]
2126pub enum PatKind { 2257pub enum PatKind {
2127 RefPat(RefPat), 2258 RefPat(RefPat),
2128 BindPat(BindPat), 2259 BindPat(BindPat),
@@ -2136,61 +2267,78 @@ pub enum PatKind {
2136 LiteralPat(LiteralPat), 2267 LiteralPat(LiteralPat),
2137} 2268}
2138impl From<RefPat> for Pat { 2269impl From<RefPat> for Pat {
2139 fn from(n: RefPat) -> Pat { Pat { syntax: n.syntax } } 2270 fn from(node: RefPat) -> Pat {
2271 Pat { syntax: node.syntax }
2272 }
2140} 2273}
2141impl From<BindPat> for Pat { 2274impl From<BindPat> for Pat {
2142 fn from(n: BindPat) -> Pat { Pat { syntax: n.syntax } } 2275 fn from(node: BindPat) -> Pat {
2276 Pat { syntax: node.syntax }
2277 }
2143} 2278}
2144impl From<PlaceholderPat> for Pat { 2279impl From<PlaceholderPat> for Pat {
2145 fn from(n: PlaceholderPat) -> Pat { Pat { syntax: n.syntax } } 2280 fn from(node: PlaceholderPat) -> Pat {
2281 Pat { syntax: node.syntax }
2282 }
2146} 2283}
2147impl From<PathPat> for Pat { 2284impl From<PathPat> for Pat {
2148 fn from(n: PathPat) -> Pat { Pat { syntax: n.syntax } } 2285 fn from(node: PathPat) -> Pat {
2286 Pat { syntax: node.syntax }
2287 }
2149} 2288}
2150impl From<StructPat> for Pat { 2289impl From<StructPat> for Pat {
2151 fn from(n: StructPat) -> Pat { Pat { syntax: n.syntax } } 2290 fn from(node: StructPat) -> Pat {
2291 Pat { syntax: node.syntax }
2292 }
2152} 2293}
2153impl From<TupleStructPat> for Pat { 2294impl From<TupleStructPat> for Pat {
2154 fn from(n: TupleStructPat) -> Pat { Pat { syntax: n.syntax } } 2295 fn from(node: TupleStructPat) -> Pat {
2296 Pat { syntax: node.syntax }
2297 }
2155} 2298}
2156impl From<TuplePat> for Pat { 2299impl From<TuplePat> for Pat {
2157 fn from(n: TuplePat) -> Pat { Pat { syntax: n.syntax } } 2300 fn from(node: TuplePat) -> Pat {
2301 Pat { syntax: node.syntax }
2302 }
2158} 2303}
2159impl From<SlicePat> for Pat { 2304impl From<SlicePat> for Pat {
2160 fn from(n: SlicePat) -> Pat { Pat { syntax: n.syntax } } 2305 fn from(node: SlicePat) -> Pat {
2306 Pat { syntax: node.syntax }
2307 }
2161} 2308}
2162impl From<RangePat> for Pat { 2309impl From<RangePat> for Pat {
2163 fn from(n: RangePat) -> Pat { Pat { syntax: n.syntax } } 2310 fn from(node: RangePat) -> Pat {
2311 Pat { syntax: node.syntax }
2312 }
2164} 2313}
2165impl From<LiteralPat> for Pat { 2314impl From<LiteralPat> for Pat {
2166 fn from(n: LiteralPat) -> Pat { Pat { syntax: n.syntax } } 2315 fn from(node: LiteralPat) -> Pat {
2316 Pat { syntax: node.syntax }
2317 }
2167} 2318}
2168impl Pat { 2319impl Pat {
2169 pub fn kind(&self) -> PatKind { 2320 pub fn kind(&self) -> PatKind {
2170 match self.syntax.kind() { 2321 let syntax = self.syntax.clone();
2171 REF_PAT => PatKind::RefPat(RefPat::cast(self.syntax.clone()).unwrap()), 2322 match syntax.kind() {
2172 BIND_PAT => PatKind::BindPat(BindPat::cast(self.syntax.clone()).unwrap()), 2323 REF_PAT => PatKind::RefPat(RefPat { syntax }),
2173 PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(self.syntax.clone()).unwrap()), 2324 BIND_PAT => PatKind::BindPat(BindPat { syntax }),
2174 PATH_PAT => PatKind::PathPat(PathPat::cast(self.syntax.clone()).unwrap()), 2325 PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat { syntax }),
2175 STRUCT_PAT => PatKind::StructPat(StructPat::cast(self.syntax.clone()).unwrap()), 2326 PATH_PAT => PatKind::PathPat(PathPat { syntax }),
2176 TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(self.syntax.clone()).unwrap()), 2327 STRUCT_PAT => PatKind::StructPat(StructPat { syntax }),
2177 TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(self.syntax.clone()).unwrap()), 2328 TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat { syntax }),
2178 SLICE_PAT => PatKind::SlicePat(SlicePat::cast(self.syntax.clone()).unwrap()), 2329 TUPLE_PAT => PatKind::TuplePat(TuplePat { syntax }),
2179 RANGE_PAT => PatKind::RangePat(RangePat::cast(self.syntax.clone()).unwrap()), 2330 SLICE_PAT => PatKind::SlicePat(SlicePat { syntax }),
2180 LITERAL_PAT => PatKind::LiteralPat(LiteralPat::cast(self.syntax.clone()).unwrap()), 2331 RANGE_PAT => PatKind::RangePat(RangePat { syntax }),
2332 LITERAL_PAT => PatKind::LiteralPat(LiteralPat { syntax }),
2181 _ => unreachable!(), 2333 _ => unreachable!(),
2182 } 2334 }
2183 } 2335 }
2184} 2336}
2185
2186impl Pat {} 2337impl Pat {}
2187
2188// Path
2189#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2338#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2190pub struct Path { 2339pub struct Path {
2191 pub(crate) syntax: SyntaxNode, 2340 pub(crate) syntax: SyntaxNode,
2192} 2341}
2193
2194impl AstNode for Path { 2342impl AstNode for Path {
2195 fn can_cast(kind: SyntaxKind) -> bool { 2343 fn can_cast(kind: SyntaxKind) -> bool {
2196 match kind { 2344 match kind {
@@ -2199,28 +2347,28 @@ impl AstNode for Path {
2199 } 2347 }
2200 } 2348 }
2201 fn cast(syntax: SyntaxNode) -> Option<Self> { 2349 fn cast(syntax: SyntaxNode) -> Option<Self> {
2202 if Self::can_cast(syntax.kind()) { Some(Path { syntax }) } else { None } 2350 if Self::can_cast(syntax.kind()) {
2351 Some(Self { syntax })
2352 } else {
2353 None
2354 }
2355 }
2356 fn syntax(&self) -> &SyntaxNode {
2357 &self.syntax
2203 } 2358 }
2204 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2205} 2359}
2206
2207
2208impl Path { 2360impl Path {
2209 pub fn segment(&self) -> Option<PathSegment> { 2361 pub fn segment(&self) -> Option<PathSegment> {
2210 super::child_opt(self) 2362 AstChildren::new(&self.syntax).next()
2211 } 2363 }
2212
2213 pub fn qualifier(&self) -> Option<Path> { 2364 pub fn qualifier(&self) -> Option<Path> {
2214 super::child_opt(self) 2365 AstChildren::new(&self.syntax).next()
2215 } 2366 }
2216} 2367}
2217
2218// PathExpr
2219#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2368#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2220pub struct PathExpr { 2369pub struct PathExpr {
2221 pub(crate) syntax: SyntaxNode, 2370 pub(crate) syntax: SyntaxNode,
2222} 2371}
2223
2224impl AstNode for PathExpr { 2372impl AstNode for PathExpr {
2225 fn can_cast(kind: SyntaxKind) -> bool { 2373 fn can_cast(kind: SyntaxKind) -> bool {
2226 match kind { 2374 match kind {
@@ -2229,24 +2377,25 @@ impl AstNode for PathExpr {
2229 } 2377 }
2230 } 2378 }
2231 fn cast(syntax: SyntaxNode) -> Option<Self> { 2379 fn cast(syntax: SyntaxNode) -> Option<Self> {
2232 if Self::can_cast(syntax.kind()) { Some(PathExpr { syntax }) } else { None } 2380 if Self::can_cast(syntax.kind()) {
2381 Some(Self { syntax })
2382 } else {
2383 None
2384 }
2385 }
2386 fn syntax(&self) -> &SyntaxNode {
2387 &self.syntax
2233 } 2388 }
2234 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2235} 2389}
2236
2237
2238impl PathExpr { 2390impl PathExpr {
2239 pub fn path(&self) -> Option<Path> { 2391 pub fn path(&self) -> Option<Path> {
2240 super::child_opt(self) 2392 AstChildren::new(&self.syntax).next()
2241 } 2393 }
2242} 2394}
2243
2244// PathPat
2245#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2395#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2246pub struct PathPat { 2396pub struct PathPat {
2247 pub(crate) syntax: SyntaxNode, 2397 pub(crate) syntax: SyntaxNode,
2248} 2398}
2249
2250impl AstNode for PathPat { 2399impl AstNode for PathPat {
2251 fn can_cast(kind: SyntaxKind) -> bool { 2400 fn can_cast(kind: SyntaxKind) -> bool {
2252 match kind { 2401 match kind {
@@ -2255,24 +2404,25 @@ impl AstNode for PathPat {
2255 } 2404 }
2256 } 2405 }
2257 fn cast(syntax: SyntaxNode) -> Option<Self> { 2406 fn cast(syntax: SyntaxNode) -> Option<Self> {
2258 if Self::can_cast(syntax.kind()) { Some(PathPat { syntax }) } else { None } 2407 if Self::can_cast(syntax.kind()) {
2408 Some(Self { syntax })
2409 } else {
2410 None
2411 }
2412 }
2413 fn syntax(&self) -> &SyntaxNode {
2414 &self.syntax
2259 } 2415 }
2260 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2261} 2416}
2262
2263
2264impl PathPat { 2417impl PathPat {
2265 pub fn path(&self) -> Option<Path> { 2418 pub fn path(&self) -> Option<Path> {
2266 super::child_opt(self) 2419 AstChildren::new(&self.syntax).next()
2267 } 2420 }
2268} 2421}
2269
2270// PathSegment
2271#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2422#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2272pub struct PathSegment { 2423pub struct PathSegment {
2273 pub(crate) syntax: SyntaxNode, 2424 pub(crate) syntax: SyntaxNode,
2274} 2425}
2275
2276impl AstNode for PathSegment { 2426impl AstNode for PathSegment {
2277 fn can_cast(kind: SyntaxKind) -> bool { 2427 fn can_cast(kind: SyntaxKind) -> bool {
2278 match kind { 2428 match kind {
@@ -2281,28 +2431,28 @@ impl AstNode for PathSegment {
2281 } 2431 }
2282 } 2432 }
2283 fn cast(syntax: SyntaxNode) -> Option<Self> { 2433 fn cast(syntax: SyntaxNode) -> Option<Self> {
2284 if Self::can_cast(syntax.kind()) { Some(PathSegment { syntax }) } else { None } 2434 if Self::can_cast(syntax.kind()) {
2435 Some(Self { syntax })
2436 } else {
2437 None
2438 }
2439 }
2440 fn syntax(&self) -> &SyntaxNode {
2441 &self.syntax
2285 } 2442 }
2286 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2287} 2443}
2288
2289
2290impl PathSegment { 2444impl PathSegment {
2291 pub fn name_ref(&self) -> Option<NameRef> { 2445 pub fn name_ref(&self) -> Option<NameRef> {
2292 super::child_opt(self) 2446 AstChildren::new(&self.syntax).next()
2293 } 2447 }
2294
2295 pub fn type_arg_list(&self) -> Option<TypeArgList> { 2448 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2296 super::child_opt(self) 2449 AstChildren::new(&self.syntax).next()
2297 } 2450 }
2298} 2451}
2299
2300// PathType
2301#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2452#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2302pub struct PathType { 2453pub struct PathType {
2303 pub(crate) syntax: SyntaxNode, 2454 pub(crate) syntax: SyntaxNode,
2304} 2455}
2305
2306impl AstNode for PathType { 2456impl AstNode for PathType {
2307 fn can_cast(kind: SyntaxKind) -> bool { 2457 fn can_cast(kind: SyntaxKind) -> bool {
2308 match kind { 2458 match kind {
@@ -2311,24 +2461,25 @@ impl AstNode for PathType {
2311 } 2461 }
2312 } 2462 }
2313 fn cast(syntax: SyntaxNode) -> Option<Self> { 2463 fn cast(syntax: SyntaxNode) -> Option<Self> {
2314 if Self::can_cast(syntax.kind()) { Some(PathType { syntax }) } else { None } 2464 if Self::can_cast(syntax.kind()) {
2465 Some(Self { syntax })
2466 } else {
2467 None
2468 }
2469 }
2470 fn syntax(&self) -> &SyntaxNode {
2471 &self.syntax
2315 } 2472 }
2316 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2317} 2473}
2318
2319
2320impl PathType { 2474impl PathType {
2321 pub fn path(&self) -> Option<Path> { 2475 pub fn path(&self) -> Option<Path> {
2322 super::child_opt(self) 2476 AstChildren::new(&self.syntax).next()
2323 } 2477 }
2324} 2478}
2325
2326// PlaceholderPat
2327#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2479#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2328pub struct PlaceholderPat { 2480pub struct PlaceholderPat {
2329 pub(crate) syntax: SyntaxNode, 2481 pub(crate) syntax: SyntaxNode,
2330} 2482}
2331
2332impl AstNode for PlaceholderPat { 2483impl AstNode for PlaceholderPat {
2333 fn can_cast(kind: SyntaxKind) -> bool { 2484 fn can_cast(kind: SyntaxKind) -> bool {
2334 match kind { 2485 match kind {
@@ -2337,20 +2488,21 @@ impl AstNode for PlaceholderPat {
2337 } 2488 }
2338 } 2489 }
2339 fn cast(syntax: SyntaxNode) -> Option<Self> { 2490 fn cast(syntax: SyntaxNode) -> Option<Self> {
2340 if Self::can_cast(syntax.kind()) { Some(PlaceholderPat { syntax }) } else { None } 2491 if Self::can_cast(syntax.kind()) {
2492 Some(Self { syntax })
2493 } else {
2494 None
2495 }
2496 }
2497 fn syntax(&self) -> &SyntaxNode {
2498 &self.syntax
2341 } 2499 }
2342 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2343} 2500}
2344
2345
2346impl PlaceholderPat {} 2501impl PlaceholderPat {}
2347
2348// PlaceholderType
2349#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2502#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2350pub struct PlaceholderType { 2503pub struct PlaceholderType {
2351 pub(crate) syntax: SyntaxNode, 2504 pub(crate) syntax: SyntaxNode,
2352} 2505}
2353
2354impl AstNode for PlaceholderType { 2506impl AstNode for PlaceholderType {
2355 fn can_cast(kind: SyntaxKind) -> bool { 2507 fn can_cast(kind: SyntaxKind) -> bool {
2356 match kind { 2508 match kind {
@@ -2359,20 +2511,21 @@ impl AstNode for PlaceholderType {
2359 } 2511 }
2360 } 2512 }
2361 fn cast(syntax: SyntaxNode) -> Option<Self> { 2513 fn cast(syntax: SyntaxNode) -> Option<Self> {
2362 if Self::can_cast(syntax.kind()) { Some(PlaceholderType { syntax }) } else { None } 2514 if Self::can_cast(syntax.kind()) {
2515 Some(Self { syntax })
2516 } else {
2517 None
2518 }
2519 }
2520 fn syntax(&self) -> &SyntaxNode {
2521 &self.syntax
2363 } 2522 }
2364 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2365} 2523}
2366
2367
2368impl PlaceholderType {} 2524impl PlaceholderType {}
2369
2370// PointerType
2371#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2525#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2372pub struct PointerType { 2526pub struct PointerType {
2373 pub(crate) syntax: SyntaxNode, 2527 pub(crate) syntax: SyntaxNode,
2374} 2528}
2375
2376impl AstNode for PointerType { 2529impl AstNode for PointerType {
2377 fn can_cast(kind: SyntaxKind) -> bool { 2530 fn can_cast(kind: SyntaxKind) -> bool {
2378 match kind { 2531 match kind {
@@ -2381,24 +2534,25 @@ impl AstNode for PointerType {
2381 } 2534 }
2382 } 2535 }
2383 fn cast(syntax: SyntaxNode) -> Option<Self> { 2536 fn cast(syntax: SyntaxNode) -> Option<Self> {
2384 if Self::can_cast(syntax.kind()) { Some(PointerType { syntax }) } else { None } 2537 if Self::can_cast(syntax.kind()) {
2538 Some(Self { syntax })
2539 } else {
2540 None
2541 }
2542 }
2543 fn syntax(&self) -> &SyntaxNode {
2544 &self.syntax
2385 } 2545 }
2386 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2387} 2546}
2388
2389
2390impl PointerType { 2547impl PointerType {
2391 pub fn type_ref(&self) -> Option<TypeRef> { 2548 pub fn type_ref(&self) -> Option<TypeRef> {
2392 super::child_opt(self) 2549 AstChildren::new(&self.syntax).next()
2393 } 2550 }
2394} 2551}
2395
2396// PosFieldDef
2397#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2552#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2398pub struct PosFieldDef { 2553pub struct PosFieldDef {
2399 pub(crate) syntax: SyntaxNode, 2554 pub(crate) syntax: SyntaxNode,
2400} 2555}
2401
2402impl AstNode for PosFieldDef { 2556impl AstNode for PosFieldDef {
2403 fn can_cast(kind: SyntaxKind) -> bool { 2557 fn can_cast(kind: SyntaxKind) -> bool {
2404 match kind { 2558 match kind {
@@ -2407,26 +2561,27 @@ impl AstNode for PosFieldDef {
2407 } 2561 }
2408 } 2562 }
2409 fn cast(syntax: SyntaxNode) -> Option<Self> { 2563 fn cast(syntax: SyntaxNode) -> Option<Self> {
2410 if Self::can_cast(syntax.kind()) { Some(PosFieldDef { syntax }) } else { None } 2564 if Self::can_cast(syntax.kind()) {
2565 Some(Self { syntax })
2566 } else {
2567 None
2568 }
2569 }
2570 fn syntax(&self) -> &SyntaxNode {
2571 &self.syntax
2411 } 2572 }
2412 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2413} 2573}
2414
2415
2416impl ast::VisibilityOwner for PosFieldDef {} 2574impl ast::VisibilityOwner for PosFieldDef {}
2417impl ast::AttrsOwner for PosFieldDef {} 2575impl ast::AttrsOwner for PosFieldDef {}
2418impl PosFieldDef { 2576impl PosFieldDef {
2419 pub fn type_ref(&self) -> Option<TypeRef> { 2577 pub fn type_ref(&self) -> Option<TypeRef> {
2420 super::child_opt(self) 2578 AstChildren::new(&self.syntax).next()
2421 } 2579 }
2422} 2580}
2423
2424// PosFieldDefList
2425#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2581#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2426pub struct PosFieldDefList { 2582pub struct PosFieldDefList {
2427 pub(crate) syntax: SyntaxNode, 2583 pub(crate) syntax: SyntaxNode,
2428} 2584}
2429
2430impl AstNode for PosFieldDefList { 2585impl AstNode for PosFieldDefList {
2431 fn can_cast(kind: SyntaxKind) -> bool { 2586 fn can_cast(kind: SyntaxKind) -> bool {
2432 match kind { 2587 match kind {
@@ -2435,24 +2590,25 @@ impl AstNode for PosFieldDefList {
2435 } 2590 }
2436 } 2591 }
2437 fn cast(syntax: SyntaxNode) -> Option<Self> { 2592 fn cast(syntax: SyntaxNode) -> Option<Self> {
2438 if Self::can_cast(syntax.kind()) { Some(PosFieldDefList { syntax }) } else { None } 2593 if Self::can_cast(syntax.kind()) {
2594 Some(Self { syntax })
2595 } else {
2596 None
2597 }
2598 }
2599 fn syntax(&self) -> &SyntaxNode {
2600 &self.syntax
2439 } 2601 }
2440 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2441} 2602}
2442
2443
2444impl PosFieldDefList { 2603impl PosFieldDefList {
2445 pub fn fields(&self) -> impl Iterator<Item = PosFieldDef> { 2604 pub fn fields(&self) -> AstChildren<PosFieldDef> {
2446 super::children(self) 2605 AstChildren::new(&self.syntax)
2447 } 2606 }
2448} 2607}
2449
2450// PrefixExpr
2451#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2608#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2452pub struct PrefixExpr { 2609pub struct PrefixExpr {
2453 pub(crate) syntax: SyntaxNode, 2610 pub(crate) syntax: SyntaxNode,
2454} 2611}
2455
2456impl AstNode for PrefixExpr { 2612impl AstNode for PrefixExpr {
2457 fn can_cast(kind: SyntaxKind) -> bool { 2613 fn can_cast(kind: SyntaxKind) -> bool {
2458 match kind { 2614 match kind {
@@ -2461,24 +2617,25 @@ impl AstNode for PrefixExpr {
2461 } 2617 }
2462 } 2618 }
2463 fn cast(syntax: SyntaxNode) -> Option<Self> { 2619 fn cast(syntax: SyntaxNode) -> Option<Self> {
2464 if Self::can_cast(syntax.kind()) { Some(PrefixExpr { syntax }) } else { None } 2620 if Self::can_cast(syntax.kind()) {
2621 Some(Self { syntax })
2622 } else {
2623 None
2624 }
2625 }
2626 fn syntax(&self) -> &SyntaxNode {
2627 &self.syntax
2465 } 2628 }
2466 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2467} 2629}
2468
2469
2470impl PrefixExpr { 2630impl PrefixExpr {
2471 pub fn expr(&self) -> Option<Expr> { 2631 pub fn expr(&self) -> Option<Expr> {
2472 super::child_opt(self) 2632 AstChildren::new(&self.syntax).next()
2473 } 2633 }
2474} 2634}
2475
2476// RangeExpr
2477#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2635#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2478pub struct RangeExpr { 2636pub struct RangeExpr {
2479 pub(crate) syntax: SyntaxNode, 2637 pub(crate) syntax: SyntaxNode,
2480} 2638}
2481
2482impl AstNode for RangeExpr { 2639impl AstNode for RangeExpr {
2483 fn can_cast(kind: SyntaxKind) -> bool { 2640 fn can_cast(kind: SyntaxKind) -> bool {
2484 match kind { 2641 match kind {
@@ -2487,20 +2644,21 @@ impl AstNode for RangeExpr {
2487 } 2644 }
2488 } 2645 }
2489 fn cast(syntax: SyntaxNode) -> Option<Self> { 2646 fn cast(syntax: SyntaxNode) -> Option<Self> {
2490 if Self::can_cast(syntax.kind()) { Some(RangeExpr { syntax }) } else { None } 2647 if Self::can_cast(syntax.kind()) {
2648 Some(Self { syntax })
2649 } else {
2650 None
2651 }
2652 }
2653 fn syntax(&self) -> &SyntaxNode {
2654 &self.syntax
2491 } 2655 }
2492 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2493} 2656}
2494
2495
2496impl RangeExpr {} 2657impl RangeExpr {}
2497
2498// RangePat
2499#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2658#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2500pub struct RangePat { 2659pub struct RangePat {
2501 pub(crate) syntax: SyntaxNode, 2660 pub(crate) syntax: SyntaxNode,
2502} 2661}
2503
2504impl AstNode for RangePat { 2662impl AstNode for RangePat {
2505 fn can_cast(kind: SyntaxKind) -> bool { 2663 fn can_cast(kind: SyntaxKind) -> bool {
2506 match kind { 2664 match kind {
@@ -2509,20 +2667,21 @@ impl AstNode for RangePat {
2509 } 2667 }
2510 } 2668 }
2511 fn cast(syntax: SyntaxNode) -> Option<Self> { 2669 fn cast(syntax: SyntaxNode) -> Option<Self> {
2512 if Self::can_cast(syntax.kind()) { Some(RangePat { syntax }) } else { None } 2670 if Self::can_cast(syntax.kind()) {
2671 Some(Self { syntax })
2672 } else {
2673 None
2674 }
2675 }
2676 fn syntax(&self) -> &SyntaxNode {
2677 &self.syntax
2513 } 2678 }
2514 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2515} 2679}
2516
2517
2518impl RangePat {} 2680impl RangePat {}
2519
2520// RefExpr
2521#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2681#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2522pub struct RefExpr { 2682pub struct RefExpr {
2523 pub(crate) syntax: SyntaxNode, 2683 pub(crate) syntax: SyntaxNode,
2524} 2684}
2525
2526impl AstNode for RefExpr { 2685impl AstNode for RefExpr {
2527 fn can_cast(kind: SyntaxKind) -> bool { 2686 fn can_cast(kind: SyntaxKind) -> bool {
2528 match kind { 2687 match kind {
@@ -2531,24 +2690,25 @@ impl AstNode for RefExpr {
2531 } 2690 }
2532 } 2691 }
2533 fn cast(syntax: SyntaxNode) -> Option<Self> { 2692 fn cast(syntax: SyntaxNode) -> Option<Self> {
2534 if Self::can_cast(syntax.kind()) { Some(RefExpr { syntax }) } else { None } 2693 if Self::can_cast(syntax.kind()) {
2694 Some(Self { syntax })
2695 } else {
2696 None
2697 }
2698 }
2699 fn syntax(&self) -> &SyntaxNode {
2700 &self.syntax
2535 } 2701 }
2536 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2537} 2702}
2538
2539
2540impl RefExpr { 2703impl RefExpr {
2541 pub fn expr(&self) -> Option<Expr> { 2704 pub fn expr(&self) -> Option<Expr> {
2542 super::child_opt(self) 2705 AstChildren::new(&self.syntax).next()
2543 } 2706 }
2544} 2707}
2545
2546// RefPat
2547#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2708#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2548pub struct RefPat { 2709pub struct RefPat {
2549 pub(crate) syntax: SyntaxNode, 2710 pub(crate) syntax: SyntaxNode,
2550} 2711}
2551
2552impl AstNode for RefPat { 2712impl AstNode for RefPat {
2553 fn can_cast(kind: SyntaxKind) -> bool { 2713 fn can_cast(kind: SyntaxKind) -> bool {
2554 match kind { 2714 match kind {
@@ -2557,24 +2717,25 @@ impl AstNode for RefPat {
2557 } 2717 }
2558 } 2718 }
2559 fn cast(syntax: SyntaxNode) -> Option<Self> { 2719 fn cast(syntax: SyntaxNode) -> Option<Self> {
2560 if Self::can_cast(syntax.kind()) { Some(RefPat { syntax }) } else { None } 2720 if Self::can_cast(syntax.kind()) {
2721 Some(Self { syntax })
2722 } else {
2723 None
2724 }
2725 }
2726 fn syntax(&self) -> &SyntaxNode {
2727 &self.syntax
2561 } 2728 }
2562 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2563} 2729}
2564
2565
2566impl RefPat { 2730impl RefPat {
2567 pub fn pat(&self) -> Option<Pat> { 2731 pub fn pat(&self) -> Option<Pat> {
2568 super::child_opt(self) 2732 AstChildren::new(&self.syntax).next()
2569 } 2733 }
2570} 2734}
2571
2572// ReferenceType
2573#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2735#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2574pub struct ReferenceType { 2736pub struct ReferenceType {
2575 pub(crate) syntax: SyntaxNode, 2737 pub(crate) syntax: SyntaxNode,
2576} 2738}
2577
2578impl AstNode for ReferenceType { 2739impl AstNode for ReferenceType {
2579 fn can_cast(kind: SyntaxKind) -> bool { 2740 fn can_cast(kind: SyntaxKind) -> bool {
2580 match kind { 2741 match kind {
@@ -2583,24 +2744,25 @@ impl AstNode for ReferenceType {
2583 } 2744 }
2584 } 2745 }
2585 fn cast(syntax: SyntaxNode) -> Option<Self> { 2746 fn cast(syntax: SyntaxNode) -> Option<Self> {
2586 if Self::can_cast(syntax.kind()) { Some(ReferenceType { syntax }) } else { None } 2747 if Self::can_cast(syntax.kind()) {
2748 Some(Self { syntax })
2749 } else {
2750 None
2751 }
2752 }
2753 fn syntax(&self) -> &SyntaxNode {
2754 &self.syntax
2587 } 2755 }
2588 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2589} 2756}
2590
2591
2592impl ReferenceType { 2757impl ReferenceType {
2593 pub fn type_ref(&self) -> Option<TypeRef> { 2758 pub fn type_ref(&self) -> Option<TypeRef> {
2594 super::child_opt(self) 2759 AstChildren::new(&self.syntax).next()
2595 } 2760 }
2596} 2761}
2597
2598// RetType
2599#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2762#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2600pub struct RetType { 2763pub struct RetType {
2601 pub(crate) syntax: SyntaxNode, 2764 pub(crate) syntax: SyntaxNode,
2602} 2765}
2603
2604impl AstNode for RetType { 2766impl AstNode for RetType {
2605 fn can_cast(kind: SyntaxKind) -> bool { 2767 fn can_cast(kind: SyntaxKind) -> bool {
2606 match kind { 2768 match kind {
@@ -2609,24 +2771,25 @@ impl AstNode for RetType {
2609 } 2771 }
2610 } 2772 }
2611 fn cast(syntax: SyntaxNode) -> Option<Self> { 2773 fn cast(syntax: SyntaxNode) -> Option<Self> {
2612 if Self::can_cast(syntax.kind()) { Some(RetType { syntax }) } else { None } 2774 if Self::can_cast(syntax.kind()) {
2775 Some(Self { syntax })
2776 } else {
2777 None
2778 }
2779 }
2780 fn syntax(&self) -> &SyntaxNode {
2781 &self.syntax
2613 } 2782 }
2614 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2615} 2783}
2616
2617
2618impl RetType { 2784impl RetType {
2619 pub fn type_ref(&self) -> Option<TypeRef> { 2785 pub fn type_ref(&self) -> Option<TypeRef> {
2620 super::child_opt(self) 2786 AstChildren::new(&self.syntax).next()
2621 } 2787 }
2622} 2788}
2623
2624// ReturnExpr
2625#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2789#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2626pub struct ReturnExpr { 2790pub struct ReturnExpr {
2627 pub(crate) syntax: SyntaxNode, 2791 pub(crate) syntax: SyntaxNode,
2628} 2792}
2629
2630impl AstNode for ReturnExpr { 2793impl AstNode for ReturnExpr {
2631 fn can_cast(kind: SyntaxKind) -> bool { 2794 fn can_cast(kind: SyntaxKind) -> bool {
2632 match kind { 2795 match kind {
@@ -2635,24 +2798,25 @@ impl AstNode for ReturnExpr {
2635 } 2798 }
2636 } 2799 }
2637 fn cast(syntax: SyntaxNode) -> Option<Self> { 2800 fn cast(syntax: SyntaxNode) -> Option<Self> {
2638 if Self::can_cast(syntax.kind()) { Some(ReturnExpr { syntax }) } else { None } 2801 if Self::can_cast(syntax.kind()) {
2802 Some(Self { syntax })
2803 } else {
2804 None
2805 }
2806 }
2807 fn syntax(&self) -> &SyntaxNode {
2808 &self.syntax
2639 } 2809 }
2640 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2641} 2810}
2642
2643
2644impl ReturnExpr { 2811impl ReturnExpr {
2645 pub fn expr(&self) -> Option<Expr> { 2812 pub fn expr(&self) -> Option<Expr> {
2646 super::child_opt(self) 2813 AstChildren::new(&self.syntax).next()
2647 } 2814 }
2648} 2815}
2649
2650// SelfParam
2651#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2816#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2652pub struct SelfParam { 2817pub struct SelfParam {
2653 pub(crate) syntax: SyntaxNode, 2818 pub(crate) syntax: SyntaxNode,
2654} 2819}
2655
2656impl AstNode for SelfParam { 2820impl AstNode for SelfParam {
2657 fn can_cast(kind: SyntaxKind) -> bool { 2821 fn can_cast(kind: SyntaxKind) -> bool {
2658 match kind { 2822 match kind {
@@ -2661,22 +2825,23 @@ impl AstNode for SelfParam {
2661 } 2825 }
2662 } 2826 }
2663 fn cast(syntax: SyntaxNode) -> Option<Self> { 2827 fn cast(syntax: SyntaxNode) -> Option<Self> {
2664 if Self::can_cast(syntax.kind()) { Some(SelfParam { syntax }) } else { None } 2828 if Self::can_cast(syntax.kind()) {
2829 Some(Self { syntax })
2830 } else {
2831 None
2832 }
2833 }
2834 fn syntax(&self) -> &SyntaxNode {
2835 &self.syntax
2665 } 2836 }
2666 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2667} 2837}
2668
2669
2670impl ast::TypeAscriptionOwner for SelfParam {} 2838impl ast::TypeAscriptionOwner for SelfParam {}
2671impl ast::AttrsOwner for SelfParam {} 2839impl ast::AttrsOwner for SelfParam {}
2672impl SelfParam {} 2840impl SelfParam {}
2673
2674// SlicePat
2675#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2841#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2676pub struct SlicePat { 2842pub struct SlicePat {
2677 pub(crate) syntax: SyntaxNode, 2843 pub(crate) syntax: SyntaxNode,
2678} 2844}
2679
2680impl AstNode for SlicePat { 2845impl AstNode for SlicePat {
2681 fn can_cast(kind: SyntaxKind) -> bool { 2846 fn can_cast(kind: SyntaxKind) -> bool {
2682 match kind { 2847 match kind {
@@ -2685,20 +2850,21 @@ impl AstNode for SlicePat {
2685 } 2850 }
2686 } 2851 }
2687 fn cast(syntax: SyntaxNode) -> Option<Self> { 2852 fn cast(syntax: SyntaxNode) -> Option<Self> {
2688 if Self::can_cast(syntax.kind()) { Some(SlicePat { syntax }) } else { None } 2853 if Self::can_cast(syntax.kind()) {
2854 Some(Self { syntax })
2855 } else {
2856 None
2857 }
2858 }
2859 fn syntax(&self) -> &SyntaxNode {
2860 &self.syntax
2689 } 2861 }
2690 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2691} 2862}
2692
2693
2694impl SlicePat {} 2863impl SlicePat {}
2695
2696// SliceType
2697#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2864#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2698pub struct SliceType { 2865pub struct SliceType {
2699 pub(crate) syntax: SyntaxNode, 2866 pub(crate) syntax: SyntaxNode,
2700} 2867}
2701
2702impl AstNode for SliceType { 2868impl AstNode for SliceType {
2703 fn can_cast(kind: SyntaxKind) -> bool { 2869 fn can_cast(kind: SyntaxKind) -> bool {
2704 match kind { 2870 match kind {
@@ -2707,24 +2873,25 @@ impl AstNode for SliceType {
2707 } 2873 }
2708 } 2874 }
2709 fn cast(syntax: SyntaxNode) -> Option<Self> { 2875 fn cast(syntax: SyntaxNode) -> Option<Self> {
2710 if Self::can_cast(syntax.kind()) { Some(SliceType { syntax }) } else { None } 2876 if Self::can_cast(syntax.kind()) {
2877 Some(Self { syntax })
2878 } else {
2879 None
2880 }
2881 }
2882 fn syntax(&self) -> &SyntaxNode {
2883 &self.syntax
2711 } 2884 }
2712 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2713} 2885}
2714
2715
2716impl SliceType { 2886impl SliceType {
2717 pub fn type_ref(&self) -> Option<TypeRef> { 2887 pub fn type_ref(&self) -> Option<TypeRef> {
2718 super::child_opt(self) 2888 AstChildren::new(&self.syntax).next()
2719 } 2889 }
2720} 2890}
2721
2722// SourceFile
2723#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2891#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2724pub struct SourceFile { 2892pub struct SourceFile {
2725 pub(crate) syntax: SyntaxNode, 2893 pub(crate) syntax: SyntaxNode,
2726} 2894}
2727
2728impl AstNode for SourceFile { 2895impl AstNode for SourceFile {
2729 fn can_cast(kind: SyntaxKind) -> bool { 2896 fn can_cast(kind: SyntaxKind) -> bool {
2730 match kind { 2897 match kind {
@@ -2733,26 +2900,27 @@ impl AstNode for SourceFile {
2733 } 2900 }
2734 } 2901 }
2735 fn cast(syntax: SyntaxNode) -> Option<Self> { 2902 fn cast(syntax: SyntaxNode) -> Option<Self> {
2736 if Self::can_cast(syntax.kind()) { Some(SourceFile { syntax }) } else { None } 2903 if Self::can_cast(syntax.kind()) {
2904 Some(Self { syntax })
2905 } else {
2906 None
2907 }
2908 }
2909 fn syntax(&self) -> &SyntaxNode {
2910 &self.syntax
2737 } 2911 }
2738 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2739} 2912}
2740
2741
2742impl ast::ModuleItemOwner for SourceFile {} 2913impl ast::ModuleItemOwner for SourceFile {}
2743impl ast::FnDefOwner for SourceFile {} 2914impl ast::FnDefOwner for SourceFile {}
2744impl SourceFile { 2915impl SourceFile {
2745 pub fn modules(&self) -> impl Iterator<Item = Module> { 2916 pub fn modules(&self) -> AstChildren<Module> {
2746 super::children(self) 2917 AstChildren::new(&self.syntax)
2747 } 2918 }
2748} 2919}
2749
2750// StaticDef
2751#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2920#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2752pub struct StaticDef { 2921pub struct StaticDef {
2753 pub(crate) syntax: SyntaxNode, 2922 pub(crate) syntax: SyntaxNode,
2754} 2923}
2755
2756impl AstNode for StaticDef { 2924impl AstNode for StaticDef {
2757 fn can_cast(kind: SyntaxKind) -> bool { 2925 fn can_cast(kind: SyntaxKind) -> bool {
2758 match kind { 2926 match kind {
@@ -2761,12 +2929,16 @@ impl AstNode for StaticDef {
2761 } 2929 }
2762 } 2930 }
2763 fn cast(syntax: SyntaxNode) -> Option<Self> { 2931 fn cast(syntax: SyntaxNode) -> Option<Self> {
2764 if Self::can_cast(syntax.kind()) { Some(StaticDef { syntax }) } else { None } 2932 if Self::can_cast(syntax.kind()) {
2933 Some(Self { syntax })
2934 } else {
2935 None
2936 }
2937 }
2938 fn syntax(&self) -> &SyntaxNode {
2939 &self.syntax
2765 } 2940 }
2766 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2767} 2941}
2768
2769
2770impl ast::VisibilityOwner for StaticDef {} 2942impl ast::VisibilityOwner for StaticDef {}
2771impl ast::NameOwner for StaticDef {} 2943impl ast::NameOwner for StaticDef {}
2772impl ast::TypeParamsOwner for StaticDef {} 2944impl ast::TypeParamsOwner for StaticDef {}
@@ -2775,59 +2947,60 @@ impl ast::DocCommentsOwner for StaticDef {}
2775impl ast::TypeAscriptionOwner for StaticDef {} 2947impl ast::TypeAscriptionOwner for StaticDef {}
2776impl StaticDef { 2948impl StaticDef {
2777 pub fn body(&self) -> Option<Expr> { 2949 pub fn body(&self) -> Option<Expr> {
2778 super::child_opt(self) 2950 AstChildren::new(&self.syntax).next()
2779 } 2951 }
2780} 2952}
2781
2782// Stmt
2783#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2953#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2784pub struct Stmt { 2954pub struct Stmt {
2785 pub(crate) syntax: SyntaxNode, 2955 pub(crate) syntax: SyntaxNode,
2786} 2956}
2787
2788impl AstNode for Stmt { 2957impl AstNode for Stmt {
2789 fn can_cast(kind: SyntaxKind) -> bool { 2958 fn can_cast(kind: SyntaxKind) -> bool {
2790 match kind { 2959 match kind {
2791 | EXPR_STMT | LET_STMT => true, 2960 EXPR_STMT | LET_STMT => true,
2792 _ => false, 2961 _ => false,
2793 } 2962 }
2794 } 2963 }
2795 fn cast(syntax: SyntaxNode) -> Option<Self> { 2964 fn cast(syntax: SyntaxNode) -> Option<Self> {
2796 if Self::can_cast(syntax.kind()) { Some(Stmt { syntax }) } else { None } 2965 if Self::can_cast(syntax.kind()) {
2966 Some(Self { syntax })
2967 } else {
2968 None
2969 }
2970 }
2971 fn syntax(&self) -> &SyntaxNode {
2972 &self.syntax
2797 } 2973 }
2798 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2799} 2974}
2800
2801
2802#[derive(Debug, Clone, PartialEq, Eq)]
2803pub enum StmtKind { 2975pub enum StmtKind {
2804 ExprStmt(ExprStmt), 2976 ExprStmt(ExprStmt),
2805 LetStmt(LetStmt), 2977 LetStmt(LetStmt),
2806} 2978}
2807impl From<ExprStmt> for Stmt { 2979impl From<ExprStmt> for Stmt {
2808 fn from(n: ExprStmt) -> Stmt { Stmt { syntax: n.syntax } } 2980 fn from(node: ExprStmt) -> Stmt {
2981 Stmt { syntax: node.syntax }
2982 }
2809} 2983}
2810impl From<LetStmt> for Stmt { 2984impl From<LetStmt> for Stmt {
2811 fn from(n: LetStmt) -> Stmt { Stmt { syntax: n.syntax } } 2985 fn from(node: LetStmt) -> Stmt {
2986 Stmt { syntax: node.syntax }
2987 }
2812} 2988}
2813impl Stmt { 2989impl Stmt {
2814 pub fn kind(&self) -> StmtKind { 2990 pub fn kind(&self) -> StmtKind {
2815 match self.syntax.kind() { 2991 let syntax = self.syntax.clone();
2816 EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(self.syntax.clone()).unwrap()), 2992 match syntax.kind() {
2817 LET_STMT => StmtKind::LetStmt(LetStmt::cast(self.syntax.clone()).unwrap()), 2993 EXPR_STMT => StmtKind::ExprStmt(ExprStmt { syntax }),
2994 LET_STMT => StmtKind::LetStmt(LetStmt { syntax }),
2818 _ => unreachable!(), 2995 _ => unreachable!(),
2819 } 2996 }
2820 } 2997 }
2821} 2998}
2822
2823impl Stmt {} 2999impl Stmt {}
2824
2825// StructDef
2826#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3000#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2827pub struct StructDef { 3001pub struct StructDef {
2828 pub(crate) syntax: SyntaxNode, 3002 pub(crate) syntax: SyntaxNode,
2829} 3003}
2830
2831impl AstNode for StructDef { 3004impl AstNode for StructDef {
2832 fn can_cast(kind: SyntaxKind) -> bool { 3005 fn can_cast(kind: SyntaxKind) -> bool {
2833 match kind { 3006 match kind {
@@ -2836,25 +3009,26 @@ impl AstNode for StructDef {
2836 } 3009 }
2837 } 3010 }
2838 fn cast(syntax: SyntaxNode) -> Option<Self> { 3011 fn cast(syntax: SyntaxNode) -> Option<Self> {
2839 if Self::can_cast(syntax.kind()) { Some(StructDef { syntax }) } else { None } 3012 if Self::can_cast(syntax.kind()) {
3013 Some(Self { syntax })
3014 } else {
3015 None
3016 }
3017 }
3018 fn syntax(&self) -> &SyntaxNode {
3019 &self.syntax
2840 } 3020 }
2841 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2842} 3021}
2843
2844
2845impl ast::VisibilityOwner for StructDef {} 3022impl ast::VisibilityOwner for StructDef {}
2846impl ast::NameOwner for StructDef {} 3023impl ast::NameOwner for StructDef {}
2847impl ast::TypeParamsOwner for StructDef {} 3024impl ast::TypeParamsOwner for StructDef {}
2848impl ast::AttrsOwner for StructDef {} 3025impl ast::AttrsOwner for StructDef {}
2849impl ast::DocCommentsOwner for StructDef {} 3026impl ast::DocCommentsOwner for StructDef {}
2850impl StructDef {} 3027impl StructDef {}
2851
2852// StructLit
2853#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3028#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2854pub struct StructLit { 3029pub struct StructLit {
2855 pub(crate) syntax: SyntaxNode, 3030 pub(crate) syntax: SyntaxNode,
2856} 3031}
2857
2858impl AstNode for StructLit { 3032impl AstNode for StructLit {
2859 fn can_cast(kind: SyntaxKind) -> bool { 3033 fn can_cast(kind: SyntaxKind) -> bool {
2860 match kind { 3034 match kind {
@@ -2863,28 +3037,28 @@ impl AstNode for StructLit {
2863 } 3037 }
2864 } 3038 }
2865 fn cast(syntax: SyntaxNode) -> Option<Self> { 3039 fn cast(syntax: SyntaxNode) -> Option<Self> {
2866 if Self::can_cast(syntax.kind()) { Some(StructLit { syntax }) } else { None } 3040 if Self::can_cast(syntax.kind()) {
3041 Some(Self { syntax })
3042 } else {
3043 None
3044 }
3045 }
3046 fn syntax(&self) -> &SyntaxNode {
3047 &self.syntax
2867 } 3048 }
2868 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2869} 3049}
2870
2871
2872impl StructLit { 3050impl StructLit {
2873 pub fn path(&self) -> Option<Path> { 3051 pub fn path(&self) -> Option<Path> {
2874 super::child_opt(self) 3052 AstChildren::new(&self.syntax).next()
2875 } 3053 }
2876
2877 pub fn named_field_list(&self) -> Option<NamedFieldList> { 3054 pub fn named_field_list(&self) -> Option<NamedFieldList> {
2878 super::child_opt(self) 3055 AstChildren::new(&self.syntax).next()
2879 } 3056 }
2880} 3057}
2881
2882// StructPat
2883#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3058#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2884pub struct StructPat { 3059pub struct StructPat {
2885 pub(crate) syntax: SyntaxNode, 3060 pub(crate) syntax: SyntaxNode,
2886} 3061}
2887
2888impl AstNode for StructPat { 3062impl AstNode for StructPat {
2889 fn can_cast(kind: SyntaxKind) -> bool { 3063 fn can_cast(kind: SyntaxKind) -> bool {
2890 match kind { 3064 match kind {
@@ -2893,28 +3067,28 @@ impl AstNode for StructPat {
2893 } 3067 }
2894 } 3068 }
2895 fn cast(syntax: SyntaxNode) -> Option<Self> { 3069 fn cast(syntax: SyntaxNode) -> Option<Self> {
2896 if Self::can_cast(syntax.kind()) { Some(StructPat { syntax }) } else { None } 3070 if Self::can_cast(syntax.kind()) {
3071 Some(Self { syntax })
3072 } else {
3073 None
3074 }
3075 }
3076 fn syntax(&self) -> &SyntaxNode {
3077 &self.syntax
2897 } 3078 }
2898 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2899} 3079}
2900
2901
2902impl StructPat { 3080impl StructPat {
2903 pub fn field_pat_list(&self) -> Option<FieldPatList> { 3081 pub fn field_pat_list(&self) -> Option<FieldPatList> {
2904 super::child_opt(self) 3082 AstChildren::new(&self.syntax).next()
2905 } 3083 }
2906
2907 pub fn path(&self) -> Option<Path> { 3084 pub fn path(&self) -> Option<Path> {
2908 super::child_opt(self) 3085 AstChildren::new(&self.syntax).next()
2909 } 3086 }
2910} 3087}
2911
2912// TokenTree
2913#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3088#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2914pub struct TokenTree { 3089pub struct TokenTree {
2915 pub(crate) syntax: SyntaxNode, 3090 pub(crate) syntax: SyntaxNode,
2916} 3091}
2917
2918impl AstNode for TokenTree { 3092impl AstNode for TokenTree {
2919 fn can_cast(kind: SyntaxKind) -> bool { 3093 fn can_cast(kind: SyntaxKind) -> bool {
2920 match kind { 3094 match kind {
@@ -2923,20 +3097,21 @@ impl AstNode for TokenTree {
2923 } 3097 }
2924 } 3098 }
2925 fn cast(syntax: SyntaxNode) -> Option<Self> { 3099 fn cast(syntax: SyntaxNode) -> Option<Self> {
2926 if Self::can_cast(syntax.kind()) { Some(TokenTree { syntax }) } else { None } 3100 if Self::can_cast(syntax.kind()) {
3101 Some(Self { syntax })
3102 } else {
3103 None
3104 }
3105 }
3106 fn syntax(&self) -> &SyntaxNode {
3107 &self.syntax
2927 } 3108 }
2928 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2929} 3109}
2930
2931
2932impl TokenTree {} 3110impl TokenTree {}
2933
2934// TraitDef
2935#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3111#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2936pub struct TraitDef { 3112pub struct TraitDef {
2937 pub(crate) syntax: SyntaxNode, 3113 pub(crate) syntax: SyntaxNode,
2938} 3114}
2939
2940impl AstNode for TraitDef { 3115impl AstNode for TraitDef {
2941 fn can_cast(kind: SyntaxKind) -> bool { 3116 fn can_cast(kind: SyntaxKind) -> bool {
2942 match kind { 3117 match kind {
@@ -2945,12 +3120,16 @@ impl AstNode for TraitDef {
2945 } 3120 }
2946 } 3121 }
2947 fn cast(syntax: SyntaxNode) -> Option<Self> { 3122 fn cast(syntax: SyntaxNode) -> Option<Self> {
2948 if Self::can_cast(syntax.kind()) { Some(TraitDef { syntax }) } else { None } 3123 if Self::can_cast(syntax.kind()) {
3124 Some(Self { syntax })
3125 } else {
3126 None
3127 }
3128 }
3129 fn syntax(&self) -> &SyntaxNode {
3130 &self.syntax
2949 } 3131 }
2950 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2951} 3132}
2952
2953
2954impl ast::VisibilityOwner for TraitDef {} 3133impl ast::VisibilityOwner for TraitDef {}
2955impl ast::NameOwner for TraitDef {} 3134impl ast::NameOwner for TraitDef {}
2956impl ast::AttrsOwner for TraitDef {} 3135impl ast::AttrsOwner for TraitDef {}
@@ -2959,16 +3138,13 @@ impl ast::TypeParamsOwner for TraitDef {}
2959impl ast::TypeBoundsOwner for TraitDef {} 3138impl ast::TypeBoundsOwner for TraitDef {}
2960impl TraitDef { 3139impl TraitDef {
2961 pub fn item_list(&self) -> Option<ItemList> { 3140 pub fn item_list(&self) -> Option<ItemList> {
2962 super::child_opt(self) 3141 AstChildren::new(&self.syntax).next()
2963 } 3142 }
2964} 3143}
2965
2966// TryBlockExpr
2967#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3144#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2968pub struct TryBlockExpr { 3145pub struct TryBlockExpr {
2969 pub(crate) syntax: SyntaxNode, 3146 pub(crate) syntax: SyntaxNode,
2970} 3147}
2971
2972impl AstNode for TryBlockExpr { 3148impl AstNode for TryBlockExpr {
2973 fn can_cast(kind: SyntaxKind) -> bool { 3149 fn can_cast(kind: SyntaxKind) -> bool {
2974 match kind { 3150 match kind {
@@ -2977,21 +3153,22 @@ impl AstNode for TryBlockExpr {
2977 } 3153 }
2978 } 3154 }
2979 fn cast(syntax: SyntaxNode) -> Option<Self> { 3155 fn cast(syntax: SyntaxNode) -> Option<Self> {
2980 if Self::can_cast(syntax.kind()) { Some(TryBlockExpr { syntax }) } else { None } 3156 if Self::can_cast(syntax.kind()) {
3157 Some(Self { syntax })
3158 } else {
3159 None
3160 }
3161 }
3162 fn syntax(&self) -> &SyntaxNode {
3163 &self.syntax
2981 } 3164 }
2982 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2983} 3165}
2984
2985
2986impl ast::TryBlockBodyOwner for TryBlockExpr {} 3166impl ast::TryBlockBodyOwner for TryBlockExpr {}
2987impl TryBlockExpr {} 3167impl TryBlockExpr {}
2988
2989// TryExpr
2990#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3168#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2991pub struct TryExpr { 3169pub struct TryExpr {
2992 pub(crate) syntax: SyntaxNode, 3170 pub(crate) syntax: SyntaxNode,
2993} 3171}
2994
2995impl AstNode for TryExpr { 3172impl AstNode for TryExpr {
2996 fn can_cast(kind: SyntaxKind) -> bool { 3173 fn can_cast(kind: SyntaxKind) -> bool {
2997 match kind { 3174 match kind {
@@ -3000,24 +3177,25 @@ impl AstNode for TryExpr {
3000 } 3177 }
3001 } 3178 }
3002 fn cast(syntax: SyntaxNode) -> Option<Self> { 3179 fn cast(syntax: SyntaxNode) -> Option<Self> {
3003 if Self::can_cast(syntax.kind()) { Some(TryExpr { syntax }) } else { None } 3180 if Self::can_cast(syntax.kind()) {
3181 Some(Self { syntax })
3182 } else {
3183 None
3184 }
3185 }
3186 fn syntax(&self) -> &SyntaxNode {
3187 &self.syntax
3004 } 3188 }
3005 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3006} 3189}
3007
3008
3009impl TryExpr { 3190impl TryExpr {
3010 pub fn expr(&self) -> Option<Expr> { 3191 pub fn expr(&self) -> Option<Expr> {
3011 super::child_opt(self) 3192 AstChildren::new(&self.syntax).next()
3012 } 3193 }
3013} 3194}
3014
3015// TupleExpr
3016#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3195#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3017pub struct TupleExpr { 3196pub struct TupleExpr {
3018 pub(crate) syntax: SyntaxNode, 3197 pub(crate) syntax: SyntaxNode,
3019} 3198}
3020
3021impl AstNode for TupleExpr { 3199impl AstNode for TupleExpr {
3022 fn can_cast(kind: SyntaxKind) -> bool { 3200 fn can_cast(kind: SyntaxKind) -> bool {
3023 match kind { 3201 match kind {
@@ -3026,24 +3204,25 @@ impl AstNode for TupleExpr {
3026 } 3204 }
3027 } 3205 }
3028 fn cast(syntax: SyntaxNode) -> Option<Self> { 3206 fn cast(syntax: SyntaxNode) -> Option<Self> {
3029 if Self::can_cast(syntax.kind()) { Some(TupleExpr { syntax }) } else { None } 3207 if Self::can_cast(syntax.kind()) {
3208 Some(Self { syntax })
3209 } else {
3210 None
3211 }
3212 }
3213 fn syntax(&self) -> &SyntaxNode {
3214 &self.syntax
3030 } 3215 }
3031 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3032} 3216}
3033
3034
3035impl TupleExpr { 3217impl TupleExpr {
3036 pub fn exprs(&self) -> impl Iterator<Item = Expr> { 3218 pub fn exprs(&self) -> AstChildren<Expr> {
3037 super::children(self) 3219 AstChildren::new(&self.syntax)
3038 } 3220 }
3039} 3221}
3040
3041// TuplePat
3042#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3222#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3043pub struct TuplePat { 3223pub struct TuplePat {
3044 pub(crate) syntax: SyntaxNode, 3224 pub(crate) syntax: SyntaxNode,
3045} 3225}
3046
3047impl AstNode for TuplePat { 3226impl AstNode for TuplePat {
3048 fn can_cast(kind: SyntaxKind) -> bool { 3227 fn can_cast(kind: SyntaxKind) -> bool {
3049 match kind { 3228 match kind {
@@ -3052,24 +3231,25 @@ impl AstNode for TuplePat {
3052 } 3231 }
3053 } 3232 }
3054 fn cast(syntax: SyntaxNode) -> Option<Self> { 3233 fn cast(syntax: SyntaxNode) -> Option<Self> {
3055 if Self::can_cast(syntax.kind()) { Some(TuplePat { syntax }) } else { None } 3234 if Self::can_cast(syntax.kind()) {
3235 Some(Self { syntax })
3236 } else {
3237 None
3238 }
3239 }
3240 fn syntax(&self) -> &SyntaxNode {
3241 &self.syntax
3056 } 3242 }
3057 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3058} 3243}
3059
3060
3061impl TuplePat { 3244impl TuplePat {
3062 pub fn args(&self) -> impl Iterator<Item = Pat> { 3245 pub fn args(&self) -> AstChildren<Pat> {
3063 super::children(self) 3246 AstChildren::new(&self.syntax)
3064 } 3247 }
3065} 3248}
3066
3067// TupleStructPat
3068#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3249#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3069pub struct TupleStructPat { 3250pub struct TupleStructPat {
3070 pub(crate) syntax: SyntaxNode, 3251 pub(crate) syntax: SyntaxNode,
3071} 3252}
3072
3073impl AstNode for TupleStructPat { 3253impl AstNode for TupleStructPat {
3074 fn can_cast(kind: SyntaxKind) -> bool { 3254 fn can_cast(kind: SyntaxKind) -> bool {
3075 match kind { 3255 match kind {
@@ -3078,28 +3258,28 @@ impl AstNode for TupleStructPat {
3078 } 3258 }
3079 } 3259 }
3080 fn cast(syntax: SyntaxNode) -> Option<Self> { 3260 fn cast(syntax: SyntaxNode) -> Option<Self> {
3081 if Self::can_cast(syntax.kind()) { Some(TupleStructPat { syntax }) } else { None } 3261 if Self::can_cast(syntax.kind()) {
3262 Some(Self { syntax })
3263 } else {
3264 None
3265 }
3266 }
3267 fn syntax(&self) -> &SyntaxNode {
3268 &self.syntax
3082 } 3269 }
3083 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3084} 3270}
3085
3086
3087impl TupleStructPat { 3271impl TupleStructPat {
3088 pub fn args(&self) -> impl Iterator<Item = Pat> { 3272 pub fn args(&self) -> AstChildren<Pat> {
3089 super::children(self) 3273 AstChildren::new(&self.syntax)
3090 } 3274 }
3091
3092 pub fn path(&self) -> Option<Path> { 3275 pub fn path(&self) -> Option<Path> {
3093 super::child_opt(self) 3276 AstChildren::new(&self.syntax).next()
3094 } 3277 }
3095} 3278}
3096
3097// TupleType
3098#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3279#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3099pub struct TupleType { 3280pub struct TupleType {
3100 pub(crate) syntax: SyntaxNode, 3281 pub(crate) syntax: SyntaxNode,
3101} 3282}
3102
3103impl AstNode for TupleType { 3283impl AstNode for TupleType {
3104 fn can_cast(kind: SyntaxKind) -> bool { 3284 fn can_cast(kind: SyntaxKind) -> bool {
3105 match kind { 3285 match kind {
@@ -3108,24 +3288,25 @@ impl AstNode for TupleType {
3108 } 3288 }
3109 } 3289 }
3110 fn cast(syntax: SyntaxNode) -> Option<Self> { 3290 fn cast(syntax: SyntaxNode) -> Option<Self> {
3111 if Self::can_cast(syntax.kind()) { Some(TupleType { syntax }) } else { None } 3291 if Self::can_cast(syntax.kind()) {
3292 Some(Self { syntax })
3293 } else {
3294 None
3295 }
3296 }
3297 fn syntax(&self) -> &SyntaxNode {
3298 &self.syntax
3112 } 3299 }
3113 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3114} 3300}
3115
3116
3117impl TupleType { 3301impl TupleType {
3118 pub fn fields(&self) -> impl Iterator<Item = TypeRef> { 3302 pub fn fields(&self) -> AstChildren<TypeRef> {
3119 super::children(self) 3303 AstChildren::new(&self.syntax)
3120 } 3304 }
3121} 3305}
3122
3123// TypeAliasDef
3124#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3306#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3125pub struct TypeAliasDef { 3307pub struct TypeAliasDef {
3126 pub(crate) syntax: SyntaxNode, 3308 pub(crate) syntax: SyntaxNode,
3127} 3309}
3128
3129impl AstNode for TypeAliasDef { 3310impl AstNode for TypeAliasDef {
3130 fn can_cast(kind: SyntaxKind) -> bool { 3311 fn can_cast(kind: SyntaxKind) -> bool {
3131 match kind { 3312 match kind {
@@ -3134,12 +3315,16 @@ impl AstNode for TypeAliasDef {
3134 } 3315 }
3135 } 3316 }
3136 fn cast(syntax: SyntaxNode) -> Option<Self> { 3317 fn cast(syntax: SyntaxNode) -> Option<Self> {
3137 if Self::can_cast(syntax.kind()) { Some(TypeAliasDef { syntax }) } else { None } 3318 if Self::can_cast(syntax.kind()) {
3319 Some(Self { syntax })
3320 } else {
3321 None
3322 }
3323 }
3324 fn syntax(&self) -> &SyntaxNode {
3325 &self.syntax
3138 } 3326 }
3139 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3140} 3327}
3141
3142
3143impl ast::VisibilityOwner for TypeAliasDef {} 3328impl ast::VisibilityOwner for TypeAliasDef {}
3144impl ast::NameOwner for TypeAliasDef {} 3329impl ast::NameOwner for TypeAliasDef {}
3145impl ast::TypeParamsOwner for TypeAliasDef {} 3330impl ast::TypeParamsOwner for TypeAliasDef {}
@@ -3148,16 +3333,13 @@ impl ast::DocCommentsOwner for TypeAliasDef {}
3148impl ast::TypeBoundsOwner for TypeAliasDef {} 3333impl ast::TypeBoundsOwner for TypeAliasDef {}
3149impl TypeAliasDef { 3334impl TypeAliasDef {
3150 pub fn type_ref(&self) -> Option<TypeRef> { 3335 pub fn type_ref(&self) -> Option<TypeRef> {
3151 super::child_opt(self) 3336 AstChildren::new(&self.syntax).next()
3152 } 3337 }
3153} 3338}
3154
3155// TypeArg
3156#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3339#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3157pub struct TypeArg { 3340pub struct TypeArg {
3158 pub(crate) syntax: SyntaxNode, 3341 pub(crate) syntax: SyntaxNode,
3159} 3342}
3160
3161impl AstNode for TypeArg { 3343impl AstNode for TypeArg {
3162 fn can_cast(kind: SyntaxKind) -> bool { 3344 fn can_cast(kind: SyntaxKind) -> bool {
3163 match kind { 3345 match kind {
@@ -3166,24 +3348,25 @@ impl AstNode for TypeArg {
3166 } 3348 }
3167 } 3349 }
3168 fn cast(syntax: SyntaxNode) -> Option<Self> { 3350 fn cast(syntax: SyntaxNode) -> Option<Self> {
3169 if Self::can_cast(syntax.kind()) { Some(TypeArg { syntax }) } else { None } 3351 if Self::can_cast(syntax.kind()) {
3352 Some(Self { syntax })
3353 } else {
3354 None
3355 }
3356 }
3357 fn syntax(&self) -> &SyntaxNode {
3358 &self.syntax
3170 } 3359 }
3171 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3172} 3360}
3173
3174
3175impl TypeArg { 3361impl TypeArg {
3176 pub fn type_ref(&self) -> Option<TypeRef> { 3362 pub fn type_ref(&self) -> Option<TypeRef> {
3177 super::child_opt(self) 3363 AstChildren::new(&self.syntax).next()
3178 } 3364 }
3179} 3365}
3180
3181// TypeArgList
3182#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3366#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3183pub struct TypeArgList { 3367pub struct TypeArgList {
3184 pub(crate) syntax: SyntaxNode, 3368 pub(crate) syntax: SyntaxNode,
3185} 3369}
3186
3187impl AstNode for TypeArgList { 3370impl AstNode for TypeArgList {
3188 fn can_cast(kind: SyntaxKind) -> bool { 3371 fn can_cast(kind: SyntaxKind) -> bool {
3189 match kind { 3372 match kind {
@@ -3192,32 +3375,31 @@ impl AstNode for TypeArgList {
3192 } 3375 }
3193 } 3376 }
3194 fn cast(syntax: SyntaxNode) -> Option<Self> { 3377 fn cast(syntax: SyntaxNode) -> Option<Self> {
3195 if Self::can_cast(syntax.kind()) { Some(TypeArgList { syntax }) } else { None } 3378 if Self::can_cast(syntax.kind()) {
3379 Some(Self { syntax })
3380 } else {
3381 None
3382 }
3383 }
3384 fn syntax(&self) -> &SyntaxNode {
3385 &self.syntax
3196 } 3386 }
3197 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3198} 3387}
3199
3200
3201impl TypeArgList { 3388impl TypeArgList {
3202 pub fn type_args(&self) -> impl Iterator<Item = TypeArg> { 3389 pub fn type_args(&self) -> AstChildren<TypeArg> {
3203 super::children(self) 3390 AstChildren::new(&self.syntax)
3204 } 3391 }
3205 3392 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3206 pub fn lifetime_args(&self) -> impl Iterator<Item = LifetimeArg> { 3393 AstChildren::new(&self.syntax)
3207 super::children(self)
3208 } 3394 }
3209 3395 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3210 pub fn assoc_type_args(&self) -> impl Iterator<Item = AssocTypeArg> { 3396 AstChildren::new(&self.syntax)
3211 super::children(self)
3212 } 3397 }
3213} 3398}
3214
3215// TypeBound
3216#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3399#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3217pub struct TypeBound { 3400pub struct TypeBound {
3218 pub(crate) syntax: SyntaxNode, 3401 pub(crate) syntax: SyntaxNode,
3219} 3402}
3220
3221impl AstNode for TypeBound { 3403impl AstNode for TypeBound {
3222 fn can_cast(kind: SyntaxKind) -> bool { 3404 fn can_cast(kind: SyntaxKind) -> bool {
3223 match kind { 3405 match kind {
@@ -3226,24 +3408,25 @@ impl AstNode for TypeBound {
3226 } 3408 }
3227 } 3409 }
3228 fn cast(syntax: SyntaxNode) -> Option<Self> { 3410 fn cast(syntax: SyntaxNode) -> Option<Self> {
3229 if Self::can_cast(syntax.kind()) { Some(TypeBound { syntax }) } else { None } 3411 if Self::can_cast(syntax.kind()) {
3412 Some(Self { syntax })
3413 } else {
3414 None
3415 }
3416 }
3417 fn syntax(&self) -> &SyntaxNode {
3418 &self.syntax
3230 } 3419 }
3231 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3232} 3420}
3233
3234
3235impl TypeBound { 3421impl TypeBound {
3236 pub fn type_ref(&self) -> Option<TypeRef> { 3422 pub fn type_ref(&self) -> Option<TypeRef> {
3237 super::child_opt(self) 3423 AstChildren::new(&self.syntax).next()
3238 } 3424 }
3239} 3425}
3240
3241// TypeBoundList
3242#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3426#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3243pub struct TypeBoundList { 3427pub struct TypeBoundList {
3244 pub(crate) syntax: SyntaxNode, 3428 pub(crate) syntax: SyntaxNode,
3245} 3429}
3246
3247impl AstNode for TypeBoundList { 3430impl AstNode for TypeBoundList {
3248 fn can_cast(kind: SyntaxKind) -> bool { 3431 fn can_cast(kind: SyntaxKind) -> bool {
3249 match kind { 3432 match kind {
@@ -3252,24 +3435,25 @@ impl AstNode for TypeBoundList {
3252 } 3435 }
3253 } 3436 }
3254 fn cast(syntax: SyntaxNode) -> Option<Self> { 3437 fn cast(syntax: SyntaxNode) -> Option<Self> {
3255 if Self::can_cast(syntax.kind()) { Some(TypeBoundList { syntax }) } else { None } 3438 if Self::can_cast(syntax.kind()) {
3439 Some(Self { syntax })
3440 } else {
3441 None
3442 }
3443 }
3444 fn syntax(&self) -> &SyntaxNode {
3445 &self.syntax
3256 } 3446 }
3257 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3258} 3447}
3259
3260
3261impl TypeBoundList { 3448impl TypeBoundList {
3262 pub fn bounds(&self) -> impl Iterator<Item = TypeBound> { 3449 pub fn bounds(&self) -> AstChildren<TypeBound> {
3263 super::children(self) 3450 AstChildren::new(&self.syntax)
3264 } 3451 }
3265} 3452}
3266
3267// TypeParam
3268#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3453#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3269pub struct TypeParam { 3454pub struct TypeParam {
3270 pub(crate) syntax: SyntaxNode, 3455 pub(crate) syntax: SyntaxNode,
3271} 3456}
3272
3273impl AstNode for TypeParam { 3457impl AstNode for TypeParam {
3274 fn can_cast(kind: SyntaxKind) -> bool { 3458 fn can_cast(kind: SyntaxKind) -> bool {
3275 match kind { 3459 match kind {
@@ -3278,24 +3462,25 @@ impl AstNode for TypeParam {
3278 } 3462 }
3279 } 3463 }
3280 fn cast(syntax: SyntaxNode) -> Option<Self> { 3464 fn cast(syntax: SyntaxNode) -> Option<Self> {
3281 if Self::can_cast(syntax.kind()) { Some(TypeParam { syntax }) } else { None } 3465 if Self::can_cast(syntax.kind()) {
3466 Some(Self { syntax })
3467 } else {
3468 None
3469 }
3470 }
3471 fn syntax(&self) -> &SyntaxNode {
3472 &self.syntax
3282 } 3473 }
3283 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3284} 3474}
3285
3286
3287impl ast::NameOwner for TypeParam {} 3475impl ast::NameOwner for TypeParam {}
3288impl ast::AttrsOwner for TypeParam {} 3476impl ast::AttrsOwner for TypeParam {}
3289impl ast::TypeBoundsOwner for TypeParam {} 3477impl ast::TypeBoundsOwner for TypeParam {}
3290impl ast::DefaultTypeParamOwner for TypeParam {} 3478impl ast::DefaultTypeParamOwner for TypeParam {}
3291impl TypeParam {} 3479impl TypeParam {}
3292
3293// TypeParamList
3294#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3480#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3295pub struct TypeParamList { 3481pub struct TypeParamList {
3296 pub(crate) syntax: SyntaxNode, 3482 pub(crate) syntax: SyntaxNode,
3297} 3483}
3298
3299impl AstNode for TypeParamList { 3484impl AstNode for TypeParamList {
3300 fn can_cast(kind: SyntaxKind) -> bool { 3485 fn can_cast(kind: SyntaxKind) -> bool {
3301 match kind { 3486 match kind {
@@ -3304,43 +3489,48 @@ impl AstNode for TypeParamList {
3304 } 3489 }
3305 } 3490 }
3306 fn cast(syntax: SyntaxNode) -> Option<Self> { 3491 fn cast(syntax: SyntaxNode) -> Option<Self> {
3307 if Self::can_cast(syntax.kind()) { Some(TypeParamList { syntax }) } else { None } 3492 if Self::can_cast(syntax.kind()) {
3493 Some(Self { syntax })
3494 } else {
3495 None
3496 }
3497 }
3498 fn syntax(&self) -> &SyntaxNode {
3499 &self.syntax
3308 } 3500 }
3309 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3310} 3501}
3311
3312
3313impl TypeParamList { 3502impl TypeParamList {
3314 pub fn type_params(&self) -> impl Iterator<Item = TypeParam> { 3503 pub fn type_params(&self) -> AstChildren<TypeParam> {
3315 super::children(self) 3504 AstChildren::new(&self.syntax)
3316 } 3505 }
3317 3506 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3318 pub fn lifetime_params(&self) -> impl Iterator<Item = LifetimeParam> { 3507 AstChildren::new(&self.syntax)
3319 super::children(self)
3320 } 3508 }
3321} 3509}
3322
3323// TypeRef
3324#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3510#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3325pub struct TypeRef { 3511pub struct TypeRef {
3326 pub(crate) syntax: SyntaxNode, 3512 pub(crate) syntax: SyntaxNode,
3327} 3513}
3328
3329impl AstNode for TypeRef { 3514impl AstNode for TypeRef {
3330 fn can_cast(kind: SyntaxKind) -> bool { 3515 fn can_cast(kind: SyntaxKind) -> bool {
3331 match kind { 3516 match kind {
3332 | PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true, 3517 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3518 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3519 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3333 _ => false, 3520 _ => false,
3334 } 3521 }
3335 } 3522 }
3336 fn cast(syntax: SyntaxNode) -> Option<Self> { 3523 fn cast(syntax: SyntaxNode) -> Option<Self> {
3337 if Self::can_cast(syntax.kind()) { Some(TypeRef { syntax }) } else { None } 3524 if Self::can_cast(syntax.kind()) {
3525 Some(Self { syntax })
3526 } else {
3527 None
3528 }
3529 }
3530 fn syntax(&self) -> &SyntaxNode {
3531 &self.syntax
3338 } 3532 }
3339 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3340} 3533}
3341
3342
3343#[derive(Debug, Clone, PartialEq, Eq)]
3344pub enum TypeRefKind { 3534pub enum TypeRefKind {
3345 ParenType(ParenType), 3535 ParenType(ParenType),
3346 TupleType(TupleType), 3536 TupleType(TupleType),
@@ -3357,73 +3547,96 @@ pub enum TypeRefKind {
3357 DynTraitType(DynTraitType), 3547 DynTraitType(DynTraitType),
3358} 3548}
3359impl From<ParenType> for TypeRef { 3549impl From<ParenType> for TypeRef {
3360 fn from(n: ParenType) -> TypeRef { TypeRef { syntax: n.syntax } } 3550 fn from(node: ParenType) -> TypeRef {
3551 TypeRef { syntax: node.syntax }
3552 }
3361} 3553}
3362impl From<TupleType> for TypeRef { 3554impl From<TupleType> for TypeRef {
3363 fn from(n: TupleType) -> TypeRef { TypeRef { syntax: n.syntax } } 3555 fn from(node: TupleType) -> TypeRef {
3556 TypeRef { syntax: node.syntax }
3557 }
3364} 3558}
3365impl From<NeverType> for TypeRef { 3559impl From<NeverType> for TypeRef {
3366 fn from(n: NeverType) -> TypeRef { TypeRef { syntax: n.syntax } } 3560 fn from(node: NeverType) -> TypeRef {
3561 TypeRef { syntax: node.syntax }
3562 }
3367} 3563}
3368impl From<PathType> for TypeRef { 3564impl From<PathType> for TypeRef {
3369 fn from(n: PathType) -> TypeRef { TypeRef { syntax: n.syntax } } 3565 fn from(node: PathType) -> TypeRef {
3566 TypeRef { syntax: node.syntax }
3567 }
3370} 3568}
3371impl From<PointerType> for TypeRef { 3569impl From<PointerType> for TypeRef {
3372 fn from(n: PointerType) -> TypeRef { TypeRef { syntax: n.syntax } } 3570 fn from(node: PointerType) -> TypeRef {
3571 TypeRef { syntax: node.syntax }
3572 }
3373} 3573}
3374impl From<ArrayType> for TypeRef { 3574impl From<ArrayType> for TypeRef {
3375 fn from(n: ArrayType) -> TypeRef { TypeRef { syntax: n.syntax } } 3575 fn from(node: ArrayType) -> TypeRef {
3576 TypeRef { syntax: node.syntax }
3577 }
3376} 3578}
3377impl From<SliceType> for TypeRef { 3579impl From<SliceType> for TypeRef {
3378 fn from(n: SliceType) -> TypeRef { TypeRef { syntax: n.syntax } } 3580 fn from(node: SliceType) -> TypeRef {
3581 TypeRef { syntax: node.syntax }
3582 }
3379} 3583}
3380impl From<ReferenceType> for TypeRef { 3584impl From<ReferenceType> for TypeRef {
3381 fn from(n: ReferenceType) -> TypeRef { TypeRef { syntax: n.syntax } } 3585 fn from(node: ReferenceType) -> TypeRef {
3586 TypeRef { syntax: node.syntax }
3587 }
3382} 3588}
3383impl From<PlaceholderType> for TypeRef { 3589impl From<PlaceholderType> for TypeRef {
3384 fn from(n: PlaceholderType) -> TypeRef { TypeRef { syntax: n.syntax } } 3590 fn from(node: PlaceholderType) -> TypeRef {
3591 TypeRef { syntax: node.syntax }
3592 }
3385} 3593}
3386impl From<FnPointerType> for TypeRef { 3594impl From<FnPointerType> for TypeRef {
3387 fn from(n: FnPointerType) -> TypeRef { TypeRef { syntax: n.syntax } } 3595 fn from(node: FnPointerType) -> TypeRef {
3596 TypeRef { syntax: node.syntax }
3597 }
3388} 3598}
3389impl From<ForType> for TypeRef { 3599impl From<ForType> for TypeRef {
3390 fn from(n: ForType) -> TypeRef { TypeRef { syntax: n.syntax } } 3600 fn from(node: ForType) -> TypeRef {
3601 TypeRef { syntax: node.syntax }
3602 }
3391} 3603}
3392impl From<ImplTraitType> for TypeRef { 3604impl From<ImplTraitType> for TypeRef {
3393 fn from(n: ImplTraitType) -> TypeRef { TypeRef { syntax: n.syntax } } 3605 fn from(node: ImplTraitType) -> TypeRef {
3606 TypeRef { syntax: node.syntax }
3607 }
3394} 3608}
3395impl From<DynTraitType> for TypeRef { 3609impl From<DynTraitType> for TypeRef {
3396 fn from(n: DynTraitType) -> TypeRef { TypeRef { syntax: n.syntax } } 3610 fn from(node: DynTraitType) -> TypeRef {
3611 TypeRef { syntax: node.syntax }
3612 }
3397} 3613}
3398impl TypeRef { 3614impl TypeRef {
3399 pub fn kind(&self) -> TypeRefKind { 3615 pub fn kind(&self) -> TypeRefKind {
3400 match self.syntax.kind() { 3616 let syntax = self.syntax.clone();
3401 PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(self.syntax.clone()).unwrap()), 3617 match syntax.kind() {
3402 TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(self.syntax.clone()).unwrap()), 3618 PAREN_TYPE => TypeRefKind::ParenType(ParenType { syntax }),
3403 NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(self.syntax.clone()).unwrap()), 3619 TUPLE_TYPE => TypeRefKind::TupleType(TupleType { syntax }),
3404 PATH_TYPE => TypeRefKind::PathType(PathType::cast(self.syntax.clone()).unwrap()), 3620 NEVER_TYPE => TypeRefKind::NeverType(NeverType { syntax }),
3405 POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(self.syntax.clone()).unwrap()), 3621 PATH_TYPE => TypeRefKind::PathType(PathType { syntax }),
3406 ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(self.syntax.clone()).unwrap()), 3622 POINTER_TYPE => TypeRefKind::PointerType(PointerType { syntax }),
3407 SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(self.syntax.clone()).unwrap()), 3623 ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType { syntax }),
3408 REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(self.syntax.clone()).unwrap()), 3624 SLICE_TYPE => TypeRefKind::SliceType(SliceType { syntax }),
3409 PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(self.syntax.clone()).unwrap()), 3625 REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType { syntax }),
3410 FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(self.syntax.clone()).unwrap()), 3626 PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType { syntax }),
3411 FOR_TYPE => TypeRefKind::ForType(ForType::cast(self.syntax.clone()).unwrap()), 3627 FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType { syntax }),
3412 IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(self.syntax.clone()).unwrap()), 3628 FOR_TYPE => TypeRefKind::ForType(ForType { syntax }),
3413 DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(self.syntax.clone()).unwrap()), 3629 IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType { syntax }),
3630 DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType { syntax }),
3414 _ => unreachable!(), 3631 _ => unreachable!(),
3415 } 3632 }
3416 } 3633 }
3417} 3634}
3418
3419impl TypeRef {} 3635impl TypeRef {}
3420
3421// UseItem
3422#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3636#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3423pub struct UseItem { 3637pub struct UseItem {
3424 pub(crate) syntax: SyntaxNode, 3638 pub(crate) syntax: SyntaxNode,
3425} 3639}
3426
3427impl AstNode for UseItem { 3640impl AstNode for UseItem {
3428 fn can_cast(kind: SyntaxKind) -> bool { 3641 fn can_cast(kind: SyntaxKind) -> bool {
3429 match kind { 3642 match kind {
@@ -3432,25 +3645,26 @@ impl AstNode for UseItem {
3432 } 3645 }
3433 } 3646 }
3434 fn cast(syntax: SyntaxNode) -> Option<Self> { 3647 fn cast(syntax: SyntaxNode) -> Option<Self> {
3435 if Self::can_cast(syntax.kind()) { Some(UseItem { syntax }) } else { None } 3648 if Self::can_cast(syntax.kind()) {
3649 Some(Self { syntax })
3650 } else {
3651 None
3652 }
3653 }
3654 fn syntax(&self) -> &SyntaxNode {
3655 &self.syntax
3436 } 3656 }
3437 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3438} 3657}
3439
3440
3441impl ast::AttrsOwner for UseItem {} 3658impl ast::AttrsOwner for UseItem {}
3442impl UseItem { 3659impl UseItem {
3443 pub fn use_tree(&self) -> Option<UseTree> { 3660 pub fn use_tree(&self) -> Option<UseTree> {
3444 super::child_opt(self) 3661 AstChildren::new(&self.syntax).next()
3445 } 3662 }
3446} 3663}
3447
3448// UseTree
3449#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3664#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3450pub struct UseTree { 3665pub struct UseTree {
3451 pub(crate) syntax: SyntaxNode, 3666 pub(crate) syntax: SyntaxNode,
3452} 3667}
3453
3454impl AstNode for UseTree { 3668impl AstNode for UseTree {
3455 fn can_cast(kind: SyntaxKind) -> bool { 3669 fn can_cast(kind: SyntaxKind) -> bool {
3456 match kind { 3670 match kind {
@@ -3459,32 +3673,31 @@ impl AstNode for UseTree {
3459 } 3673 }
3460 } 3674 }
3461 fn cast(syntax: SyntaxNode) -> Option<Self> { 3675 fn cast(syntax: SyntaxNode) -> Option<Self> {
3462 if Self::can_cast(syntax.kind()) { Some(UseTree { syntax }) } else { None } 3676 if Self::can_cast(syntax.kind()) {
3677 Some(Self { syntax })
3678 } else {
3679 None
3680 }
3681 }
3682 fn syntax(&self) -> &SyntaxNode {
3683 &self.syntax
3463 } 3684 }
3464 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3465} 3685}
3466
3467
3468impl UseTree { 3686impl UseTree {
3469 pub fn path(&self) -> Option<Path> { 3687 pub fn path(&self) -> Option<Path> {
3470 super::child_opt(self) 3688 AstChildren::new(&self.syntax).next()
3471 } 3689 }
3472
3473 pub fn use_tree_list(&self) -> Option<UseTreeList> { 3690 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3474 super::child_opt(self) 3691 AstChildren::new(&self.syntax).next()
3475 } 3692 }
3476
3477 pub fn alias(&self) -> Option<Alias> { 3693 pub fn alias(&self) -> Option<Alias> {
3478 super::child_opt(self) 3694 AstChildren::new(&self.syntax).next()
3479 } 3695 }
3480} 3696}
3481
3482// UseTreeList
3483#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3697#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3484pub struct UseTreeList { 3698pub struct UseTreeList {
3485 pub(crate) syntax: SyntaxNode, 3699 pub(crate) syntax: SyntaxNode,
3486} 3700}
3487
3488impl AstNode for UseTreeList { 3701impl AstNode for UseTreeList {
3489 fn can_cast(kind: SyntaxKind) -> bool { 3702 fn can_cast(kind: SyntaxKind) -> bool {
3490 match kind { 3703 match kind {
@@ -3493,24 +3706,25 @@ impl AstNode for UseTreeList {
3493 } 3706 }
3494 } 3707 }
3495 fn cast(syntax: SyntaxNode) -> Option<Self> { 3708 fn cast(syntax: SyntaxNode) -> Option<Self> {
3496 if Self::can_cast(syntax.kind()) { Some(UseTreeList { syntax }) } else { None } 3709 if Self::can_cast(syntax.kind()) {
3710 Some(Self { syntax })
3711 } else {
3712 None
3713 }
3714 }
3715 fn syntax(&self) -> &SyntaxNode {
3716 &self.syntax
3497 } 3717 }
3498 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3499} 3718}
3500
3501
3502impl UseTreeList { 3719impl UseTreeList {
3503 pub fn use_trees(&self) -> impl Iterator<Item = UseTree> { 3720 pub fn use_trees(&self) -> AstChildren<UseTree> {
3504 super::children(self) 3721 AstChildren::new(&self.syntax)
3505 } 3722 }
3506} 3723}
3507
3508// Visibility
3509#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3724#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3510pub struct Visibility { 3725pub struct Visibility {
3511 pub(crate) syntax: SyntaxNode, 3726 pub(crate) syntax: SyntaxNode,
3512} 3727}
3513
3514impl AstNode for Visibility { 3728impl AstNode for Visibility {
3515 fn can_cast(kind: SyntaxKind) -> bool { 3729 fn can_cast(kind: SyntaxKind) -> bool {
3516 match kind { 3730 match kind {
@@ -3519,20 +3733,21 @@ impl AstNode for Visibility {
3519 } 3733 }
3520 } 3734 }
3521 fn cast(syntax: SyntaxNode) -> Option<Self> { 3735 fn cast(syntax: SyntaxNode) -> Option<Self> {
3522 if Self::can_cast(syntax.kind()) { Some(Visibility { syntax }) } else { None } 3736 if Self::can_cast(syntax.kind()) {
3737 Some(Self { syntax })
3738 } else {
3739 None
3740 }
3741 }
3742 fn syntax(&self) -> &SyntaxNode {
3743 &self.syntax
3523 } 3744 }
3524 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3525} 3745}
3526
3527
3528impl Visibility {} 3746impl Visibility {}
3529
3530// WhereClause
3531#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3747#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3532pub struct WhereClause { 3748pub struct WhereClause {
3533 pub(crate) syntax: SyntaxNode, 3749 pub(crate) syntax: SyntaxNode,
3534} 3750}
3535
3536impl AstNode for WhereClause { 3751impl AstNode for WhereClause {
3537 fn can_cast(kind: SyntaxKind) -> bool { 3752 fn can_cast(kind: SyntaxKind) -> bool {
3538 match kind { 3753 match kind {
@@ -3541,24 +3756,25 @@ impl AstNode for WhereClause {
3541 } 3756 }
3542 } 3757 }
3543 fn cast(syntax: SyntaxNode) -> Option<Self> { 3758 fn cast(syntax: SyntaxNode) -> Option<Self> {
3544 if Self::can_cast(syntax.kind()) { Some(WhereClause { syntax }) } else { None } 3759 if Self::can_cast(syntax.kind()) {
3760 Some(Self { syntax })
3761 } else {
3762 None
3763 }
3764 }
3765 fn syntax(&self) -> &SyntaxNode {
3766 &self.syntax
3545 } 3767 }
3546 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3547} 3768}
3548
3549
3550impl WhereClause { 3769impl WhereClause {
3551 pub fn predicates(&self) -> impl Iterator<Item = WherePred> { 3770 pub fn predicates(&self) -> AstChildren<WherePred> {
3552 super::children(self) 3771 AstChildren::new(&self.syntax)
3553 } 3772 }
3554} 3773}
3555
3556// WherePred
3557#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3774#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3558pub struct WherePred { 3775pub struct WherePred {
3559 pub(crate) syntax: SyntaxNode, 3776 pub(crate) syntax: SyntaxNode,
3560} 3777}
3561
3562impl AstNode for WherePred { 3778impl AstNode for WherePred {
3563 fn can_cast(kind: SyntaxKind) -> bool { 3779 fn can_cast(kind: SyntaxKind) -> bool {
3564 match kind { 3780 match kind {
@@ -3567,25 +3783,26 @@ impl AstNode for WherePred {
3567 } 3783 }
3568 } 3784 }
3569 fn cast(syntax: SyntaxNode) -> Option<Self> { 3785 fn cast(syntax: SyntaxNode) -> Option<Self> {
3570 if Self::can_cast(syntax.kind()) { Some(WherePred { syntax }) } else { None } 3786 if Self::can_cast(syntax.kind()) {
3787 Some(Self { syntax })
3788 } else {
3789 None
3790 }
3791 }
3792 fn syntax(&self) -> &SyntaxNode {
3793 &self.syntax
3571 } 3794 }
3572 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3573} 3795}
3574
3575
3576impl ast::TypeBoundsOwner for WherePred {} 3796impl ast::TypeBoundsOwner for WherePred {}
3577impl WherePred { 3797impl WherePred {
3578 pub fn type_ref(&self) -> Option<TypeRef> { 3798 pub fn type_ref(&self) -> Option<TypeRef> {
3579 super::child_opt(self) 3799 AstChildren::new(&self.syntax).next()
3580 } 3800 }
3581} 3801}
3582
3583// WhileExpr
3584#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3802#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3585pub struct WhileExpr { 3803pub struct WhileExpr {
3586 pub(crate) syntax: SyntaxNode, 3804 pub(crate) syntax: SyntaxNode,
3587} 3805}
3588
3589impl AstNode for WhileExpr { 3806impl AstNode for WhileExpr {
3590 fn can_cast(kind: SyntaxKind) -> bool { 3807 fn can_cast(kind: SyntaxKind) -> bool {
3591 match kind { 3808 match kind {
@@ -3594,16 +3811,19 @@ impl AstNode for WhileExpr {
3594 } 3811 }
3595 } 3812 }
3596 fn cast(syntax: SyntaxNode) -> Option<Self> { 3813 fn cast(syntax: SyntaxNode) -> Option<Self> {
3597 if Self::can_cast(syntax.kind()) { Some(WhileExpr { syntax }) } else { None } 3814 if Self::can_cast(syntax.kind()) {
3815 Some(Self { syntax })
3816 } else {
3817 None
3818 }
3819 }
3820 fn syntax(&self) -> &SyntaxNode {
3821 &self.syntax
3598 } 3822 }
3599 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3600} 3823}
3601
3602
3603impl ast::LoopBodyOwner for WhileExpr {} 3824impl ast::LoopBodyOwner for WhileExpr {}
3604impl WhileExpr { 3825impl WhileExpr {
3605 pub fn condition(&self) -> Option<Condition> { 3826 pub fn condition(&self) -> Option<Condition> {
3606 super::child_opt(self) 3827 AstChildren::new(&self.syntax).next()
3607 } 3828 }
3608} 3829}
3609
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera
deleted file mode 100644
index 03b4bf3a1..000000000
--- a/crates/ra_syntax/src/ast/generated.rs.tera
+++ /dev/null
@@ -1,101 +0,0 @@
1{# THIS File is not automatically generated:
2the below applies to the result of this template
3#}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
4// Do not edit manually
5
6//! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes
7//! are generic over ownership: `X<'a>` things are `Copy` references, `XNode`
8//! are Arc-based. You can switch between the two variants using `.owned` and
9//! `.borrowed` functions. Most of the code works with borowed mode, and only
10//! this mode has all AST accessors.
11
12#![cfg_attr(rustfmt, rustfmt_skip)]
13
14use crate::{
15 SyntaxNode, SyntaxKind::{self, *},
16 ast::{self, AstNode},
17};
18{% for node, methods in ast %}
19// {{ node }}
20#[derive(Debug, Clone, PartialEq, Eq, Hash)]
21pub struct {{ node }} {
22 pub(crate) syntax: SyntaxNode,
23}
24
25impl AstNode for {{ node }} {
26 fn can_cast(kind: SyntaxKind) -> bool {
27 match kind {
28 {%- if methods.enum %}
29 {% for kind in methods.enum %} | {{ kind | SCREAM }} {%- endfor -%}
30 {% else %}
31 {{ node | SCREAM }}
32 {%- endif %} => true,
33 _ => false,
34 }
35 }
36 fn cast(syntax: SyntaxNode) -> Option<Self> {
37 if Self::can_cast(syntax.kind()) { Some({{ node }} { syntax }) } else { None }
38 }
39 fn syntax(&self) -> &SyntaxNode { &self.syntax }
40}
41
42{% if methods.enum %}
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub enum {{ node }}Kind {
45{%- for kind in methods.enum %}
46 {{ kind }}({{ kind }}),
47{%- endfor %}
48}
49
50{%- for kind in methods.enum %}
51impl From<{{ kind }}> for {{ node }} {
52 fn from(n: {{ kind }}) -> {{ node }} { {{ node }} { syntax: n.syntax } }
53}
54{%- endfor %}
55impl {{ node }} {
56 pub fn kind(&self) -> {{ node }}Kind {
57 match self.syntax.kind() {
58 {%- for kind in methods.enum %}
59 {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(self.syntax.clone()).unwrap()),
60 {%- endfor %}
61 _ => unreachable!(),
62 }
63 }
64}
65{% endif %}
66{% if methods.traits -%}
67
68{%- for t in methods.traits -%}
69impl ast::{{ t }} for {{ node }} {}
70{% endfor -%}
71
72{%- endif -%}
73
74impl {{ node }} {
75{%- if methods.collections -%}
76{%- for m in methods.collections -%}
77{%- set method_name = m.0 -%}
78{%- set ChildName = m.1 %}
79 pub fn {{ method_name }}(&self) -> impl Iterator<Item = {{ ChildName }}> {
80 super::children(self)
81 }
82{% endfor -%}
83{%- endif -%}
84
85{%- if methods.options -%}
86{%- for m in methods.options -%}
87
88{%- if m is string -%}
89{%- set method_name = m | snake -%}
90{%- set ChildName = m %}
91{%- else -%}
92{%- set method_name = m.0 -%}
93{%- set ChildName = m.1 %}
94{%- endif %}
95 pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> {
96 super::child_opt(self)
97 }
98{% endfor -%}
99{%- endif -%}
100}
101{% endfor %}
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index f2c20573e..26efeeba9 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -2,61 +2,61 @@
2// See `cargo gen-syntax` (defined in crates/tools/src/main.rs) 2// See `cargo gen-syntax` (defined in crates/tools/src/main.rs)
3Grammar( 3Grammar(
4 single_byte_tokens: [ 4 single_byte_tokens: [
5 [";", "SEMI"], 5 (";", "SEMI"),
6 [",", "COMMA"], 6 (",", "COMMA"),
7 ["(", "L_PAREN"], 7 ("(", "L_PAREN"),
8 [")", "R_PAREN"], 8 (")", "R_PAREN"),
9 ["{", "L_CURLY"], 9 ("{", "L_CURLY"),
10 ["}", "R_CURLY"], 10 ("}", "R_CURLY"),
11 ["[", "L_BRACK"], 11 ("[", "L_BRACK"),
12 ["]", "R_BRACK"], 12 ("]", "R_BRACK"),
13 ["<", "L_ANGLE"], 13 ("<", "L_ANGLE"),
14 [">", "R_ANGLE"], 14 (">", "R_ANGLE"),
15 ["@", "AT"], 15 ("@", "AT"),
16 ["#", "POUND"], 16 ("#", "POUND"),
17 ["~", "TILDE"], 17 ("~", "TILDE"),
18 ["?", "QUESTION"], 18 ("?", "QUESTION"),
19 ["$", "DOLLAR"], 19 ("$", "DOLLAR"),
20 ["&", "AMP"], 20 ("&", "AMP"),
21 ["|", "PIPE"], 21 ("|", "PIPE"),
22 ["+", "PLUS"], 22 ("+", "PLUS"),
23 ["*", "STAR"], 23 ("*", "STAR"),
24 ["/", "SLASH"], 24 ("/", "SLASH"),
25 ["^", "CARET"], 25 ("^", "CARET"),
26 ["%", "PERCENT"], 26 ("%", "PERCENT"),
27 ["_", "UNDERSCORE"], 27 ("_", "UNDERSCORE"),
28 ], 28 ],
29 // Tokens for which the longest match must be chosen (e.g. `..` is a DOTDOT, but `.` is a DOT) 29 // Tokens for which the longest match must be chosen (e.g. `..` is a DOTDOT, but `.` is a DOT)
30 multi_byte_tokens: [ 30 multi_byte_tokens: [
31 [".", "DOT"], 31 (".", "DOT"),
32 ["..", "DOTDOT"], 32 ("..", "DOTDOT"),
33 ["...", "DOTDOTDOT"], 33 ("...", "DOTDOTDOT"),
34 ["..=", "DOTDOTEQ"], 34 ("..=", "DOTDOTEQ"),
35 [":", "COLON"], 35 (":", "COLON"),
36 ["::", "COLONCOLON"], 36 ("::", "COLONCOLON"),
37 ["=", "EQ"], 37 ("=", "EQ"),
38 ["==", "EQEQ"], 38 ("==", "EQEQ"),
39 ["=>", "FAT_ARROW"], 39 ("=>", "FAT_ARROW"),
40 ["!", "EXCL"], 40 ("!", "EXCL"),
41 ["!=", "NEQ"], 41 ("!=", "NEQ"),
42 ["-", "MINUS"], 42 ("-", "MINUS"),
43 ["->", "THIN_ARROW"], 43 ("->", "THIN_ARROW"),
44 ["<=", "LTEQ"], 44 ("<=", "LTEQ"),
45 [">=", "GTEQ"], 45 (">=", "GTEQ"),
46 ["+=", "PLUSEQ"], 46 ("+=", "PLUSEQ"),
47 ["-=", "MINUSEQ"], 47 ("-=", "MINUSEQ"),
48 ["|=", "PIPEEQ"], 48 ("|=", "PIPEEQ"),
49 ["&=", "AMPEQ"], 49 ("&=", "AMPEQ"),
50 ["^=", "CARETEQ"], 50 ("^=", "CARETEQ"),
51 ["/=", "SLASHEQ"], 51 ("/=", "SLASHEQ"),
52 ["*=", "STAREQ"], 52 ("*=", "STAREQ"),
53 ["%=", "PERCENTEQ"], 53 ("%=", "PERCENTEQ"),
54 ["&&", "AMPAMP"], 54 ("&&", "AMPAMP"),
55 ["||", "PIPEPIPE"], 55 ("||", "PIPEPIPE"),
56 ["<<", "SHL"], 56 ("<<", "SHL"),
57 [">>", "SHR"], 57 (">>", "SHR"),
58 ["<<=", "SHLEQ"], 58 ("<<=", "SHLEQ"),
59 [">>=", "SHREQ"], 59 (">>=", "SHREQ"),
60 ], 60 ],
61 keywords: [ 61 keywords: [
62 "async", 62 "async",
@@ -263,7 +263,7 @@ Grammar(
263 "SourceFile": ( 263 "SourceFile": (
264 traits: [ "ModuleItemOwner", "FnDefOwner" ], 264 traits: [ "ModuleItemOwner", "FnDefOwner" ],
265 collections: [ 265 collections: [
266 ["modules", "Module"], 266 ("modules", "Module"),
267 ] 267 ]
268 ), 268 ),
269 "FnDef": ( 269 "FnDef": (
@@ -286,7 +286,7 @@ Grammar(
286 "DocCommentsOwner" 286 "DocCommentsOwner"
287 ] 287 ]
288 ), 288 ),
289 "NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]), 289 "NamedFieldDefList": (collections: [("fields", "NamedFieldDef")]),
290 "NamedFieldDef": ( 290 "NamedFieldDef": (
291 traits: [ 291 traits: [
292 "VisibilityOwner", 292 "VisibilityOwner",
@@ -296,7 +296,7 @@ Grammar(
296 "TypeAscriptionOwner" 296 "TypeAscriptionOwner"
297 ] 297 ]
298 ), 298 ),
299 "PosFieldDefList": (collections: [["fields", "PosFieldDef"]]), 299 "PosFieldDefList": (collections: [("fields", "PosFieldDef")]),
300 "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]), 300 "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]),
301 "EnumDef": ( traits: [ 301 "EnumDef": ( traits: [
302 "VisibilityOwner", 302 "VisibilityOwner",
@@ -305,7 +305,7 @@ Grammar(
305 "AttrsOwner", 305 "AttrsOwner",
306 "DocCommentsOwner" 306 "DocCommentsOwner"
307 ], options: [["variant_list", "EnumVariantList"]] ), 307 ], options: [["variant_list", "EnumVariantList"]] ),
308 "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ), 308 "EnumVariantList": ( collections: [("variants", "EnumVariant")] ),
309 "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ), 309 "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ),
310 "TraitDef": ( 310 "TraitDef": (
311 traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner", "TypeBoundsOwner"], 311 traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner", "TypeBoundsOwner"],
@@ -316,7 +316,7 @@ Grammar(
316 options: [ "ItemList" ] 316 options: [ "ItemList" ]
317 ), 317 ),
318 "ItemList": ( 318 "ItemList": (
319 collections: [["impl_items", "ImplItem"]], 319 collections: [("impl_items", "ImplItem")],
320 traits: [ "FnDefOwner", "ModuleItemOwner" ], 320 traits: [ "FnDefOwner", "ModuleItemOwner" ],
321 ), 321 ),
322 "ConstDef": ( 322 "ConstDef": (
@@ -355,7 +355,7 @@ Grammar(
355 "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]), 355 "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]),
356 356
357 "ParenType": (options: ["TypeRef"]), 357 "ParenType": (options: ["TypeRef"]),
358 "TupleType": ( collections: [["fields", "TypeRef"]] ), 358 "TupleType": ( collections: [("fields", "TypeRef")] ),
359 "NeverType": (), 359 "NeverType": (),
360 "PathType": (options: ["Path"]), 360 "PathType": (options: ["Path"]),
361 "PointerType": (options: ["TypeRef"]), 361 "PointerType": (options: ["TypeRef"]),
@@ -405,10 +405,10 @@ Grammar(
405 ), 405 ),
406 406
407 "TupleExpr": ( 407 "TupleExpr": (
408 collections: [["exprs", "Expr"]] 408 collections: [("exprs", "Expr")]
409 ), 409 ),
410 "ArrayExpr": ( 410 "ArrayExpr": (
411 collections: [["exprs", "Expr"]] 411 collections: [("exprs", "Expr")]
412 ), 412 ),
413 "ParenExpr": (options: ["Expr"]), 413 "ParenExpr": (options: ["Expr"]),
414 "PathExpr": (options: ["Path"]), 414 "PathExpr": (options: ["Path"]),
@@ -449,7 +449,7 @@ Grammar(
449 options: [ "Expr", "MatchArmList" ], 449 options: [ "Expr", "MatchArmList" ],
450 ), 450 ),
451 "MatchArmList": ( 451 "MatchArmList": (
452 collections: [ ["arms", "MatchArm"] ], 452 collections: [ ("arms", "MatchArm") ],
453 traits: [ "AttrsOwner" ] 453 traits: [ "AttrsOwner" ]
454 ), 454 ),
455 "MatchArm": ( 455 "MatchArm": (
@@ -457,13 +457,13 @@ Grammar(
457 [ "guard", "MatchGuard" ], 457 [ "guard", "MatchGuard" ],
458 "Expr", 458 "Expr",
459 ], 459 ],
460 collections: [ [ "pats", "Pat" ] ], 460 collections: [ ("pats", "Pat") ],
461 traits: [ "AttrsOwner" ] 461 traits: [ "AttrsOwner" ]
462 ), 462 ),
463 "MatchGuard": (options: ["Expr"]), 463 "MatchGuard": (options: ["Expr"]),
464 "StructLit": (options: ["Path", "NamedFieldList"]), 464 "StructLit": (options: ["Path", "NamedFieldList"]),
465 "NamedFieldList": ( 465 "NamedFieldList": (
466 collections: [ ["fields", "NamedField"] ], 466 collections: [ ("fields", "NamedField") ],
467 options: [["spread", "Expr"]] 467 options: [["spread", "Expr"]]
468 ), 468 ),
469 "NamedField": (options: ["NameRef", "Expr"]), 469 "NamedField": (options: ["NameRef", "Expr"]),
@@ -532,8 +532,8 @@ Grammar(
532 "StructPat": ( options: ["FieldPatList", "Path"] ), 532 "StructPat": ( options: ["FieldPatList", "Path"] ),
533 "FieldPatList": ( 533 "FieldPatList": (
534 collections: [ 534 collections: [
535 ["field_pats", "FieldPat"], 535 ("field_pats", "FieldPat"),
536 ["bind_pats", "BindPat"], 536 ("bind_pats", "BindPat"),
537 ] 537 ]
538 ), 538 ),
539 "FieldPat": ( 539 "FieldPat": (
@@ -542,9 +542,9 @@ Grammar(
542 ), 542 ),
543 "TupleStructPat": ( 543 "TupleStructPat": (
544 options: ["Path"], 544 options: ["Path"],
545 collections: [["args", "Pat"]], 545 collections: [("args", "Pat")],
546 ), 546 ),
547 "TuplePat": ( collections: [["args", "Pat"]] ), 547 "TuplePat": ( collections: [("args", "Pat")] ),
548 "SlicePat": (), 548 "SlicePat": (),
549 "RangePat": (), 549 "RangePat": (),
550 "LiteralPat": (options: ["Literal"]), 550 "LiteralPat": (options: ["Literal"]),
@@ -575,8 +575,8 @@ Grammar(
575 "TokenTree": (), 575 "TokenTree": (),
576 "TypeParamList": ( 576 "TypeParamList": (
577 collections: [ 577 collections: [
578 ["type_params", "TypeParam" ], 578 ("type_params", "TypeParam" ),
579 ["lifetime_params", "LifetimeParam" ], 579 ("lifetime_params", "LifetimeParam" ),
580 ] 580 ]
581 ), 581 ),
582 "TypeParam": ( traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner", "DefaultTypeParamOwner"] ), 582 "TypeParam": ( traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner", "DefaultTypeParamOwner"] ),
@@ -590,7 +590,7 @@ Grammar(
590 ), 590 ),
591 "TypeBoundList": ( 591 "TypeBoundList": (
592 collections: [ 592 collections: [
593 ["bounds", "TypeBound"], 593 ("bounds", "TypeBound"),
594 ] 594 ]
595 ), 595 ),
596 "WherePred": ( 596 "WherePred": (
@@ -603,7 +603,7 @@ Grammar(
603 ), 603 ),
604 "WhereClause": ( 604 "WhereClause": (
605 collections: [ 605 collections: [
606 ["predicates", "WherePred"], 606 ("predicates", "WherePred"),
607 ], 607 ],
608 ), 608 ),
609 "ExprStmt": ( 609 "ExprStmt": (
@@ -627,7 +627,7 @@ Grammar(
627 "Block": ( 627 "Block": (
628 options: [ "Expr" ], 628 options: [ "Expr" ],
629 collections: [ 629 collections: [
630 ["statements", "Stmt"], 630 ("statements", "Stmt"),
631 ], 631 ],
632 traits: [ 632 traits: [
633 "AttrsOwner", 633 "AttrsOwner",
@@ -636,7 +636,7 @@ Grammar(
636 "ParamList": ( 636 "ParamList": (
637 options: [ "SelfParam" ], 637 options: [ "SelfParam" ],
638 collections: [ 638 collections: [
639 ["params", "Param"] 639 ("params", "Param"),
640 ] 640 ]
641 ), 641 ),
642 "SelfParam": ( 642 "SelfParam": (
@@ -663,14 +663,14 @@ Grammar(
663 traits: ["NameOwner"], 663 traits: ["NameOwner"],
664 ), 664 ),
665 "UseTreeList": ( 665 "UseTreeList": (
666 collections: [["use_trees", "UseTree"]] 666 collections: [("use_trees", "UseTree")]
667 ), 667 ),
668 "ExternCrateItem": ( 668 "ExternCrateItem": (
669 options: ["NameRef", "Alias"], 669 options: ["NameRef", "Alias"],
670 ), 670 ),
671 "ArgList": ( 671 "ArgList": (
672 collections: [ 672 collections: [
673 ["args", "Expr"] 673 ("args", "Expr"),
674 ] 674 ]
675 ), 675 ),
676 "Path": ( 676 "Path": (
@@ -683,22 +683,22 @@ Grammar(
683 options: [ "NameRef", "TypeArgList" ] 683 options: [ "NameRef", "TypeArgList" ]
684 ), 684 ),
685 "TypeArgList": (collections: [ 685 "TypeArgList": (collections: [
686 ["type_args", "TypeArg"], 686 ("type_args", "TypeArg"),
687 ["lifetime_args", "LifetimeArg"], 687 ("lifetime_args", "LifetimeArg"),
688 ["assoc_type_args", "AssocTypeArg"], 688 ("assoc_type_args", "AssocTypeArg"),
689 ]), 689 ]),
690 "TypeArg": (options: ["TypeRef"]), 690 "TypeArg": (options: ["TypeRef"]),
691 "AssocTypeArg": (options: ["NameRef", "TypeRef"]), 691 "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
692 "LifetimeArg": (), 692 "LifetimeArg": (),
693 693
694 "MacroItems": ( 694 "MacroItems": (
695 traits: [ "ModuleItemOwner", "FnDefOwner" ], 695 traits: [ "ModuleItemOwner", "FnDefOwner" ],
696 ), 696 ),
697 697
698 "MacroStmts" : ( 698 "MacroStmts" : (
699 options: [ "Expr" ], 699 options: [ "Expr" ],
700 collections: [ 700 collections: [
701 ["statements", "Stmt"], 701 ("statements", "Stmt"),
702 ], 702 ],
703 ) 703 )
704 }, 704 },