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