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