]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/ast/generated.rs
Merge #1568
[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 Param {
2017     pub fn pat(&self) -> Option<Pat> {
2018         super::child_opt(self)
2019     }
2020 }
2021
2022 // ParamList
2023 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2024 pub struct ParamList {
2025     pub(crate) syntax: SyntaxNode,
2026 }
2027
2028 impl AstNode for ParamList {
2029     fn can_cast(kind: SyntaxKind) -> bool {
2030         match kind {
2031             PARAM_LIST => true,
2032             _ => false,
2033         }
2034     }
2035     fn cast(syntax: SyntaxNode) -> Option<Self> {
2036         if Self::can_cast(syntax.kind()) { Some(ParamList { syntax }) } else { None }
2037     }
2038     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2039 }
2040
2041
2042 impl ParamList {
2043     pub fn params(&self) -> impl Iterator<Item = Param> {
2044         super::children(self)
2045     }
2046
2047     pub fn self_param(&self) -> Option<SelfParam> {
2048         super::child_opt(self)
2049     }
2050 }
2051
2052 // ParenExpr
2053 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2054 pub struct ParenExpr {
2055     pub(crate) syntax: SyntaxNode,
2056 }
2057
2058 impl AstNode for ParenExpr {
2059     fn can_cast(kind: SyntaxKind) -> bool {
2060         match kind {
2061             PAREN_EXPR => true,
2062             _ => false,
2063         }
2064     }
2065     fn cast(syntax: SyntaxNode) -> Option<Self> {
2066         if Self::can_cast(syntax.kind()) { Some(ParenExpr { syntax }) } else { None }
2067     }
2068     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2069 }
2070
2071
2072 impl ParenExpr {
2073     pub fn expr(&self) -> Option<Expr> {
2074         super::child_opt(self)
2075     }
2076 }
2077
2078 // ParenType
2079 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2080 pub struct ParenType {
2081     pub(crate) syntax: SyntaxNode,
2082 }
2083
2084 impl AstNode for ParenType {
2085     fn can_cast(kind: SyntaxKind) -> bool {
2086         match kind {
2087             PAREN_TYPE => true,
2088             _ => false,
2089         }
2090     }
2091     fn cast(syntax: SyntaxNode) -> Option<Self> {
2092         if Self::can_cast(syntax.kind()) { Some(ParenType { syntax }) } else { None }
2093     }
2094     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2095 }
2096
2097
2098 impl ParenType {
2099     pub fn type_ref(&self) -> Option<TypeRef> {
2100         super::child_opt(self)
2101     }
2102 }
2103
2104 // Pat
2105 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2106 pub struct Pat {
2107     pub(crate) syntax: SyntaxNode,
2108 }
2109
2110 impl AstNode for Pat {
2111     fn can_cast(kind: SyntaxKind) -> bool {
2112         match kind {
2113              | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2114             _ => false,
2115         }
2116     }
2117     fn cast(syntax: SyntaxNode) -> Option<Self> {
2118         if Self::can_cast(syntax.kind()) { Some(Pat { syntax }) } else { None }
2119     }
2120     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2121 }
2122
2123
2124 #[derive(Debug, Clone, PartialEq, Eq)]
2125 pub enum PatKind {
2126     RefPat(RefPat),
2127     BindPat(BindPat),
2128     PlaceholderPat(PlaceholderPat),
2129     PathPat(PathPat),
2130     StructPat(StructPat),
2131     TupleStructPat(TupleStructPat),
2132     TuplePat(TuplePat),
2133     SlicePat(SlicePat),
2134     RangePat(RangePat),
2135     LiteralPat(LiteralPat),
2136 }
2137 impl From<RefPat> for Pat {
2138     fn from(n: RefPat) -> Pat { Pat { syntax: n.syntax } }
2139 }
2140 impl From<BindPat> for Pat {
2141     fn from(n: BindPat) -> Pat { Pat { syntax: n.syntax } }
2142 }
2143 impl From<PlaceholderPat> for Pat {
2144     fn from(n: PlaceholderPat) -> Pat { Pat { syntax: n.syntax } }
2145 }
2146 impl From<PathPat> for Pat {
2147     fn from(n: PathPat) -> Pat { Pat { syntax: n.syntax } }
2148 }
2149 impl From<StructPat> for Pat {
2150     fn from(n: StructPat) -> Pat { Pat { syntax: n.syntax } }
2151 }
2152 impl From<TupleStructPat> for Pat {
2153     fn from(n: TupleStructPat) -> Pat { Pat { syntax: n.syntax } }
2154 }
2155 impl From<TuplePat> for Pat {
2156     fn from(n: TuplePat) -> Pat { Pat { syntax: n.syntax } }
2157 }
2158 impl From<SlicePat> for Pat {
2159     fn from(n: SlicePat) -> Pat { Pat { syntax: n.syntax } }
2160 }
2161 impl From<RangePat> for Pat {
2162     fn from(n: RangePat) -> Pat { Pat { syntax: n.syntax } }
2163 }
2164 impl From<LiteralPat> for Pat {
2165     fn from(n: LiteralPat) -> Pat { Pat { syntax: n.syntax } }
2166 }
2167 impl Pat {
2168     pub fn kind(&self) -> PatKind {
2169         match self.syntax.kind() {
2170             REF_PAT => PatKind::RefPat(RefPat::cast(self.syntax.clone()).unwrap()),
2171             BIND_PAT => PatKind::BindPat(BindPat::cast(self.syntax.clone()).unwrap()),
2172             PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(self.syntax.clone()).unwrap()),
2173             PATH_PAT => PatKind::PathPat(PathPat::cast(self.syntax.clone()).unwrap()),
2174             STRUCT_PAT => PatKind::StructPat(StructPat::cast(self.syntax.clone()).unwrap()),
2175             TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(self.syntax.clone()).unwrap()),
2176             TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(self.syntax.clone()).unwrap()),
2177             SLICE_PAT => PatKind::SlicePat(SlicePat::cast(self.syntax.clone()).unwrap()),
2178             RANGE_PAT => PatKind::RangePat(RangePat::cast(self.syntax.clone()).unwrap()),
2179             LITERAL_PAT => PatKind::LiteralPat(LiteralPat::cast(self.syntax.clone()).unwrap()),
2180             _ => unreachable!(),
2181         }
2182     }
2183 }
2184
2185 impl Pat {}
2186
2187 // Path
2188 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2189 pub struct Path {
2190     pub(crate) syntax: SyntaxNode,
2191 }
2192
2193 impl AstNode for Path {
2194     fn can_cast(kind: SyntaxKind) -> bool {
2195         match kind {
2196             PATH => true,
2197             _ => false,
2198         }
2199     }
2200     fn cast(syntax: SyntaxNode) -> Option<Self> {
2201         if Self::can_cast(syntax.kind()) { Some(Path { syntax }) } else { None }
2202     }
2203     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2204 }
2205
2206
2207 impl Path {
2208     pub fn segment(&self) -> Option<PathSegment> {
2209         super::child_opt(self)
2210     }
2211
2212     pub fn qualifier(&self) -> Option<Path> {
2213         super::child_opt(self)
2214     }
2215 }
2216
2217 // PathExpr
2218 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2219 pub struct PathExpr {
2220     pub(crate) syntax: SyntaxNode,
2221 }
2222
2223 impl AstNode for PathExpr {
2224     fn can_cast(kind: SyntaxKind) -> bool {
2225         match kind {
2226             PATH_EXPR => true,
2227             _ => false,
2228         }
2229     }
2230     fn cast(syntax: SyntaxNode) -> Option<Self> {
2231         if Self::can_cast(syntax.kind()) { Some(PathExpr { syntax }) } else { None }
2232     }
2233     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2234 }
2235
2236
2237 impl PathExpr {
2238     pub fn path(&self) -> Option<Path> {
2239         super::child_opt(self)
2240     }
2241 }
2242
2243 // PathPat
2244 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2245 pub struct PathPat {
2246     pub(crate) syntax: SyntaxNode,
2247 }
2248
2249 impl AstNode for PathPat {
2250     fn can_cast(kind: SyntaxKind) -> bool {
2251         match kind {
2252             PATH_PAT => true,
2253             _ => false,
2254         }
2255     }
2256     fn cast(syntax: SyntaxNode) -> Option<Self> {
2257         if Self::can_cast(syntax.kind()) { Some(PathPat { syntax }) } else { None }
2258     }
2259     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2260 }
2261
2262
2263 impl PathPat {
2264     pub fn path(&self) -> Option<Path> {
2265         super::child_opt(self)
2266     }
2267 }
2268
2269 // PathSegment
2270 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2271 pub struct PathSegment {
2272     pub(crate) syntax: SyntaxNode,
2273 }
2274
2275 impl AstNode for PathSegment {
2276     fn can_cast(kind: SyntaxKind) -> bool {
2277         match kind {
2278             PATH_SEGMENT => true,
2279             _ => false,
2280         }
2281     }
2282     fn cast(syntax: SyntaxNode) -> Option<Self> {
2283         if Self::can_cast(syntax.kind()) { Some(PathSegment { syntax }) } else { None }
2284     }
2285     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2286 }
2287
2288
2289 impl PathSegment {
2290     pub fn name_ref(&self) -> Option<NameRef> {
2291         super::child_opt(self)
2292     }
2293
2294     pub fn type_arg_list(&self) -> Option<TypeArgList> {
2295         super::child_opt(self)
2296     }
2297 }
2298
2299 // PathType
2300 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2301 pub struct PathType {
2302     pub(crate) syntax: SyntaxNode,
2303 }
2304
2305 impl AstNode for PathType {
2306     fn can_cast(kind: SyntaxKind) -> bool {
2307         match kind {
2308             PATH_TYPE => true,
2309             _ => false,
2310         }
2311     }
2312     fn cast(syntax: SyntaxNode) -> Option<Self> {
2313         if Self::can_cast(syntax.kind()) { Some(PathType { syntax }) } else { None }
2314     }
2315     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2316 }
2317
2318
2319 impl PathType {
2320     pub fn path(&self) -> Option<Path> {
2321         super::child_opt(self)
2322     }
2323 }
2324
2325 // PlaceholderPat
2326 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2327 pub struct PlaceholderPat {
2328     pub(crate) syntax: SyntaxNode,
2329 }
2330
2331 impl AstNode for PlaceholderPat {
2332     fn can_cast(kind: SyntaxKind) -> bool {
2333         match kind {
2334             PLACEHOLDER_PAT => true,
2335             _ => false,
2336         }
2337     }
2338     fn cast(syntax: SyntaxNode) -> Option<Self> {
2339         if Self::can_cast(syntax.kind()) { Some(PlaceholderPat { syntax }) } else { None }
2340     }
2341     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2342 }
2343
2344
2345 impl PlaceholderPat {}
2346
2347 // PlaceholderType
2348 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2349 pub struct PlaceholderType {
2350     pub(crate) syntax: SyntaxNode,
2351 }
2352
2353 impl AstNode for PlaceholderType {
2354     fn can_cast(kind: SyntaxKind) -> bool {
2355         match kind {
2356             PLACEHOLDER_TYPE => true,
2357             _ => false,
2358         }
2359     }
2360     fn cast(syntax: SyntaxNode) -> Option<Self> {
2361         if Self::can_cast(syntax.kind()) { Some(PlaceholderType { syntax }) } else { None }
2362     }
2363     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2364 }
2365
2366
2367 impl PlaceholderType {}
2368
2369 // PointerType
2370 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2371 pub struct PointerType {
2372     pub(crate) syntax: SyntaxNode,
2373 }
2374
2375 impl AstNode for PointerType {
2376     fn can_cast(kind: SyntaxKind) -> bool {
2377         match kind {
2378             POINTER_TYPE => true,
2379             _ => false,
2380         }
2381     }
2382     fn cast(syntax: SyntaxNode) -> Option<Self> {
2383         if Self::can_cast(syntax.kind()) { Some(PointerType { syntax }) } else { None }
2384     }
2385     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2386 }
2387
2388
2389 impl PointerType {
2390     pub fn type_ref(&self) -> Option<TypeRef> {
2391         super::child_opt(self)
2392     }
2393 }
2394
2395 // PosFieldDef
2396 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2397 pub struct PosFieldDef {
2398     pub(crate) syntax: SyntaxNode,
2399 }
2400
2401 impl AstNode for PosFieldDef {
2402     fn can_cast(kind: SyntaxKind) -> bool {
2403         match kind {
2404             POS_FIELD_DEF => true,
2405             _ => false,
2406         }
2407     }
2408     fn cast(syntax: SyntaxNode) -> Option<Self> {
2409         if Self::can_cast(syntax.kind()) { Some(PosFieldDef { syntax }) } else { None }
2410     }
2411     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2412 }
2413
2414
2415 impl ast::VisibilityOwner for PosFieldDef {}
2416 impl ast::AttrsOwner for PosFieldDef {}
2417 impl PosFieldDef {
2418     pub fn type_ref(&self) -> Option<TypeRef> {
2419         super::child_opt(self)
2420     }
2421 }
2422
2423 // PosFieldDefList
2424 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2425 pub struct PosFieldDefList {
2426     pub(crate) syntax: SyntaxNode,
2427 }
2428
2429 impl AstNode for PosFieldDefList {
2430     fn can_cast(kind: SyntaxKind) -> bool {
2431         match kind {
2432             POS_FIELD_DEF_LIST => true,
2433             _ => false,
2434         }
2435     }
2436     fn cast(syntax: SyntaxNode) -> Option<Self> {
2437         if Self::can_cast(syntax.kind()) { Some(PosFieldDefList { syntax }) } else { None }
2438     }
2439     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2440 }
2441
2442
2443 impl PosFieldDefList {
2444     pub fn fields(&self) -> impl Iterator<Item = PosFieldDef> {
2445         super::children(self)
2446     }
2447 }
2448
2449 // PrefixExpr
2450 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2451 pub struct PrefixExpr {
2452     pub(crate) syntax: SyntaxNode,
2453 }
2454
2455 impl AstNode for PrefixExpr {
2456     fn can_cast(kind: SyntaxKind) -> bool {
2457         match kind {
2458             PREFIX_EXPR => true,
2459             _ => false,
2460         }
2461     }
2462     fn cast(syntax: SyntaxNode) -> Option<Self> {
2463         if Self::can_cast(syntax.kind()) { Some(PrefixExpr { syntax }) } else { None }
2464     }
2465     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2466 }
2467
2468
2469 impl PrefixExpr {
2470     pub fn expr(&self) -> Option<Expr> {
2471         super::child_opt(self)
2472     }
2473 }
2474
2475 // RangeExpr
2476 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2477 pub struct RangeExpr {
2478     pub(crate) syntax: SyntaxNode,
2479 }
2480
2481 impl AstNode for RangeExpr {
2482     fn can_cast(kind: SyntaxKind) -> bool {
2483         match kind {
2484             RANGE_EXPR => true,
2485             _ => false,
2486         }
2487     }
2488     fn cast(syntax: SyntaxNode) -> Option<Self> {
2489         if Self::can_cast(syntax.kind()) { Some(RangeExpr { syntax }) } else { None }
2490     }
2491     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2492 }
2493
2494
2495 impl RangeExpr {}
2496
2497 // RangePat
2498 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2499 pub struct RangePat {
2500     pub(crate) syntax: SyntaxNode,
2501 }
2502
2503 impl AstNode for RangePat {
2504     fn can_cast(kind: SyntaxKind) -> bool {
2505         match kind {
2506             RANGE_PAT => true,
2507             _ => false,
2508         }
2509     }
2510     fn cast(syntax: SyntaxNode) -> Option<Self> {
2511         if Self::can_cast(syntax.kind()) { Some(RangePat { syntax }) } else { None }
2512     }
2513     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2514 }
2515
2516
2517 impl RangePat {}
2518
2519 // RefExpr
2520 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2521 pub struct RefExpr {
2522     pub(crate) syntax: SyntaxNode,
2523 }
2524
2525 impl AstNode for RefExpr {
2526     fn can_cast(kind: SyntaxKind) -> bool {
2527         match kind {
2528             REF_EXPR => true,
2529             _ => false,
2530         }
2531     }
2532     fn cast(syntax: SyntaxNode) -> Option<Self> {
2533         if Self::can_cast(syntax.kind()) { Some(RefExpr { syntax }) } else { None }
2534     }
2535     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2536 }
2537
2538
2539 impl RefExpr {
2540     pub fn expr(&self) -> Option<Expr> {
2541         super::child_opt(self)
2542     }
2543 }
2544
2545 // RefPat
2546 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2547 pub struct RefPat {
2548     pub(crate) syntax: SyntaxNode,
2549 }
2550
2551 impl AstNode for RefPat {
2552     fn can_cast(kind: SyntaxKind) -> bool {
2553         match kind {
2554             REF_PAT => true,
2555             _ => false,
2556         }
2557     }
2558     fn cast(syntax: SyntaxNode) -> Option<Self> {
2559         if Self::can_cast(syntax.kind()) { Some(RefPat { syntax }) } else { None }
2560     }
2561     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2562 }
2563
2564
2565 impl RefPat {
2566     pub fn pat(&self) -> Option<Pat> {
2567         super::child_opt(self)
2568     }
2569 }
2570
2571 // ReferenceType
2572 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2573 pub struct ReferenceType {
2574     pub(crate) syntax: SyntaxNode,
2575 }
2576
2577 impl AstNode for ReferenceType {
2578     fn can_cast(kind: SyntaxKind) -> bool {
2579         match kind {
2580             REFERENCE_TYPE => true,
2581             _ => false,
2582         }
2583     }
2584     fn cast(syntax: SyntaxNode) -> Option<Self> {
2585         if Self::can_cast(syntax.kind()) { Some(ReferenceType { syntax }) } else { None }
2586     }
2587     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2588 }
2589
2590
2591 impl ReferenceType {
2592     pub fn type_ref(&self) -> Option<TypeRef> {
2593         super::child_opt(self)
2594     }
2595 }
2596
2597 // RetType
2598 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2599 pub struct RetType {
2600     pub(crate) syntax: SyntaxNode,
2601 }
2602
2603 impl AstNode for RetType {
2604     fn can_cast(kind: SyntaxKind) -> bool {
2605         match kind {
2606             RET_TYPE => true,
2607             _ => false,
2608         }
2609     }
2610     fn cast(syntax: SyntaxNode) -> Option<Self> {
2611         if Self::can_cast(syntax.kind()) { Some(RetType { syntax }) } else { None }
2612     }
2613     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2614 }
2615
2616
2617 impl RetType {
2618     pub fn type_ref(&self) -> Option<TypeRef> {
2619         super::child_opt(self)
2620     }
2621 }
2622
2623 // ReturnExpr
2624 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2625 pub struct ReturnExpr {
2626     pub(crate) syntax: SyntaxNode,
2627 }
2628
2629 impl AstNode for ReturnExpr {
2630     fn can_cast(kind: SyntaxKind) -> bool {
2631         match kind {
2632             RETURN_EXPR => true,
2633             _ => false,
2634         }
2635     }
2636     fn cast(syntax: SyntaxNode) -> Option<Self> {
2637         if Self::can_cast(syntax.kind()) { Some(ReturnExpr { syntax }) } else { None }
2638     }
2639     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2640 }
2641
2642
2643 impl ReturnExpr {
2644     pub fn expr(&self) -> Option<Expr> {
2645         super::child_opt(self)
2646     }
2647 }
2648
2649 // SelfParam
2650 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2651 pub struct SelfParam {
2652     pub(crate) syntax: SyntaxNode,
2653 }
2654
2655 impl AstNode for SelfParam {
2656     fn can_cast(kind: SyntaxKind) -> bool {
2657         match kind {
2658             SELF_PARAM => true,
2659             _ => false,
2660         }
2661     }
2662     fn cast(syntax: SyntaxNode) -> Option<Self> {
2663         if Self::can_cast(syntax.kind()) { Some(SelfParam { syntax }) } else { None }
2664     }
2665     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2666 }
2667
2668
2669 impl ast::TypeAscriptionOwner for SelfParam {}
2670 impl SelfParam {}
2671
2672 // SlicePat
2673 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2674 pub struct SlicePat {
2675     pub(crate) syntax: SyntaxNode,
2676 }
2677
2678 impl AstNode for SlicePat {
2679     fn can_cast(kind: SyntaxKind) -> bool {
2680         match kind {
2681             SLICE_PAT => true,
2682             _ => false,
2683         }
2684     }
2685     fn cast(syntax: SyntaxNode) -> Option<Self> {
2686         if Self::can_cast(syntax.kind()) { Some(SlicePat { syntax }) } else { None }
2687     }
2688     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2689 }
2690
2691
2692 impl SlicePat {}
2693
2694 // SliceType
2695 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2696 pub struct SliceType {
2697     pub(crate) syntax: SyntaxNode,
2698 }
2699
2700 impl AstNode for SliceType {
2701     fn can_cast(kind: SyntaxKind) -> bool {
2702         match kind {
2703             SLICE_TYPE => true,
2704             _ => false,
2705         }
2706     }
2707     fn cast(syntax: SyntaxNode) -> Option<Self> {
2708         if Self::can_cast(syntax.kind()) { Some(SliceType { syntax }) } else { None }
2709     }
2710     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2711 }
2712
2713
2714 impl SliceType {
2715     pub fn type_ref(&self) -> Option<TypeRef> {
2716         super::child_opt(self)
2717     }
2718 }
2719
2720 // SourceFile
2721 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2722 pub struct SourceFile {
2723     pub(crate) syntax: SyntaxNode,
2724 }
2725
2726 impl AstNode for SourceFile {
2727     fn can_cast(kind: SyntaxKind) -> bool {
2728         match kind {
2729             SOURCE_FILE => true,
2730             _ => false,
2731         }
2732     }
2733     fn cast(syntax: SyntaxNode) -> Option<Self> {
2734         if Self::can_cast(syntax.kind()) { Some(SourceFile { syntax }) } else { None }
2735     }
2736     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2737 }
2738
2739
2740 impl ast::ModuleItemOwner for SourceFile {}
2741 impl ast::FnDefOwner for SourceFile {}
2742 impl SourceFile {
2743     pub fn modules(&self) -> impl Iterator<Item = Module> {
2744         super::children(self)
2745     }
2746 }
2747
2748 // StaticDef
2749 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2750 pub struct StaticDef {
2751     pub(crate) syntax: SyntaxNode,
2752 }
2753
2754 impl AstNode for StaticDef {
2755     fn can_cast(kind: SyntaxKind) -> bool {
2756         match kind {
2757             STATIC_DEF => true,
2758             _ => false,
2759         }
2760     }
2761     fn cast(syntax: SyntaxNode) -> Option<Self> {
2762         if Self::can_cast(syntax.kind()) { Some(StaticDef { syntax }) } else { None }
2763     }
2764     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2765 }
2766
2767
2768 impl ast::VisibilityOwner for StaticDef {}
2769 impl ast::NameOwner for StaticDef {}
2770 impl ast::TypeParamsOwner for StaticDef {}
2771 impl ast::AttrsOwner for StaticDef {}
2772 impl ast::DocCommentsOwner for StaticDef {}
2773 impl ast::TypeAscriptionOwner for StaticDef {}
2774 impl StaticDef {
2775     pub fn body(&self) -> Option<Expr> {
2776         super::child_opt(self)
2777     }
2778 }
2779
2780 // Stmt
2781 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2782 pub struct Stmt {
2783     pub(crate) syntax: SyntaxNode,
2784 }
2785
2786 impl AstNode for Stmt {
2787     fn can_cast(kind: SyntaxKind) -> bool {
2788         match kind {
2789              | EXPR_STMT | LET_STMT => true,
2790             _ => false,
2791         }
2792     }
2793     fn cast(syntax: SyntaxNode) -> Option<Self> {
2794         if Self::can_cast(syntax.kind()) { Some(Stmt { syntax }) } else { None }
2795     }
2796     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2797 }
2798
2799
2800 #[derive(Debug, Clone, PartialEq, Eq)]
2801 pub enum StmtKind {
2802     ExprStmt(ExprStmt),
2803     LetStmt(LetStmt),
2804 }
2805 impl From<ExprStmt> for Stmt {
2806     fn from(n: ExprStmt) -> Stmt { Stmt { syntax: n.syntax } }
2807 }
2808 impl From<LetStmt> for Stmt {
2809     fn from(n: LetStmt) -> Stmt { Stmt { syntax: n.syntax } }
2810 }
2811 impl Stmt {
2812     pub fn kind(&self) -> StmtKind {
2813         match self.syntax.kind() {
2814             EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(self.syntax.clone()).unwrap()),
2815             LET_STMT => StmtKind::LetStmt(LetStmt::cast(self.syntax.clone()).unwrap()),
2816             _ => unreachable!(),
2817         }
2818     }
2819 }
2820
2821 impl Stmt {}
2822
2823 // StructDef
2824 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2825 pub struct StructDef {
2826     pub(crate) syntax: SyntaxNode,
2827 }
2828
2829 impl AstNode for StructDef {
2830     fn can_cast(kind: SyntaxKind) -> bool {
2831         match kind {
2832             STRUCT_DEF => true,
2833             _ => false,
2834         }
2835     }
2836     fn cast(syntax: SyntaxNode) -> Option<Self> {
2837         if Self::can_cast(syntax.kind()) { Some(StructDef { syntax }) } else { None }
2838     }
2839     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2840 }
2841
2842
2843 impl ast::VisibilityOwner for StructDef {}
2844 impl ast::NameOwner for StructDef {}
2845 impl ast::TypeParamsOwner for StructDef {}
2846 impl ast::AttrsOwner for StructDef {}
2847 impl ast::DocCommentsOwner for StructDef {}
2848 impl StructDef {}
2849
2850 // StructLit
2851 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2852 pub struct StructLit {
2853     pub(crate) syntax: SyntaxNode,
2854 }
2855
2856 impl AstNode for StructLit {
2857     fn can_cast(kind: SyntaxKind) -> bool {
2858         match kind {
2859             STRUCT_LIT => true,
2860             _ => false,
2861         }
2862     }
2863     fn cast(syntax: SyntaxNode) -> Option<Self> {
2864         if Self::can_cast(syntax.kind()) { Some(StructLit { syntax }) } else { None }
2865     }
2866     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2867 }
2868
2869
2870 impl StructLit {
2871     pub fn path(&self) -> Option<Path> {
2872         super::child_opt(self)
2873     }
2874
2875     pub fn named_field_list(&self) -> Option<NamedFieldList> {
2876         super::child_opt(self)
2877     }
2878 }
2879
2880 // StructPat
2881 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2882 pub struct StructPat {
2883     pub(crate) syntax: SyntaxNode,
2884 }
2885
2886 impl AstNode for StructPat {
2887     fn can_cast(kind: SyntaxKind) -> bool {
2888         match kind {
2889             STRUCT_PAT => true,
2890             _ => false,
2891         }
2892     }
2893     fn cast(syntax: SyntaxNode) -> Option<Self> {
2894         if Self::can_cast(syntax.kind()) { Some(StructPat { syntax }) } else { None }
2895     }
2896     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2897 }
2898
2899
2900 impl StructPat {
2901     pub fn field_pat_list(&self) -> Option<FieldPatList> {
2902         super::child_opt(self)
2903     }
2904
2905     pub fn path(&self) -> Option<Path> {
2906         super::child_opt(self)
2907     }
2908 }
2909
2910 // TokenTree
2911 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2912 pub struct TokenTree {
2913     pub(crate) syntax: SyntaxNode,
2914 }
2915
2916 impl AstNode for TokenTree {
2917     fn can_cast(kind: SyntaxKind) -> bool {
2918         match kind {
2919             TOKEN_TREE => true,
2920             _ => false,
2921         }
2922     }
2923     fn cast(syntax: SyntaxNode) -> Option<Self> {
2924         if Self::can_cast(syntax.kind()) { Some(TokenTree { syntax }) } else { None }
2925     }
2926     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2927 }
2928
2929
2930 impl TokenTree {}
2931
2932 // TraitDef
2933 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2934 pub struct TraitDef {
2935     pub(crate) syntax: SyntaxNode,
2936 }
2937
2938 impl AstNode for TraitDef {
2939     fn can_cast(kind: SyntaxKind) -> bool {
2940         match kind {
2941             TRAIT_DEF => true,
2942             _ => false,
2943         }
2944     }
2945     fn cast(syntax: SyntaxNode) -> Option<Self> {
2946         if Self::can_cast(syntax.kind()) { Some(TraitDef { syntax }) } else { None }
2947     }
2948     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2949 }
2950
2951
2952 impl ast::VisibilityOwner for TraitDef {}
2953 impl ast::NameOwner for TraitDef {}
2954 impl ast::AttrsOwner for TraitDef {}
2955 impl ast::DocCommentsOwner for TraitDef {}
2956 impl ast::TypeParamsOwner for TraitDef {}
2957 impl ast::TypeBoundsOwner for TraitDef {}
2958 impl TraitDef {
2959     pub fn item_list(&self) -> Option<ItemList> {
2960         super::child_opt(self)
2961     }
2962 }
2963
2964 // TryBlockExpr
2965 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2966 pub struct TryBlockExpr {
2967     pub(crate) syntax: SyntaxNode,
2968 }
2969
2970 impl AstNode for TryBlockExpr {
2971     fn can_cast(kind: SyntaxKind) -> bool {
2972         match kind {
2973             TRY_BLOCK_EXPR => true,
2974             _ => false,
2975         }
2976     }
2977     fn cast(syntax: SyntaxNode) -> Option<Self> {
2978         if Self::can_cast(syntax.kind()) { Some(TryBlockExpr { syntax }) } else { None }
2979     }
2980     fn syntax(&self) -> &SyntaxNode { &self.syntax }
2981 }
2982
2983
2984 impl ast::TryBlockBodyOwner for TryBlockExpr {}
2985 impl TryBlockExpr {}
2986
2987 // TryExpr
2988 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2989 pub struct TryExpr {
2990     pub(crate) syntax: SyntaxNode,
2991 }
2992
2993 impl AstNode for TryExpr {
2994     fn can_cast(kind: SyntaxKind) -> bool {
2995         match kind {
2996             TRY_EXPR => true,
2997             _ => false,
2998         }
2999     }
3000     fn cast(syntax: SyntaxNode) -> Option<Self> {
3001         if Self::can_cast(syntax.kind()) { Some(TryExpr { syntax }) } else { None }
3002     }
3003     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3004 }
3005
3006
3007 impl TryExpr {
3008     pub fn expr(&self) -> Option<Expr> {
3009         super::child_opt(self)
3010     }
3011 }
3012
3013 // TupleExpr
3014 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3015 pub struct TupleExpr {
3016     pub(crate) syntax: SyntaxNode,
3017 }
3018
3019 impl AstNode for TupleExpr {
3020     fn can_cast(kind: SyntaxKind) -> bool {
3021         match kind {
3022             TUPLE_EXPR => true,
3023             _ => false,
3024         }
3025     }
3026     fn cast(syntax: SyntaxNode) -> Option<Self> {
3027         if Self::can_cast(syntax.kind()) { Some(TupleExpr { syntax }) } else { None }
3028     }
3029     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3030 }
3031
3032
3033 impl TupleExpr {
3034     pub fn exprs(&self) -> impl Iterator<Item = Expr> {
3035         super::children(self)
3036     }
3037 }
3038
3039 // TuplePat
3040 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3041 pub struct TuplePat {
3042     pub(crate) syntax: SyntaxNode,
3043 }
3044
3045 impl AstNode for TuplePat {
3046     fn can_cast(kind: SyntaxKind) -> bool {
3047         match kind {
3048             TUPLE_PAT => true,
3049             _ => false,
3050         }
3051     }
3052     fn cast(syntax: SyntaxNode) -> Option<Self> {
3053         if Self::can_cast(syntax.kind()) { Some(TuplePat { syntax }) } else { None }
3054     }
3055     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3056 }
3057
3058
3059 impl TuplePat {
3060     pub fn args(&self) -> impl Iterator<Item = Pat> {
3061         super::children(self)
3062     }
3063 }
3064
3065 // TupleStructPat
3066 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3067 pub struct TupleStructPat {
3068     pub(crate) syntax: SyntaxNode,
3069 }
3070
3071 impl AstNode for TupleStructPat {
3072     fn can_cast(kind: SyntaxKind) -> bool {
3073         match kind {
3074             TUPLE_STRUCT_PAT => true,
3075             _ => false,
3076         }
3077     }
3078     fn cast(syntax: SyntaxNode) -> Option<Self> {
3079         if Self::can_cast(syntax.kind()) { Some(TupleStructPat { syntax }) } else { None }
3080     }
3081     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3082 }
3083
3084
3085 impl TupleStructPat {
3086     pub fn args(&self) -> impl Iterator<Item = Pat> {
3087         super::children(self)
3088     }
3089
3090     pub fn path(&self) -> Option<Path> {
3091         super::child_opt(self)
3092     }
3093 }
3094
3095 // TupleType
3096 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3097 pub struct TupleType {
3098     pub(crate) syntax: SyntaxNode,
3099 }
3100
3101 impl AstNode for TupleType {
3102     fn can_cast(kind: SyntaxKind) -> bool {
3103         match kind {
3104             TUPLE_TYPE => true,
3105             _ => false,
3106         }
3107     }
3108     fn cast(syntax: SyntaxNode) -> Option<Self> {
3109         if Self::can_cast(syntax.kind()) { Some(TupleType { syntax }) } else { None }
3110     }
3111     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3112 }
3113
3114
3115 impl TupleType {
3116     pub fn fields(&self) -> impl Iterator<Item = TypeRef> {
3117         super::children(self)
3118     }
3119 }
3120
3121 // TypeAliasDef
3122 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3123 pub struct TypeAliasDef {
3124     pub(crate) syntax: SyntaxNode,
3125 }
3126
3127 impl AstNode for TypeAliasDef {
3128     fn can_cast(kind: SyntaxKind) -> bool {
3129         match kind {
3130             TYPE_ALIAS_DEF => true,
3131             _ => false,
3132         }
3133     }
3134     fn cast(syntax: SyntaxNode) -> Option<Self> {
3135         if Self::can_cast(syntax.kind()) { Some(TypeAliasDef { syntax }) } else { None }
3136     }
3137     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3138 }
3139
3140
3141 impl ast::VisibilityOwner for TypeAliasDef {}
3142 impl ast::NameOwner for TypeAliasDef {}
3143 impl ast::TypeParamsOwner for TypeAliasDef {}
3144 impl ast::AttrsOwner for TypeAliasDef {}
3145 impl ast::DocCommentsOwner for TypeAliasDef {}
3146 impl ast::TypeBoundsOwner for TypeAliasDef {}
3147 impl TypeAliasDef {
3148     pub fn type_ref(&self) -> Option<TypeRef> {
3149         super::child_opt(self)
3150     }
3151 }
3152
3153 // TypeArg
3154 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3155 pub struct TypeArg {
3156     pub(crate) syntax: SyntaxNode,
3157 }
3158
3159 impl AstNode for TypeArg {
3160     fn can_cast(kind: SyntaxKind) -> bool {
3161         match kind {
3162             TYPE_ARG => true,
3163             _ => false,
3164         }
3165     }
3166     fn cast(syntax: SyntaxNode) -> Option<Self> {
3167         if Self::can_cast(syntax.kind()) { Some(TypeArg { syntax }) } else { None }
3168     }
3169     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3170 }
3171
3172
3173 impl TypeArg {
3174     pub fn type_ref(&self) -> Option<TypeRef> {
3175         super::child_opt(self)
3176     }
3177 }
3178
3179 // TypeArgList
3180 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3181 pub struct TypeArgList {
3182     pub(crate) syntax: SyntaxNode,
3183 }
3184
3185 impl AstNode for TypeArgList {
3186     fn can_cast(kind: SyntaxKind) -> bool {
3187         match kind {
3188             TYPE_ARG_LIST => true,
3189             _ => false,
3190         }
3191     }
3192     fn cast(syntax: SyntaxNode) -> Option<Self> {
3193         if Self::can_cast(syntax.kind()) { Some(TypeArgList { syntax }) } else { None }
3194     }
3195     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3196 }
3197
3198
3199 impl TypeArgList {
3200     pub fn type_args(&self) -> impl Iterator<Item = TypeArg> {
3201         super::children(self)
3202     }
3203
3204     pub fn lifetime_args(&self) -> impl Iterator<Item = LifetimeArg> {
3205         super::children(self)
3206     }
3207
3208     pub fn assoc_type_args(&self) -> impl Iterator<Item = AssocTypeArg> {
3209         super::children(self)
3210     }
3211 }
3212
3213 // TypeBound
3214 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3215 pub struct TypeBound {
3216     pub(crate) syntax: SyntaxNode,
3217 }
3218
3219 impl AstNode for TypeBound {
3220     fn can_cast(kind: SyntaxKind) -> bool {
3221         match kind {
3222             TYPE_BOUND => true,
3223             _ => false,
3224         }
3225     }
3226     fn cast(syntax: SyntaxNode) -> Option<Self> {
3227         if Self::can_cast(syntax.kind()) { Some(TypeBound { syntax }) } else { None }
3228     }
3229     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3230 }
3231
3232
3233 impl TypeBound {
3234     pub fn type_ref(&self) -> Option<TypeRef> {
3235         super::child_opt(self)
3236     }
3237 }
3238
3239 // TypeBoundList
3240 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3241 pub struct TypeBoundList {
3242     pub(crate) syntax: SyntaxNode,
3243 }
3244
3245 impl AstNode for TypeBoundList {
3246     fn can_cast(kind: SyntaxKind) -> bool {
3247         match kind {
3248             TYPE_BOUND_LIST => true,
3249             _ => false,
3250         }
3251     }
3252     fn cast(syntax: SyntaxNode) -> Option<Self> {
3253         if Self::can_cast(syntax.kind()) { Some(TypeBoundList { syntax }) } else { None }
3254     }
3255     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3256 }
3257
3258
3259 impl TypeBoundList {
3260     pub fn bounds(&self) -> impl Iterator<Item = TypeBound> {
3261         super::children(self)
3262     }
3263 }
3264
3265 // TypeParam
3266 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3267 pub struct TypeParam {
3268     pub(crate) syntax: SyntaxNode,
3269 }
3270
3271 impl AstNode for TypeParam {
3272     fn can_cast(kind: SyntaxKind) -> bool {
3273         match kind {
3274             TYPE_PARAM => true,
3275             _ => false,
3276         }
3277     }
3278     fn cast(syntax: SyntaxNode) -> Option<Self> {
3279         if Self::can_cast(syntax.kind()) { Some(TypeParam { syntax }) } else { None }
3280     }
3281     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3282 }
3283
3284
3285 impl ast::NameOwner for TypeParam {}
3286 impl ast::AttrsOwner for TypeParam {}
3287 impl ast::TypeBoundsOwner for TypeParam {}
3288 impl ast::DefaultTypeParamOwner for TypeParam {}
3289 impl TypeParam {}
3290
3291 // TypeParamList
3292 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3293 pub struct TypeParamList {
3294     pub(crate) syntax: SyntaxNode,
3295 }
3296
3297 impl AstNode for TypeParamList {
3298     fn can_cast(kind: SyntaxKind) -> bool {
3299         match kind {
3300             TYPE_PARAM_LIST => true,
3301             _ => false,
3302         }
3303     }
3304     fn cast(syntax: SyntaxNode) -> Option<Self> {
3305         if Self::can_cast(syntax.kind()) { Some(TypeParamList { syntax }) } else { None }
3306     }
3307     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3308 }
3309
3310
3311 impl TypeParamList {
3312     pub fn type_params(&self) -> impl Iterator<Item = TypeParam> {
3313         super::children(self)
3314     }
3315
3316     pub fn lifetime_params(&self) -> impl Iterator<Item = LifetimeParam> {
3317         super::children(self)
3318     }
3319 }
3320
3321 // TypeRef
3322 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3323 pub struct TypeRef {
3324     pub(crate) syntax: SyntaxNode,
3325 }
3326
3327 impl AstNode for TypeRef {
3328     fn can_cast(kind: SyntaxKind) -> bool {
3329         match kind {
3330              | 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,
3331             _ => false,
3332         }
3333     }
3334     fn cast(syntax: SyntaxNode) -> Option<Self> {
3335         if Self::can_cast(syntax.kind()) { Some(TypeRef { syntax }) } else { None }
3336     }
3337     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3338 }
3339
3340
3341 #[derive(Debug, Clone, PartialEq, Eq)]
3342 pub enum TypeRefKind {
3343     ParenType(ParenType),
3344     TupleType(TupleType),
3345     NeverType(NeverType),
3346     PathType(PathType),
3347     PointerType(PointerType),
3348     ArrayType(ArrayType),
3349     SliceType(SliceType),
3350     ReferenceType(ReferenceType),
3351     PlaceholderType(PlaceholderType),
3352     FnPointerType(FnPointerType),
3353     ForType(ForType),
3354     ImplTraitType(ImplTraitType),
3355     DynTraitType(DynTraitType),
3356 }
3357 impl From<ParenType> for TypeRef {
3358     fn from(n: ParenType) -> TypeRef { TypeRef { syntax: n.syntax } }
3359 }
3360 impl From<TupleType> for TypeRef {
3361     fn from(n: TupleType) -> TypeRef { TypeRef { syntax: n.syntax } }
3362 }
3363 impl From<NeverType> for TypeRef {
3364     fn from(n: NeverType) -> TypeRef { TypeRef { syntax: n.syntax } }
3365 }
3366 impl From<PathType> for TypeRef {
3367     fn from(n: PathType) -> TypeRef { TypeRef { syntax: n.syntax } }
3368 }
3369 impl From<PointerType> for TypeRef {
3370     fn from(n: PointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3371 }
3372 impl From<ArrayType> for TypeRef {
3373     fn from(n: ArrayType) -> TypeRef { TypeRef { syntax: n.syntax } }
3374 }
3375 impl From<SliceType> for TypeRef {
3376     fn from(n: SliceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3377 }
3378 impl From<ReferenceType> for TypeRef {
3379     fn from(n: ReferenceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3380 }
3381 impl From<PlaceholderType> for TypeRef {
3382     fn from(n: PlaceholderType) -> TypeRef { TypeRef { syntax: n.syntax } }
3383 }
3384 impl From<FnPointerType> for TypeRef {
3385     fn from(n: FnPointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3386 }
3387 impl From<ForType> for TypeRef {
3388     fn from(n: ForType) -> TypeRef { TypeRef { syntax: n.syntax } }
3389 }
3390 impl From<ImplTraitType> for TypeRef {
3391     fn from(n: ImplTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3392 }
3393 impl From<DynTraitType> for TypeRef {
3394     fn from(n: DynTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3395 }
3396 impl TypeRef {
3397     pub fn kind(&self) -> TypeRefKind {
3398         match self.syntax.kind() {
3399             PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(self.syntax.clone()).unwrap()),
3400             TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(self.syntax.clone()).unwrap()),
3401             NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(self.syntax.clone()).unwrap()),
3402             PATH_TYPE => TypeRefKind::PathType(PathType::cast(self.syntax.clone()).unwrap()),
3403             POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(self.syntax.clone()).unwrap()),
3404             ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(self.syntax.clone()).unwrap()),
3405             SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(self.syntax.clone()).unwrap()),
3406             REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(self.syntax.clone()).unwrap()),
3407             PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(self.syntax.clone()).unwrap()),
3408             FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(self.syntax.clone()).unwrap()),
3409             FOR_TYPE => TypeRefKind::ForType(ForType::cast(self.syntax.clone()).unwrap()),
3410             IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(self.syntax.clone()).unwrap()),
3411             DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(self.syntax.clone()).unwrap()),
3412             _ => unreachable!(),
3413         }
3414     }
3415 }
3416
3417 impl TypeRef {}
3418
3419 // UseItem
3420 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3421 pub struct UseItem {
3422     pub(crate) syntax: SyntaxNode,
3423 }
3424
3425 impl AstNode for UseItem {
3426     fn can_cast(kind: SyntaxKind) -> bool {
3427         match kind {
3428             USE_ITEM => true,
3429             _ => false,
3430         }
3431     }
3432     fn cast(syntax: SyntaxNode) -> Option<Self> {
3433         if Self::can_cast(syntax.kind()) { Some(UseItem { syntax }) } else { None }
3434     }
3435     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3436 }
3437
3438
3439 impl ast::AttrsOwner for UseItem {}
3440 impl UseItem {
3441     pub fn use_tree(&self) -> Option<UseTree> {
3442         super::child_opt(self)
3443     }
3444 }
3445
3446 // UseTree
3447 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3448 pub struct UseTree {
3449     pub(crate) syntax: SyntaxNode,
3450 }
3451
3452 impl AstNode for UseTree {
3453     fn can_cast(kind: SyntaxKind) -> bool {
3454         match kind {
3455             USE_TREE => true,
3456             _ => false,
3457         }
3458     }
3459     fn cast(syntax: SyntaxNode) -> Option<Self> {
3460         if Self::can_cast(syntax.kind()) { Some(UseTree { syntax }) } else { None }
3461     }
3462     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3463 }
3464
3465
3466 impl UseTree {
3467     pub fn path(&self) -> Option<Path> {
3468         super::child_opt(self)
3469     }
3470
3471     pub fn use_tree_list(&self) -> Option<UseTreeList> {
3472         super::child_opt(self)
3473     }
3474
3475     pub fn alias(&self) -> Option<Alias> {
3476         super::child_opt(self)
3477     }
3478 }
3479
3480 // UseTreeList
3481 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3482 pub struct UseTreeList {
3483     pub(crate) syntax: SyntaxNode,
3484 }
3485
3486 impl AstNode for UseTreeList {
3487     fn can_cast(kind: SyntaxKind) -> bool {
3488         match kind {
3489             USE_TREE_LIST => true,
3490             _ => false,
3491         }
3492     }
3493     fn cast(syntax: SyntaxNode) -> Option<Self> {
3494         if Self::can_cast(syntax.kind()) { Some(UseTreeList { syntax }) } else { None }
3495     }
3496     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3497 }
3498
3499
3500 impl UseTreeList {
3501     pub fn use_trees(&self) -> impl Iterator<Item = UseTree> {
3502         super::children(self)
3503     }
3504 }
3505
3506 // Visibility
3507 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3508 pub struct Visibility {
3509     pub(crate) syntax: SyntaxNode,
3510 }
3511
3512 impl AstNode for Visibility {
3513     fn can_cast(kind: SyntaxKind) -> bool {
3514         match kind {
3515             VISIBILITY => true,
3516             _ => false,
3517         }
3518     }
3519     fn cast(syntax: SyntaxNode) -> Option<Self> {
3520         if Self::can_cast(syntax.kind()) { Some(Visibility { syntax }) } else { None }
3521     }
3522     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3523 }
3524
3525
3526 impl Visibility {}
3527
3528 // WhereClause
3529 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3530 pub struct WhereClause {
3531     pub(crate) syntax: SyntaxNode,
3532 }
3533
3534 impl AstNode for WhereClause {
3535     fn can_cast(kind: SyntaxKind) -> bool {
3536         match kind {
3537             WHERE_CLAUSE => true,
3538             _ => false,
3539         }
3540     }
3541     fn cast(syntax: SyntaxNode) -> Option<Self> {
3542         if Self::can_cast(syntax.kind()) { Some(WhereClause { syntax }) } else { None }
3543     }
3544     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3545 }
3546
3547
3548 impl WhereClause {
3549     pub fn predicates(&self) -> impl Iterator<Item = WherePred> {
3550         super::children(self)
3551     }
3552 }
3553
3554 // WherePred
3555 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3556 pub struct WherePred {
3557     pub(crate) syntax: SyntaxNode,
3558 }
3559
3560 impl AstNode for WherePred {
3561     fn can_cast(kind: SyntaxKind) -> bool {
3562         match kind {
3563             WHERE_PRED => true,
3564             _ => false,
3565         }
3566     }
3567     fn cast(syntax: SyntaxNode) -> Option<Self> {
3568         if Self::can_cast(syntax.kind()) { Some(WherePred { syntax }) } else { None }
3569     }
3570     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3571 }
3572
3573
3574 impl ast::TypeBoundsOwner for WherePred {}
3575 impl WherePred {
3576     pub fn type_ref(&self) -> Option<TypeRef> {
3577         super::child_opt(self)
3578     }
3579 }
3580
3581 // WhileExpr
3582 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3583 pub struct WhileExpr {
3584     pub(crate) syntax: SyntaxNode,
3585 }
3586
3587 impl AstNode for WhileExpr {
3588     fn can_cast(kind: SyntaxKind) -> bool {
3589         match kind {
3590             WHILE_EXPR => true,
3591             _ => false,
3592         }
3593     }
3594     fn cast(syntax: SyntaxNode) -> Option<Self> {
3595         if Self::can_cast(syntax.kind()) { Some(WhileExpr { syntax }) } else { None }
3596     }
3597     fn syntax(&self) -> &SyntaxNode { &self.syntax }
3598 }
3599
3600
3601 impl ast::LoopBodyOwner for WhileExpr {}
3602 impl WhileExpr {
3603     pub fn condition(&self) -> Option<Condition> {
3604         super::child_opt(self)
3605     }
3606 }
3607