1 // This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
2 // Do not edit manually
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.
10 #![cfg_attr(rustfmt, rustfmt_skip)]
13 SyntaxNode, SyntaxKind::{self, *},
18 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
20 pub(crate) syntax: SyntaxNode,
23 impl AstNode for Alias {
24 fn can_cast(kind: SyntaxKind) -> bool {
30 fn cast(syntax: SyntaxNode) -> Option<Self> {
31 if Self::can_cast(syntax.kind()) { Some(Alias { syntax }) } else { None }
33 fn syntax(&self) -> &SyntaxNode { &self.syntax }
37 impl ast::NameOwner for Alias {}
41 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
43 pub(crate) syntax: SyntaxNode,
46 impl AstNode for ArgList {
47 fn can_cast(kind: SyntaxKind) -> bool {
53 fn cast(syntax: SyntaxNode) -> Option<Self> {
54 if Self::can_cast(syntax.kind()) { Some(ArgList { syntax }) } else { None }
56 fn syntax(&self) -> &SyntaxNode { &self.syntax }
61 pub fn args(&self) -> impl Iterator<Item = Expr> {
67 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
68 pub struct ArrayExpr {
69 pub(crate) syntax: SyntaxNode,
72 impl AstNode for ArrayExpr {
73 fn can_cast(kind: SyntaxKind) -> bool {
79 fn cast(syntax: SyntaxNode) -> Option<Self> {
80 if Self::can_cast(syntax.kind()) { Some(ArrayExpr { syntax }) } else { None }
82 fn syntax(&self) -> &SyntaxNode { &self.syntax }
87 pub fn exprs(&self) -> impl Iterator<Item = Expr> {
93 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
94 pub struct ArrayType {
95 pub(crate) syntax: SyntaxNode,
98 impl AstNode for ArrayType {
99 fn can_cast(kind: SyntaxKind) -> bool {
105 fn cast(syntax: SyntaxNode) -> Option<Self> {
106 if Self::can_cast(syntax.kind()) { Some(ArrayType { syntax }) } else { None }
108 fn syntax(&self) -> &SyntaxNode { &self.syntax }
113 pub fn type_ref(&self) -> Option<TypeRef> {
114 super::child_opt(self)
117 pub fn expr(&self) -> Option<Expr> {
118 super::child_opt(self)
123 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
124 pub struct AssocTypeArg {
125 pub(crate) syntax: SyntaxNode,
128 impl AstNode for AssocTypeArg {
129 fn can_cast(kind: SyntaxKind) -> bool {
131 ASSOC_TYPE_ARG => true,
135 fn cast(syntax: SyntaxNode) -> Option<Self> {
136 if Self::can_cast(syntax.kind()) { Some(AssocTypeArg { syntax }) } else { None }
138 fn syntax(&self) -> &SyntaxNode { &self.syntax }
143 pub fn name_ref(&self) -> Option<NameRef> {
144 super::child_opt(self)
147 pub fn type_ref(&self) -> Option<TypeRef> {
148 super::child_opt(self)
153 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
155 pub(crate) syntax: SyntaxNode,
158 impl AstNode for Attr {
159 fn can_cast(kind: SyntaxKind) -> bool {
165 fn cast(syntax: SyntaxNode) -> Option<Self> {
166 if Self::can_cast(syntax.kind()) { Some(Attr { syntax }) } else { None }
168 fn syntax(&self) -> &SyntaxNode { &self.syntax }
173 pub fn value(&self) -> Option<TokenTree> {
174 super::child_opt(self)
179 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
180 pub struct AwaitExpr {
181 pub(crate) syntax: SyntaxNode,
184 impl AstNode for AwaitExpr {
185 fn can_cast(kind: SyntaxKind) -> bool {
191 fn cast(syntax: SyntaxNode) -> Option<Self> {
192 if Self::can_cast(syntax.kind()) { Some(AwaitExpr { syntax }) } else { None }
194 fn syntax(&self) -> &SyntaxNode { &self.syntax }
199 pub fn expr(&self) -> Option<Expr> {
200 super::child_opt(self)
205 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
207 pub(crate) syntax: SyntaxNode,
210 impl AstNode for BinExpr {
211 fn can_cast(kind: SyntaxKind) -> bool {
217 fn cast(syntax: SyntaxNode) -> Option<Self> {
218 if Self::can_cast(syntax.kind()) { Some(BinExpr { syntax }) } else { None }
220 fn syntax(&self) -> &SyntaxNode { &self.syntax }
227 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
229 pub(crate) syntax: SyntaxNode,
232 impl AstNode for BindPat {
233 fn can_cast(kind: SyntaxKind) -> bool {
239 fn cast(syntax: SyntaxNode) -> Option<Self> {
240 if Self::can_cast(syntax.kind()) { Some(BindPat { syntax }) } else { None }
242 fn syntax(&self) -> &SyntaxNode { &self.syntax }
246 impl ast::NameOwner for BindPat {}
248 pub fn pat(&self) -> Option<Pat> {
249 super::child_opt(self)
254 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
256 pub(crate) syntax: SyntaxNode,
259 impl AstNode for Block {
260 fn can_cast(kind: SyntaxKind) -> bool {
266 fn cast(syntax: SyntaxNode) -> Option<Self> {
267 if Self::can_cast(syntax.kind()) { Some(Block { syntax }) } else { None }
269 fn syntax(&self) -> &SyntaxNode { &self.syntax }
273 impl ast::AttrsOwner for Block {}
275 pub fn statements(&self) -> impl Iterator<Item = Stmt> {
276 super::children(self)
279 pub fn expr(&self) -> Option<Expr> {
280 super::child_opt(self)
285 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
286 pub struct BlockExpr {
287 pub(crate) syntax: SyntaxNode,
290 impl AstNode for BlockExpr {
291 fn can_cast(kind: SyntaxKind) -> bool {
297 fn cast(syntax: SyntaxNode) -> Option<Self> {
298 if Self::can_cast(syntax.kind()) { Some(BlockExpr { syntax }) } else { None }
300 fn syntax(&self) -> &SyntaxNode { &self.syntax }
305 pub fn block(&self) -> Option<Block> {
306 super::child_opt(self)
311 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
312 pub struct BreakExpr {
313 pub(crate) syntax: SyntaxNode,
316 impl AstNode for BreakExpr {
317 fn can_cast(kind: SyntaxKind) -> bool {
323 fn cast(syntax: SyntaxNode) -> Option<Self> {
324 if Self::can_cast(syntax.kind()) { Some(BreakExpr { syntax }) } else { None }
326 fn syntax(&self) -> &SyntaxNode { &self.syntax }
331 pub fn expr(&self) -> Option<Expr> {
332 super::child_opt(self)
337 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
338 pub struct CallExpr {
339 pub(crate) syntax: SyntaxNode,
342 impl AstNode for CallExpr {
343 fn can_cast(kind: SyntaxKind) -> bool {
349 fn cast(syntax: SyntaxNode) -> Option<Self> {
350 if Self::can_cast(syntax.kind()) { Some(CallExpr { syntax }) } else { None }
352 fn syntax(&self) -> &SyntaxNode { &self.syntax }
356 impl ast::ArgListOwner for CallExpr {}
358 pub fn expr(&self) -> Option<Expr> {
359 super::child_opt(self)
364 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
365 pub struct CastExpr {
366 pub(crate) syntax: SyntaxNode,
369 impl AstNode for CastExpr {
370 fn can_cast(kind: SyntaxKind) -> bool {
376 fn cast(syntax: SyntaxNode) -> Option<Self> {
377 if Self::can_cast(syntax.kind()) { Some(CastExpr { syntax }) } else { None }
379 fn syntax(&self) -> &SyntaxNode { &self.syntax }
384 pub fn expr(&self) -> Option<Expr> {
385 super::child_opt(self)
388 pub fn type_ref(&self) -> Option<TypeRef> {
389 super::child_opt(self)
394 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
395 pub struct Condition {
396 pub(crate) syntax: SyntaxNode,
399 impl AstNode for Condition {
400 fn can_cast(kind: SyntaxKind) -> bool {
406 fn cast(syntax: SyntaxNode) -> Option<Self> {
407 if Self::can_cast(syntax.kind()) { Some(Condition { syntax }) } else { None }
409 fn syntax(&self) -> &SyntaxNode { &self.syntax }
414 pub fn pat(&self) -> Option<Pat> {
415 super::child_opt(self)
418 pub fn expr(&self) -> Option<Expr> {
419 super::child_opt(self)
424 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
425 pub struct ConstDef {
426 pub(crate) syntax: SyntaxNode,
429 impl AstNode for ConstDef {
430 fn can_cast(kind: SyntaxKind) -> bool {
436 fn cast(syntax: SyntaxNode) -> Option<Self> {
437 if Self::can_cast(syntax.kind()) { Some(ConstDef { syntax }) } else { None }
439 fn syntax(&self) -> &SyntaxNode { &self.syntax }
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 {}
450 pub fn body(&self) -> Option<Expr> {
451 super::child_opt(self)
456 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
457 pub struct ContinueExpr {
458 pub(crate) syntax: SyntaxNode,
461 impl AstNode for ContinueExpr {
462 fn can_cast(kind: SyntaxKind) -> bool {
464 CONTINUE_EXPR => true,
468 fn cast(syntax: SyntaxNode) -> Option<Self> {
469 if Self::can_cast(syntax.kind()) { Some(ContinueExpr { syntax }) } else { None }
471 fn syntax(&self) -> &SyntaxNode { &self.syntax }
478 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
479 pub struct DynTraitType {
480 pub(crate) syntax: SyntaxNode,
483 impl AstNode for DynTraitType {
484 fn can_cast(kind: SyntaxKind) -> bool {
486 DYN_TRAIT_TYPE => true,
490 fn cast(syntax: SyntaxNode) -> Option<Self> {
491 if Self::can_cast(syntax.kind()) { Some(DynTraitType { syntax }) } else { None }
493 fn syntax(&self) -> &SyntaxNode { &self.syntax }
497 impl ast::TypeBoundsOwner for DynTraitType {}
501 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
503 pub(crate) syntax: SyntaxNode,
506 impl AstNode for EnumDef {
507 fn can_cast(kind: SyntaxKind) -> bool {
513 fn cast(syntax: SyntaxNode) -> Option<Self> {
514 if Self::can_cast(syntax.kind()) { Some(EnumDef { syntax }) } else { None }
516 fn syntax(&self) -> &SyntaxNode { &self.syntax }
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 {}
526 pub fn variant_list(&self) -> Option<EnumVariantList> {
527 super::child_opt(self)
532 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
533 pub struct EnumVariant {
534 pub(crate) syntax: SyntaxNode,
537 impl AstNode for EnumVariant {
538 fn can_cast(kind: SyntaxKind) -> bool {
540 ENUM_VARIANT => true,
544 fn cast(syntax: SyntaxNode) -> Option<Self> {
545 if Self::can_cast(syntax.kind()) { Some(EnumVariant { syntax }) } else { None }
547 fn syntax(&self) -> &SyntaxNode { &self.syntax }
551 impl ast::NameOwner for EnumVariant {}
552 impl ast::DocCommentsOwner for EnumVariant {}
553 impl ast::AttrsOwner for EnumVariant {}
555 pub fn expr(&self) -> Option<Expr> {
556 super::child_opt(self)
561 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
562 pub struct EnumVariantList {
563 pub(crate) syntax: SyntaxNode,
566 impl AstNode for EnumVariantList {
567 fn can_cast(kind: SyntaxKind) -> bool {
569 ENUM_VARIANT_LIST => true,
573 fn cast(syntax: SyntaxNode) -> Option<Self> {
574 if Self::can_cast(syntax.kind()) { Some(EnumVariantList { syntax }) } else { None }
576 fn syntax(&self) -> &SyntaxNode { &self.syntax }
580 impl EnumVariantList {
581 pub fn variants(&self) -> impl Iterator<Item = EnumVariant> {
582 super::children(self)
587 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
589 pub(crate) syntax: SyntaxNode,
592 impl AstNode for Expr {
593 fn can_cast(kind: SyntaxKind) -> bool {
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,
599 fn cast(syntax: SyntaxNode) -> Option<Self> {
600 if Self::can_cast(syntax.kind()) { Some(Expr { syntax }) } else { None }
602 fn syntax(&self) -> &SyntaxNode { &self.syntax }
606 #[derive(Debug, Clone, PartialEq, Eq)]
608 TupleExpr(TupleExpr),
609 ArrayExpr(ArrayExpr),
610 ParenExpr(ParenExpr),
612 LambdaExpr(LambdaExpr),
616 WhileExpr(WhileExpr),
617 ContinueExpr(ContinueExpr),
618 BreakExpr(BreakExpr),
620 BlockExpr(BlockExpr),
621 ReturnExpr(ReturnExpr),
622 MatchExpr(MatchExpr),
623 StructLit(StructLit),
625 IndexExpr(IndexExpr),
626 MethodCallExpr(MethodCallExpr),
627 FieldExpr(FieldExpr),
628 AwaitExpr(AwaitExpr),
630 TryBlockExpr(TryBlockExpr),
633 PrefixExpr(PrefixExpr),
634 RangeExpr(RangeExpr),
637 MacroCall(MacroCall),
639 impl From<TupleExpr> for Expr {
640 fn from(n: TupleExpr) -> Expr { Expr { syntax: n.syntax } }
642 impl From<ArrayExpr> for Expr {
643 fn from(n: ArrayExpr) -> Expr { Expr { syntax: n.syntax } }
645 impl From<ParenExpr> for Expr {
646 fn from(n: ParenExpr) -> Expr { Expr { syntax: n.syntax } }
648 impl From<PathExpr> for Expr {
649 fn from(n: PathExpr) -> Expr { Expr { syntax: n.syntax } }
651 impl From<LambdaExpr> for Expr {
652 fn from(n: LambdaExpr) -> Expr { Expr { syntax: n.syntax } }
654 impl From<IfExpr> for Expr {
655 fn from(n: IfExpr) -> Expr { Expr { syntax: n.syntax } }
657 impl From<LoopExpr> for Expr {
658 fn from(n: LoopExpr) -> Expr { Expr { syntax: n.syntax } }
660 impl From<ForExpr> for Expr {
661 fn from(n: ForExpr) -> Expr { Expr { syntax: n.syntax } }
663 impl From<WhileExpr> for Expr {
664 fn from(n: WhileExpr) -> Expr { Expr { syntax: n.syntax } }
666 impl From<ContinueExpr> for Expr {
667 fn from(n: ContinueExpr) -> Expr { Expr { syntax: n.syntax } }
669 impl From<BreakExpr> for Expr {
670 fn from(n: BreakExpr) -> Expr { Expr { syntax: n.syntax } }
672 impl From<Label> for Expr {
673 fn from(n: Label) -> Expr { Expr { syntax: n.syntax } }
675 impl From<BlockExpr> for Expr {
676 fn from(n: BlockExpr) -> Expr { Expr { syntax: n.syntax } }
678 impl From<ReturnExpr> for Expr {
679 fn from(n: ReturnExpr) -> Expr { Expr { syntax: n.syntax } }
681 impl From<MatchExpr> for Expr {
682 fn from(n: MatchExpr) -> Expr { Expr { syntax: n.syntax } }
684 impl From<StructLit> for Expr {
685 fn from(n: StructLit) -> Expr { Expr { syntax: n.syntax } }
687 impl From<CallExpr> for Expr {
688 fn from(n: CallExpr) -> Expr { Expr { syntax: n.syntax } }
690 impl From<IndexExpr> for Expr {
691 fn from(n: IndexExpr) -> Expr { Expr { syntax: n.syntax } }
693 impl From<MethodCallExpr> for Expr {
694 fn from(n: MethodCallExpr) -> Expr { Expr { syntax: n.syntax } }
696 impl From<FieldExpr> for Expr {
697 fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } }
699 impl From<AwaitExpr> for Expr {
700 fn from(n: AwaitExpr) -> Expr { Expr { syntax: n.syntax } }
702 impl From<TryExpr> for Expr {
703 fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } }
705 impl From<TryBlockExpr> for Expr {
706 fn from(n: TryBlockExpr) -> Expr { Expr { syntax: n.syntax } }
708 impl From<CastExpr> for Expr {
709 fn from(n: CastExpr) -> Expr { Expr { syntax: n.syntax } }
711 impl From<RefExpr> for Expr {
712 fn from(n: RefExpr) -> Expr { Expr { syntax: n.syntax } }
714 impl From<PrefixExpr> for Expr {
715 fn from(n: PrefixExpr) -> Expr { Expr { syntax: n.syntax } }
717 impl From<RangeExpr> for Expr {
718 fn from(n: RangeExpr) -> Expr { Expr { syntax: n.syntax } }
720 impl From<BinExpr> for Expr {
721 fn from(n: BinExpr) -> Expr { Expr { syntax: n.syntax } }
723 impl From<Literal> for Expr {
724 fn from(n: Literal) -> Expr { Expr { syntax: n.syntax } }
726 impl From<MacroCall> for Expr {
727 fn from(n: MacroCall) -> Expr { Expr { syntax: n.syntax } }
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()),
770 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
771 pub struct ExprStmt {
772 pub(crate) syntax: SyntaxNode,
775 impl AstNode for ExprStmt {
776 fn can_cast(kind: SyntaxKind) -> bool {
782 fn cast(syntax: SyntaxNode) -> Option<Self> {
783 if Self::can_cast(syntax.kind()) { Some(ExprStmt { syntax }) } else { None }
785 fn syntax(&self) -> &SyntaxNode { &self.syntax }
790 pub fn expr(&self) -> Option<Expr> {
791 super::child_opt(self)
796 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
797 pub struct ExternCrateItem {
798 pub(crate) syntax: SyntaxNode,
801 impl AstNode for ExternCrateItem {
802 fn can_cast(kind: SyntaxKind) -> bool {
804 EXTERN_CRATE_ITEM => true,
808 fn cast(syntax: SyntaxNode) -> Option<Self> {
809 if Self::can_cast(syntax.kind()) { Some(ExternCrateItem { syntax }) } else { None }
811 fn syntax(&self) -> &SyntaxNode { &self.syntax }
815 impl ExternCrateItem {
816 pub fn name_ref(&self) -> Option<NameRef> {
817 super::child_opt(self)
820 pub fn alias(&self) -> Option<Alias> {
821 super::child_opt(self)
826 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
827 pub struct FieldExpr {
828 pub(crate) syntax: SyntaxNode,
831 impl AstNode for FieldExpr {
832 fn can_cast(kind: SyntaxKind) -> bool {
838 fn cast(syntax: SyntaxNode) -> Option<Self> {
839 if Self::can_cast(syntax.kind()) { Some(FieldExpr { syntax }) } else { None }
841 fn syntax(&self) -> &SyntaxNode { &self.syntax }
846 pub fn expr(&self) -> Option<Expr> {
847 super::child_opt(self)
850 pub fn name_ref(&self) -> Option<NameRef> {
851 super::child_opt(self)
856 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
857 pub struct FieldPat {
858 pub(crate) syntax: SyntaxNode,
861 impl AstNode for FieldPat {
862 fn can_cast(kind: SyntaxKind) -> bool {
868 fn cast(syntax: SyntaxNode) -> Option<Self> {
869 if Self::can_cast(syntax.kind()) { Some(FieldPat { syntax }) } else { None }
871 fn syntax(&self) -> &SyntaxNode { &self.syntax }
875 impl ast::NameOwner for FieldPat {}
877 pub fn pat(&self) -> Option<Pat> {
878 super::child_opt(self)
883 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
884 pub struct FieldPatList {
885 pub(crate) syntax: SyntaxNode,
888 impl AstNode for FieldPatList {
889 fn can_cast(kind: SyntaxKind) -> bool {
891 FIELD_PAT_LIST => true,
895 fn cast(syntax: SyntaxNode) -> Option<Self> {
896 if Self::can_cast(syntax.kind()) { Some(FieldPatList { syntax }) } else { None }
898 fn syntax(&self) -> &SyntaxNode { &self.syntax }
903 pub fn field_pats(&self) -> impl Iterator<Item = FieldPat> {
904 super::children(self)
907 pub fn bind_pats(&self) -> impl Iterator<Item = BindPat> {
908 super::children(self)
913 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
915 pub(crate) syntax: SyntaxNode,
918 impl AstNode for FnDef {
919 fn can_cast(kind: SyntaxKind) -> bool {
925 fn cast(syntax: SyntaxNode) -> Option<Self> {
926 if Self::can_cast(syntax.kind()) { Some(FnDef { syntax }) } else { None }
928 fn syntax(&self) -> &SyntaxNode { &self.syntax }
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 {}
938 pub fn param_list(&self) -> Option<ParamList> {
939 super::child_opt(self)
942 pub fn body(&self) -> Option<Block> {
943 super::child_opt(self)
946 pub fn ret_type(&self) -> Option<RetType> {
947 super::child_opt(self)
952 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
953 pub struct FnPointerType {
954 pub(crate) syntax: SyntaxNode,
957 impl AstNode for FnPointerType {
958 fn can_cast(kind: SyntaxKind) -> bool {
960 FN_POINTER_TYPE => true,
964 fn cast(syntax: SyntaxNode) -> Option<Self> {
965 if Self::can_cast(syntax.kind()) { Some(FnPointerType { syntax }) } else { None }
967 fn syntax(&self) -> &SyntaxNode { &self.syntax }
972 pub fn param_list(&self) -> Option<ParamList> {
973 super::child_opt(self)
976 pub fn ret_type(&self) -> Option<RetType> {
977 super::child_opt(self)
982 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
984 pub(crate) syntax: SyntaxNode,
987 impl AstNode for ForExpr {
988 fn can_cast(kind: SyntaxKind) -> bool {
994 fn cast(syntax: SyntaxNode) -> Option<Self> {
995 if Self::can_cast(syntax.kind()) { Some(ForExpr { syntax }) } else { None }
997 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1001 impl ast::LoopBodyOwner for ForExpr {}
1003 pub fn pat(&self) -> Option<Pat> {
1004 super::child_opt(self)
1007 pub fn iterable(&self) -> Option<Expr> {
1008 super::child_opt(self)
1013 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1014 pub struct ForType {
1015 pub(crate) syntax: SyntaxNode,
1018 impl AstNode for ForType {
1019 fn can_cast(kind: SyntaxKind) -> bool {
1025 fn cast(syntax: SyntaxNode) -> Option<Self> {
1026 if Self::can_cast(syntax.kind()) { Some(ForType { syntax }) } else { None }
1028 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1033 pub fn type_ref(&self) -> Option<TypeRef> {
1034 super::child_opt(self)
1039 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1041 pub(crate) syntax: SyntaxNode,
1044 impl AstNode for IfExpr {
1045 fn can_cast(kind: SyntaxKind) -> bool {
1051 fn cast(syntax: SyntaxNode) -> Option<Self> {
1052 if Self::can_cast(syntax.kind()) { Some(IfExpr { syntax }) } else { None }
1054 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1059 pub fn condition(&self) -> Option<Condition> {
1060 super::child_opt(self)
1065 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1066 pub struct ImplBlock {
1067 pub(crate) syntax: SyntaxNode,
1070 impl AstNode for ImplBlock {
1071 fn can_cast(kind: SyntaxKind) -> bool {
1077 fn cast(syntax: SyntaxNode) -> Option<Self> {
1078 if Self::can_cast(syntax.kind()) { Some(ImplBlock { syntax }) } else { None }
1080 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1084 impl ast::TypeParamsOwner for ImplBlock {}
1085 impl ast::AttrsOwner for ImplBlock {}
1087 pub fn item_list(&self) -> Option<ItemList> {
1088 super::child_opt(self)
1093 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1094 pub struct ImplItem {
1095 pub(crate) syntax: SyntaxNode,
1098 impl AstNode for ImplItem {
1099 fn can_cast(kind: SyntaxKind) -> bool {
1101 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1105 fn cast(syntax: SyntaxNode) -> Option<Self> {
1106 if Self::can_cast(syntax.kind()) { Some(ImplItem { syntax }) } else { None }
1108 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1112 #[derive(Debug, Clone, PartialEq, Eq)]
1113 pub enum ImplItemKind {
1115 TypeAliasDef(TypeAliasDef),
1118 impl From<FnDef> for ImplItem {
1119 fn from(n: FnDef) -> ImplItem { ImplItem { syntax: n.syntax } }
1121 impl From<TypeAliasDef> for ImplItem {
1122 fn from(n: TypeAliasDef) -> ImplItem { ImplItem { syntax: n.syntax } }
1124 impl From<ConstDef> for ImplItem {
1125 fn from(n: ConstDef) -> ImplItem { ImplItem { syntax: n.syntax } }
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!(),
1141 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1142 pub struct ImplTraitType {
1143 pub(crate) syntax: SyntaxNode,
1146 impl AstNode for ImplTraitType {
1147 fn can_cast(kind: SyntaxKind) -> bool {
1149 IMPL_TRAIT_TYPE => true,
1153 fn cast(syntax: SyntaxNode) -> Option<Self> {
1154 if Self::can_cast(syntax.kind()) { Some(ImplTraitType { syntax }) } else { None }
1156 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1160 impl ast::TypeBoundsOwner for ImplTraitType {}
1161 impl ImplTraitType {}
1164 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1165 pub struct IndexExpr {
1166 pub(crate) syntax: SyntaxNode,
1169 impl AstNode for IndexExpr {
1170 fn can_cast(kind: SyntaxKind) -> bool {
1176 fn cast(syntax: SyntaxNode) -> Option<Self> {
1177 if Self::can_cast(syntax.kind()) { Some(IndexExpr { syntax }) } else { None }
1179 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1186 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1187 pub struct ItemList {
1188 pub(crate) syntax: SyntaxNode,
1191 impl AstNode for ItemList {
1192 fn can_cast(kind: SyntaxKind) -> bool {
1198 fn cast(syntax: SyntaxNode) -> Option<Self> {
1199 if Self::can_cast(syntax.kind()) { Some(ItemList { syntax }) } else { None }
1201 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1205 impl ast::FnDefOwner for ItemList {}
1206 impl ast::ModuleItemOwner for ItemList {}
1208 pub fn impl_items(&self) -> impl Iterator<Item = ImplItem> {
1209 super::children(self)
1214 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1216 pub(crate) syntax: SyntaxNode,
1219 impl AstNode for Label {
1220 fn can_cast(kind: SyntaxKind) -> bool {
1226 fn cast(syntax: SyntaxNode) -> Option<Self> {
1227 if Self::can_cast(syntax.kind()) { Some(Label { syntax }) } else { None }
1229 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1236 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1237 pub struct LambdaExpr {
1238 pub(crate) syntax: SyntaxNode,
1241 impl AstNode for LambdaExpr {
1242 fn can_cast(kind: SyntaxKind) -> bool {
1244 LAMBDA_EXPR => true,
1248 fn cast(syntax: SyntaxNode) -> Option<Self> {
1249 if Self::can_cast(syntax.kind()) { Some(LambdaExpr { syntax }) } else { None }
1251 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1256 pub fn param_list(&self) -> Option<ParamList> {
1257 super::child_opt(self)
1260 pub fn body(&self) -> Option<Expr> {
1261 super::child_opt(self)
1266 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1267 pub struct LetStmt {
1268 pub(crate) syntax: SyntaxNode,
1271 impl AstNode for LetStmt {
1272 fn can_cast(kind: SyntaxKind) -> bool {
1278 fn cast(syntax: SyntaxNode) -> Option<Self> {
1279 if Self::can_cast(syntax.kind()) { Some(LetStmt { syntax }) } else { None }
1281 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1285 impl ast::TypeAscriptionOwner for LetStmt {}
1287 pub fn pat(&self) -> Option<Pat> {
1288 super::child_opt(self)
1291 pub fn initializer(&self) -> Option<Expr> {
1292 super::child_opt(self)
1297 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1298 pub struct LifetimeArg {
1299 pub(crate) syntax: SyntaxNode,
1302 impl AstNode for LifetimeArg {
1303 fn can_cast(kind: SyntaxKind) -> bool {
1305 LIFETIME_ARG => true,
1309 fn cast(syntax: SyntaxNode) -> Option<Self> {
1310 if Self::can_cast(syntax.kind()) { Some(LifetimeArg { syntax }) } else { None }
1312 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1319 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1320 pub struct LifetimeParam {
1321 pub(crate) syntax: SyntaxNode,
1324 impl AstNode for LifetimeParam {
1325 fn can_cast(kind: SyntaxKind) -> bool {
1327 LIFETIME_PARAM => true,
1331 fn cast(syntax: SyntaxNode) -> Option<Self> {
1332 if Self::can_cast(syntax.kind()) { Some(LifetimeParam { syntax }) } else { None }
1334 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1338 impl ast::AttrsOwner for LifetimeParam {}
1339 impl LifetimeParam {}
1342 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1343 pub struct Literal {
1344 pub(crate) syntax: SyntaxNode,
1347 impl AstNode for Literal {
1348 fn can_cast(kind: SyntaxKind) -> bool {
1354 fn cast(syntax: SyntaxNode) -> Option<Self> {
1355 if Self::can_cast(syntax.kind()) { Some(Literal { syntax }) } else { None }
1357 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1364 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1365 pub struct LiteralPat {
1366 pub(crate) syntax: SyntaxNode,
1369 impl AstNode for LiteralPat {
1370 fn can_cast(kind: SyntaxKind) -> bool {
1372 LITERAL_PAT => true,
1376 fn cast(syntax: SyntaxNode) -> Option<Self> {
1377 if Self::can_cast(syntax.kind()) { Some(LiteralPat { syntax }) } else { None }
1379 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1384 pub fn literal(&self) -> Option<Literal> {
1385 super::child_opt(self)
1390 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1391 pub struct LoopExpr {
1392 pub(crate) syntax: SyntaxNode,
1395 impl AstNode for LoopExpr {
1396 fn can_cast(kind: SyntaxKind) -> bool {
1402 fn cast(syntax: SyntaxNode) -> Option<Self> {
1403 if Self::can_cast(syntax.kind()) { Some(LoopExpr { syntax }) } else { None }
1405 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1409 impl ast::LoopBodyOwner for LoopExpr {}
1413 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1414 pub struct MacroCall {
1415 pub(crate) syntax: SyntaxNode,
1418 impl AstNode for MacroCall {
1419 fn can_cast(kind: SyntaxKind) -> bool {
1425 fn cast(syntax: SyntaxNode) -> Option<Self> {
1426 if Self::can_cast(syntax.kind()) { Some(MacroCall { syntax }) } else { None }
1428 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1432 impl ast::NameOwner for MacroCall {}
1433 impl ast::AttrsOwner for MacroCall {}
1434 impl ast::DocCommentsOwner for MacroCall {}
1436 pub fn token_tree(&self) -> Option<TokenTree> {
1437 super::child_opt(self)
1440 pub fn path(&self) -> Option<Path> {
1441 super::child_opt(self)
1446 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1447 pub struct MacroItems {
1448 pub(crate) syntax: SyntaxNode,
1451 impl AstNode for MacroItems {
1452 fn can_cast(kind: SyntaxKind) -> bool {
1454 MACRO_ITEMS => true,
1458 fn cast(syntax: SyntaxNode) -> Option<Self> {
1459 if Self::can_cast(syntax.kind()) { Some(MacroItems { syntax }) } else { None }
1461 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1465 impl ast::ModuleItemOwner for MacroItems {}
1466 impl ast::FnDefOwner for MacroItems {}
1470 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1471 pub struct MacroStmts {
1472 pub(crate) syntax: SyntaxNode,
1475 impl AstNode for MacroStmts {
1476 fn can_cast(kind: SyntaxKind) -> bool {
1478 MACRO_STMTS => true,
1482 fn cast(syntax: SyntaxNode) -> Option<Self> {
1483 if Self::can_cast(syntax.kind()) { Some(MacroStmts { syntax }) } else { None }
1485 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1490 pub fn statements(&self) -> impl Iterator<Item = Stmt> {
1491 super::children(self)
1494 pub fn expr(&self) -> Option<Expr> {
1495 super::child_opt(self)
1500 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1501 pub struct MatchArm {
1502 pub(crate) syntax: SyntaxNode,
1505 impl AstNode for MatchArm {
1506 fn can_cast(kind: SyntaxKind) -> bool {
1512 fn cast(syntax: SyntaxNode) -> Option<Self> {
1513 if Self::can_cast(syntax.kind()) { Some(MatchArm { syntax }) } else { None }
1515 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1519 impl ast::AttrsOwner for MatchArm {}
1521 pub fn pats(&self) -> impl Iterator<Item = Pat> {
1522 super::children(self)
1525 pub fn guard(&self) -> Option<MatchGuard> {
1526 super::child_opt(self)
1529 pub fn expr(&self) -> Option<Expr> {
1530 super::child_opt(self)
1535 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1536 pub struct MatchArmList {
1537 pub(crate) syntax: SyntaxNode,
1540 impl AstNode for MatchArmList {
1541 fn can_cast(kind: SyntaxKind) -> bool {
1543 MATCH_ARM_LIST => true,
1547 fn cast(syntax: SyntaxNode) -> Option<Self> {
1548 if Self::can_cast(syntax.kind()) { Some(MatchArmList { syntax }) } else { None }
1550 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1554 impl ast::AttrsOwner for MatchArmList {}
1556 pub fn arms(&self) -> impl Iterator<Item = MatchArm> {
1557 super::children(self)
1562 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1563 pub struct MatchExpr {
1564 pub(crate) syntax: SyntaxNode,
1567 impl AstNode for MatchExpr {
1568 fn can_cast(kind: SyntaxKind) -> bool {
1574 fn cast(syntax: SyntaxNode) -> Option<Self> {
1575 if Self::can_cast(syntax.kind()) { Some(MatchExpr { syntax }) } else { None }
1577 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1582 pub fn expr(&self) -> Option<Expr> {
1583 super::child_opt(self)
1586 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1587 super::child_opt(self)
1592 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1593 pub struct MatchGuard {
1594 pub(crate) syntax: SyntaxNode,
1597 impl AstNode for MatchGuard {
1598 fn can_cast(kind: SyntaxKind) -> bool {
1600 MATCH_GUARD => true,
1604 fn cast(syntax: SyntaxNode) -> Option<Self> {
1605 if Self::can_cast(syntax.kind()) { Some(MatchGuard { syntax }) } else { None }
1607 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1612 pub fn expr(&self) -> Option<Expr> {
1613 super::child_opt(self)
1618 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1619 pub struct MethodCallExpr {
1620 pub(crate) syntax: SyntaxNode,
1623 impl AstNode for MethodCallExpr {
1624 fn can_cast(kind: SyntaxKind) -> bool {
1626 METHOD_CALL_EXPR => true,
1630 fn cast(syntax: SyntaxNode) -> Option<Self> {
1631 if Self::can_cast(syntax.kind()) { Some(MethodCallExpr { syntax }) } else { None }
1633 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1637 impl ast::ArgListOwner for MethodCallExpr {}
1638 impl MethodCallExpr {
1639 pub fn expr(&self) -> Option<Expr> {
1640 super::child_opt(self)
1643 pub fn name_ref(&self) -> Option<NameRef> {
1644 super::child_opt(self)
1647 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1648 super::child_opt(self)
1653 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1655 pub(crate) syntax: SyntaxNode,
1658 impl AstNode for Module {
1659 fn can_cast(kind: SyntaxKind) -> bool {
1665 fn cast(syntax: SyntaxNode) -> Option<Self> {
1666 if Self::can_cast(syntax.kind()) { Some(Module { syntax }) } else { None }
1668 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1672 impl ast::VisibilityOwner for Module {}
1673 impl ast::NameOwner for Module {}
1674 impl ast::AttrsOwner for Module {}
1675 impl ast::DocCommentsOwner for Module {}
1677 pub fn item_list(&self) -> Option<ItemList> {
1678 super::child_opt(self)
1683 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1684 pub struct ModuleItem {
1685 pub(crate) syntax: SyntaxNode,
1688 impl AstNode for ModuleItem {
1689 fn can_cast(kind: SyntaxKind) -> bool {
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,
1695 fn cast(syntax: SyntaxNode) -> Option<Self> {
1696 if Self::can_cast(syntax.kind()) { Some(ModuleItem { syntax }) } else { None }
1698 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1702 #[derive(Debug, Clone, PartialEq, Eq)]
1703 pub enum ModuleItemKind {
1704 StructDef(StructDef),
1708 TypeAliasDef(TypeAliasDef),
1709 ImplBlock(ImplBlock),
1711 ExternCrateItem(ExternCrateItem),
1713 StaticDef(StaticDef),
1716 impl From<StructDef> for ModuleItem {
1717 fn from(n: StructDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1719 impl From<EnumDef> for ModuleItem {
1720 fn from(n: EnumDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1722 impl From<FnDef> for ModuleItem {
1723 fn from(n: FnDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1725 impl From<TraitDef> for ModuleItem {
1726 fn from(n: TraitDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1728 impl From<TypeAliasDef> for ModuleItem {
1729 fn from(n: TypeAliasDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1731 impl From<ImplBlock> for ModuleItem {
1732 fn from(n: ImplBlock) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1734 impl From<UseItem> for ModuleItem {
1735 fn from(n: UseItem) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1737 impl From<ExternCrateItem> for ModuleItem {
1738 fn from(n: ExternCrateItem) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1740 impl From<ConstDef> for ModuleItem {
1741 fn from(n: ConstDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1743 impl From<StaticDef> for ModuleItem {
1744 fn from(n: StaticDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1746 impl From<Module> for ModuleItem {
1747 fn from(n: Module) -> ModuleItem { ModuleItem { syntax: n.syntax } }
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!(),
1771 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1773 pub(crate) syntax: SyntaxNode,
1776 impl AstNode for Name {
1777 fn can_cast(kind: SyntaxKind) -> bool {
1783 fn cast(syntax: SyntaxNode) -> Option<Self> {
1784 if Self::can_cast(syntax.kind()) { Some(Name { syntax }) } else { None }
1786 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1793 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1794 pub struct NameRef {
1795 pub(crate) syntax: SyntaxNode,
1798 impl AstNode for NameRef {
1799 fn can_cast(kind: SyntaxKind) -> bool {
1805 fn cast(syntax: SyntaxNode) -> Option<Self> {
1806 if Self::can_cast(syntax.kind()) { Some(NameRef { syntax }) } else { None }
1808 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1815 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1816 pub struct NamedField {
1817 pub(crate) syntax: SyntaxNode,
1820 impl AstNode for NamedField {
1821 fn can_cast(kind: SyntaxKind) -> bool {
1823 NAMED_FIELD => true,
1827 fn cast(syntax: SyntaxNode) -> Option<Self> {
1828 if Self::can_cast(syntax.kind()) { Some(NamedField { syntax }) } else { None }
1830 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1835 pub fn name_ref(&self) -> Option<NameRef> {
1836 super::child_opt(self)
1839 pub fn expr(&self) -> Option<Expr> {
1840 super::child_opt(self)
1845 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1846 pub struct NamedFieldDef {
1847 pub(crate) syntax: SyntaxNode,
1850 impl AstNode for NamedFieldDef {
1851 fn can_cast(kind: SyntaxKind) -> bool {
1853 NAMED_FIELD_DEF => true,
1857 fn cast(syntax: SyntaxNode) -> Option<Self> {
1858 if Self::can_cast(syntax.kind()) { Some(NamedFieldDef { syntax }) } else { None }
1860 fn syntax(&self) -> &SyntaxNode { &self.syntax }
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 {}
1871 // NamedFieldDefList
1872 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1873 pub struct NamedFieldDefList {
1874 pub(crate) syntax: SyntaxNode,
1877 impl AstNode for NamedFieldDefList {
1878 fn can_cast(kind: SyntaxKind) -> bool {
1880 NAMED_FIELD_DEF_LIST => true,
1884 fn cast(syntax: SyntaxNode) -> Option<Self> {
1885 if Self::can_cast(syntax.kind()) { Some(NamedFieldDefList { syntax }) } else { None }
1887 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1891 impl NamedFieldDefList {
1892 pub fn fields(&self) -> impl Iterator<Item = NamedFieldDef> {
1893 super::children(self)
1898 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1899 pub struct NamedFieldList {
1900 pub(crate) syntax: SyntaxNode,
1903 impl AstNode for NamedFieldList {
1904 fn can_cast(kind: SyntaxKind) -> bool {
1906 NAMED_FIELD_LIST => true,
1910 fn cast(syntax: SyntaxNode) -> Option<Self> {
1911 if Self::can_cast(syntax.kind()) { Some(NamedFieldList { syntax }) } else { None }
1913 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1917 impl NamedFieldList {
1918 pub fn fields(&self) -> impl Iterator<Item = NamedField> {
1919 super::children(self)
1922 pub fn spread(&self) -> Option<Expr> {
1923 super::child_opt(self)
1928 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1929 pub struct NeverType {
1930 pub(crate) syntax: SyntaxNode,
1933 impl AstNode for NeverType {
1934 fn can_cast(kind: SyntaxKind) -> bool {
1940 fn cast(syntax: SyntaxNode) -> Option<Self> {
1941 if Self::can_cast(syntax.kind()) { Some(NeverType { syntax }) } else { None }
1943 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1950 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1951 pub struct NominalDef {
1952 pub(crate) syntax: SyntaxNode,
1955 impl AstNode for NominalDef {
1956 fn can_cast(kind: SyntaxKind) -> bool {
1958 | STRUCT_DEF | ENUM_DEF => true,
1962 fn cast(syntax: SyntaxNode) -> Option<Self> {
1963 if Self::can_cast(syntax.kind()) { Some(NominalDef { syntax }) } else { None }
1965 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1969 #[derive(Debug, Clone, PartialEq, Eq)]
1970 pub enum NominalDefKind {
1971 StructDef(StructDef),
1974 impl From<StructDef> for NominalDef {
1975 fn from(n: StructDef) -> NominalDef { NominalDef { syntax: n.syntax } }
1977 impl From<EnumDef> for NominalDef {
1978 fn from(n: EnumDef) -> NominalDef { NominalDef { syntax: n.syntax } }
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!(),
1990 impl ast::NameOwner for NominalDef {}
1991 impl ast::TypeParamsOwner for NominalDef {}
1992 impl ast::AttrsOwner for NominalDef {}
1996 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1998 pub(crate) syntax: SyntaxNode,
2001 impl AstNode for Param {
2002 fn can_cast(kind: SyntaxKind) -> bool {
2008 fn cast(syntax: SyntaxNode) -> Option<Self> {
2009 if Self::can_cast(syntax.kind()) { Some(Param { syntax }) } else { None }
2011 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2015 impl ast::TypeAscriptionOwner for Param {}
2016 impl ast::AttrsOwner for Param {}
2018 pub fn pat(&self) -> Option<Pat> {
2019 super::child_opt(self)
2024 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2025 pub struct ParamList {
2026 pub(crate) syntax: SyntaxNode,
2029 impl AstNode for ParamList {
2030 fn can_cast(kind: SyntaxKind) -> bool {
2036 fn cast(syntax: SyntaxNode) -> Option<Self> {
2037 if Self::can_cast(syntax.kind()) { Some(ParamList { syntax }) } else { None }
2039 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2044 pub fn params(&self) -> impl Iterator<Item = Param> {
2045 super::children(self)
2048 pub fn self_param(&self) -> Option<SelfParam> {
2049 super::child_opt(self)
2054 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2055 pub struct ParenExpr {
2056 pub(crate) syntax: SyntaxNode,
2059 impl AstNode for ParenExpr {
2060 fn can_cast(kind: SyntaxKind) -> bool {
2066 fn cast(syntax: SyntaxNode) -> Option<Self> {
2067 if Self::can_cast(syntax.kind()) { Some(ParenExpr { syntax }) } else { None }
2069 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2074 pub fn expr(&self) -> Option<Expr> {
2075 super::child_opt(self)
2080 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2081 pub struct ParenType {
2082 pub(crate) syntax: SyntaxNode,
2085 impl AstNode for ParenType {
2086 fn can_cast(kind: SyntaxKind) -> bool {
2092 fn cast(syntax: SyntaxNode) -> Option<Self> {
2093 if Self::can_cast(syntax.kind()) { Some(ParenType { syntax }) } else { None }
2095 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2100 pub fn type_ref(&self) -> Option<TypeRef> {
2101 super::child_opt(self)
2106 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2108 pub(crate) syntax: SyntaxNode,
2111 impl AstNode for Pat {
2112 fn can_cast(kind: SyntaxKind) -> bool {
2114 | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2118 fn cast(syntax: SyntaxNode) -> Option<Self> {
2119 if Self::can_cast(syntax.kind()) { Some(Pat { syntax }) } else { None }
2121 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2125 #[derive(Debug, Clone, PartialEq, Eq)]
2129 PlaceholderPat(PlaceholderPat),
2131 StructPat(StructPat),
2132 TupleStructPat(TupleStructPat),
2136 LiteralPat(LiteralPat),
2138 impl From<RefPat> for Pat {
2139 fn from(n: RefPat) -> Pat { Pat { syntax: n.syntax } }
2141 impl From<BindPat> for Pat {
2142 fn from(n: BindPat) -> Pat { Pat { syntax: n.syntax } }
2144 impl From<PlaceholderPat> for Pat {
2145 fn from(n: PlaceholderPat) -> Pat { Pat { syntax: n.syntax } }
2147 impl From<PathPat> for Pat {
2148 fn from(n: PathPat) -> Pat { Pat { syntax: n.syntax } }
2150 impl From<StructPat> for Pat {
2151 fn from(n: StructPat) -> Pat { Pat { syntax: n.syntax } }
2153 impl From<TupleStructPat> for Pat {
2154 fn from(n: TupleStructPat) -> Pat { Pat { syntax: n.syntax } }
2156 impl From<TuplePat> for Pat {
2157 fn from(n: TuplePat) -> Pat { Pat { syntax: n.syntax } }
2159 impl From<SlicePat> for Pat {
2160 fn from(n: SlicePat) -> Pat { Pat { syntax: n.syntax } }
2162 impl From<RangePat> for Pat {
2163 fn from(n: RangePat) -> Pat { Pat { syntax: n.syntax } }
2165 impl From<LiteralPat> for Pat {
2166 fn from(n: LiteralPat) -> Pat { Pat { syntax: n.syntax } }
2169 pub fn kind(&self) -> PatKind {
2170 match self.syntax.kind() {
2171 REF_PAT => PatKind::RefPat(RefPat::cast(self.syntax.clone()).unwrap()),
2172 BIND_PAT => PatKind::BindPat(BindPat::cast(self.syntax.clone()).unwrap()),
2173 PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(self.syntax.clone()).unwrap()),
2174 PATH_PAT => PatKind::PathPat(PathPat::cast(self.syntax.clone()).unwrap()),
2175 STRUCT_PAT => PatKind::StructPat(StructPat::cast(self.syntax.clone()).unwrap()),
2176 TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(self.syntax.clone()).unwrap()),
2177 TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(self.syntax.clone()).unwrap()),
2178 SLICE_PAT => PatKind::SlicePat(SlicePat::cast(self.syntax.clone()).unwrap()),
2179 RANGE_PAT => PatKind::RangePat(RangePat::cast(self.syntax.clone()).unwrap()),
2180 LITERAL_PAT => PatKind::LiteralPat(LiteralPat::cast(self.syntax.clone()).unwrap()),
2181 _ => unreachable!(),
2189 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2191 pub(crate) syntax: SyntaxNode,
2194 impl AstNode for Path {
2195 fn can_cast(kind: SyntaxKind) -> bool {
2201 fn cast(syntax: SyntaxNode) -> Option<Self> {
2202 if Self::can_cast(syntax.kind()) { Some(Path { syntax }) } else { None }
2204 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2209 pub fn segment(&self) -> Option<PathSegment> {
2210 super::child_opt(self)
2213 pub fn qualifier(&self) -> Option<Path> {
2214 super::child_opt(self)
2219 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2220 pub struct PathExpr {
2221 pub(crate) syntax: SyntaxNode,
2224 impl AstNode for PathExpr {
2225 fn can_cast(kind: SyntaxKind) -> bool {
2231 fn cast(syntax: SyntaxNode) -> Option<Self> {
2232 if Self::can_cast(syntax.kind()) { Some(PathExpr { syntax }) } else { None }
2234 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2239 pub fn path(&self) -> Option<Path> {
2240 super::child_opt(self)
2245 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2246 pub struct PathPat {
2247 pub(crate) syntax: SyntaxNode,
2250 impl AstNode for PathPat {
2251 fn can_cast(kind: SyntaxKind) -> bool {
2257 fn cast(syntax: SyntaxNode) -> Option<Self> {
2258 if Self::can_cast(syntax.kind()) { Some(PathPat { syntax }) } else { None }
2260 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2265 pub fn path(&self) -> Option<Path> {
2266 super::child_opt(self)
2271 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2272 pub struct PathSegment {
2273 pub(crate) syntax: SyntaxNode,
2276 impl AstNode for PathSegment {
2277 fn can_cast(kind: SyntaxKind) -> bool {
2279 PATH_SEGMENT => true,
2283 fn cast(syntax: SyntaxNode) -> Option<Self> {
2284 if Self::can_cast(syntax.kind()) { Some(PathSegment { syntax }) } else { None }
2286 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2291 pub fn name_ref(&self) -> Option<NameRef> {
2292 super::child_opt(self)
2295 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2296 super::child_opt(self)
2301 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2302 pub struct PathType {
2303 pub(crate) syntax: SyntaxNode,
2306 impl AstNode for PathType {
2307 fn can_cast(kind: SyntaxKind) -> bool {
2313 fn cast(syntax: SyntaxNode) -> Option<Self> {
2314 if Self::can_cast(syntax.kind()) { Some(PathType { syntax }) } else { None }
2316 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2321 pub fn path(&self) -> Option<Path> {
2322 super::child_opt(self)
2327 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2328 pub struct PlaceholderPat {
2329 pub(crate) syntax: SyntaxNode,
2332 impl AstNode for PlaceholderPat {
2333 fn can_cast(kind: SyntaxKind) -> bool {
2335 PLACEHOLDER_PAT => true,
2339 fn cast(syntax: SyntaxNode) -> Option<Self> {
2340 if Self::can_cast(syntax.kind()) { Some(PlaceholderPat { syntax }) } else { None }
2342 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2346 impl PlaceholderPat {}
2349 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2350 pub struct PlaceholderType {
2351 pub(crate) syntax: SyntaxNode,
2354 impl AstNode for PlaceholderType {
2355 fn can_cast(kind: SyntaxKind) -> bool {
2357 PLACEHOLDER_TYPE => true,
2361 fn cast(syntax: SyntaxNode) -> Option<Self> {
2362 if Self::can_cast(syntax.kind()) { Some(PlaceholderType { syntax }) } else { None }
2364 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2368 impl PlaceholderType {}
2371 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2372 pub struct PointerType {
2373 pub(crate) syntax: SyntaxNode,
2376 impl AstNode for PointerType {
2377 fn can_cast(kind: SyntaxKind) -> bool {
2379 POINTER_TYPE => true,
2383 fn cast(syntax: SyntaxNode) -> Option<Self> {
2384 if Self::can_cast(syntax.kind()) { Some(PointerType { syntax }) } else { None }
2386 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2391 pub fn type_ref(&self) -> Option<TypeRef> {
2392 super::child_opt(self)
2397 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2398 pub struct PosFieldDef {
2399 pub(crate) syntax: SyntaxNode,
2402 impl AstNode for PosFieldDef {
2403 fn can_cast(kind: SyntaxKind) -> bool {
2405 POS_FIELD_DEF => true,
2409 fn cast(syntax: SyntaxNode) -> Option<Self> {
2410 if Self::can_cast(syntax.kind()) { Some(PosFieldDef { syntax }) } else { None }
2412 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2416 impl ast::VisibilityOwner for PosFieldDef {}
2417 impl ast::AttrsOwner for PosFieldDef {}
2419 pub fn type_ref(&self) -> Option<TypeRef> {
2420 super::child_opt(self)
2425 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2426 pub struct PosFieldDefList {
2427 pub(crate) syntax: SyntaxNode,
2430 impl AstNode for PosFieldDefList {
2431 fn can_cast(kind: SyntaxKind) -> bool {
2433 POS_FIELD_DEF_LIST => true,
2437 fn cast(syntax: SyntaxNode) -> Option<Self> {
2438 if Self::can_cast(syntax.kind()) { Some(PosFieldDefList { syntax }) } else { None }
2440 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2444 impl PosFieldDefList {
2445 pub fn fields(&self) -> impl Iterator<Item = PosFieldDef> {
2446 super::children(self)
2451 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2452 pub struct PrefixExpr {
2453 pub(crate) syntax: SyntaxNode,
2456 impl AstNode for PrefixExpr {
2457 fn can_cast(kind: SyntaxKind) -> bool {
2459 PREFIX_EXPR => true,
2463 fn cast(syntax: SyntaxNode) -> Option<Self> {
2464 if Self::can_cast(syntax.kind()) { Some(PrefixExpr { syntax }) } else { None }
2466 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2471 pub fn expr(&self) -> Option<Expr> {
2472 super::child_opt(self)
2477 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2478 pub struct RangeExpr {
2479 pub(crate) syntax: SyntaxNode,
2482 impl AstNode for RangeExpr {
2483 fn can_cast(kind: SyntaxKind) -> bool {
2489 fn cast(syntax: SyntaxNode) -> Option<Self> {
2490 if Self::can_cast(syntax.kind()) { Some(RangeExpr { syntax }) } else { None }
2492 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2499 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2500 pub struct RangePat {
2501 pub(crate) syntax: SyntaxNode,
2504 impl AstNode for RangePat {
2505 fn can_cast(kind: SyntaxKind) -> bool {
2511 fn cast(syntax: SyntaxNode) -> Option<Self> {
2512 if Self::can_cast(syntax.kind()) { Some(RangePat { syntax }) } else { None }
2514 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2521 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2522 pub struct RefExpr {
2523 pub(crate) syntax: SyntaxNode,
2526 impl AstNode for RefExpr {
2527 fn can_cast(kind: SyntaxKind) -> bool {
2533 fn cast(syntax: SyntaxNode) -> Option<Self> {
2534 if Self::can_cast(syntax.kind()) { Some(RefExpr { syntax }) } else { None }
2536 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2541 pub fn expr(&self) -> Option<Expr> {
2542 super::child_opt(self)
2547 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2549 pub(crate) syntax: SyntaxNode,
2552 impl AstNode for RefPat {
2553 fn can_cast(kind: SyntaxKind) -> bool {
2559 fn cast(syntax: SyntaxNode) -> Option<Self> {
2560 if Self::can_cast(syntax.kind()) { Some(RefPat { syntax }) } else { None }
2562 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2567 pub fn pat(&self) -> Option<Pat> {
2568 super::child_opt(self)
2573 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2574 pub struct ReferenceType {
2575 pub(crate) syntax: SyntaxNode,
2578 impl AstNode for ReferenceType {
2579 fn can_cast(kind: SyntaxKind) -> bool {
2581 REFERENCE_TYPE => true,
2585 fn cast(syntax: SyntaxNode) -> Option<Self> {
2586 if Self::can_cast(syntax.kind()) { Some(ReferenceType { syntax }) } else { None }
2588 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2592 impl ReferenceType {
2593 pub fn type_ref(&self) -> Option<TypeRef> {
2594 super::child_opt(self)
2599 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2600 pub struct RetType {
2601 pub(crate) syntax: SyntaxNode,
2604 impl AstNode for RetType {
2605 fn can_cast(kind: SyntaxKind) -> bool {
2611 fn cast(syntax: SyntaxNode) -> Option<Self> {
2612 if Self::can_cast(syntax.kind()) { Some(RetType { syntax }) } else { None }
2614 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2619 pub fn type_ref(&self) -> Option<TypeRef> {
2620 super::child_opt(self)
2625 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2626 pub struct ReturnExpr {
2627 pub(crate) syntax: SyntaxNode,
2630 impl AstNode for ReturnExpr {
2631 fn can_cast(kind: SyntaxKind) -> bool {
2633 RETURN_EXPR => true,
2637 fn cast(syntax: SyntaxNode) -> Option<Self> {
2638 if Self::can_cast(syntax.kind()) { Some(ReturnExpr { syntax }) } else { None }
2640 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2645 pub fn expr(&self) -> Option<Expr> {
2646 super::child_opt(self)
2651 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2652 pub struct SelfParam {
2653 pub(crate) syntax: SyntaxNode,
2656 impl AstNode for SelfParam {
2657 fn can_cast(kind: SyntaxKind) -> bool {
2663 fn cast(syntax: SyntaxNode) -> Option<Self> {
2664 if Self::can_cast(syntax.kind()) { Some(SelfParam { syntax }) } else { None }
2666 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2670 impl ast::TypeAscriptionOwner for SelfParam {}
2671 impl ast::AttrsOwner for SelfParam {}
2675 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2676 pub struct SlicePat {
2677 pub(crate) syntax: SyntaxNode,
2680 impl AstNode for SlicePat {
2681 fn can_cast(kind: SyntaxKind) -> bool {
2687 fn cast(syntax: SyntaxNode) -> Option<Self> {
2688 if Self::can_cast(syntax.kind()) { Some(SlicePat { syntax }) } else { None }
2690 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2697 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2698 pub struct SliceType {
2699 pub(crate) syntax: SyntaxNode,
2702 impl AstNode for SliceType {
2703 fn can_cast(kind: SyntaxKind) -> bool {
2709 fn cast(syntax: SyntaxNode) -> Option<Self> {
2710 if Self::can_cast(syntax.kind()) { Some(SliceType { syntax }) } else { None }
2712 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2717 pub fn type_ref(&self) -> Option<TypeRef> {
2718 super::child_opt(self)
2723 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2724 pub struct SourceFile {
2725 pub(crate) syntax: SyntaxNode,
2728 impl AstNode for SourceFile {
2729 fn can_cast(kind: SyntaxKind) -> bool {
2731 SOURCE_FILE => true,
2735 fn cast(syntax: SyntaxNode) -> Option<Self> {
2736 if Self::can_cast(syntax.kind()) { Some(SourceFile { syntax }) } else { None }
2738 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2742 impl ast::ModuleItemOwner for SourceFile {}
2743 impl ast::FnDefOwner for SourceFile {}
2745 pub fn modules(&self) -> impl Iterator<Item = Module> {
2746 super::children(self)
2751 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2752 pub struct StaticDef {
2753 pub(crate) syntax: SyntaxNode,
2756 impl AstNode for StaticDef {
2757 fn can_cast(kind: SyntaxKind) -> bool {
2763 fn cast(syntax: SyntaxNode) -> Option<Self> {
2764 if Self::can_cast(syntax.kind()) { Some(StaticDef { syntax }) } else { None }
2766 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2770 impl ast::VisibilityOwner for StaticDef {}
2771 impl ast::NameOwner for StaticDef {}
2772 impl ast::TypeParamsOwner for StaticDef {}
2773 impl ast::AttrsOwner for StaticDef {}
2774 impl ast::DocCommentsOwner for StaticDef {}
2775 impl ast::TypeAscriptionOwner for StaticDef {}
2777 pub fn body(&self) -> Option<Expr> {
2778 super::child_opt(self)
2783 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2785 pub(crate) syntax: SyntaxNode,
2788 impl AstNode for Stmt {
2789 fn can_cast(kind: SyntaxKind) -> bool {
2791 | EXPR_STMT | LET_STMT => true,
2795 fn cast(syntax: SyntaxNode) -> Option<Self> {
2796 if Self::can_cast(syntax.kind()) { Some(Stmt { syntax }) } else { None }
2798 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2802 #[derive(Debug, Clone, PartialEq, Eq)]
2807 impl From<ExprStmt> for Stmt {
2808 fn from(n: ExprStmt) -> Stmt { Stmt { syntax: n.syntax } }
2810 impl From<LetStmt> for Stmt {
2811 fn from(n: LetStmt) -> Stmt { Stmt { syntax: n.syntax } }
2814 pub fn kind(&self) -> StmtKind {
2815 match self.syntax.kind() {
2816 EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(self.syntax.clone()).unwrap()),
2817 LET_STMT => StmtKind::LetStmt(LetStmt::cast(self.syntax.clone()).unwrap()),
2818 _ => unreachable!(),
2826 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2827 pub struct StructDef {
2828 pub(crate) syntax: SyntaxNode,
2831 impl AstNode for StructDef {
2832 fn can_cast(kind: SyntaxKind) -> bool {
2838 fn cast(syntax: SyntaxNode) -> Option<Self> {
2839 if Self::can_cast(syntax.kind()) { Some(StructDef { syntax }) } else { None }
2841 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2845 impl ast::VisibilityOwner for StructDef {}
2846 impl ast::NameOwner for StructDef {}
2847 impl ast::TypeParamsOwner for StructDef {}
2848 impl ast::AttrsOwner for StructDef {}
2849 impl ast::DocCommentsOwner for StructDef {}
2853 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2854 pub struct StructLit {
2855 pub(crate) syntax: SyntaxNode,
2858 impl AstNode for StructLit {
2859 fn can_cast(kind: SyntaxKind) -> bool {
2865 fn cast(syntax: SyntaxNode) -> Option<Self> {
2866 if Self::can_cast(syntax.kind()) { Some(StructLit { syntax }) } else { None }
2868 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2873 pub fn path(&self) -> Option<Path> {
2874 super::child_opt(self)
2877 pub fn named_field_list(&self) -> Option<NamedFieldList> {
2878 super::child_opt(self)
2883 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2884 pub struct StructPat {
2885 pub(crate) syntax: SyntaxNode,
2888 impl AstNode for StructPat {
2889 fn can_cast(kind: SyntaxKind) -> bool {
2895 fn cast(syntax: SyntaxNode) -> Option<Self> {
2896 if Self::can_cast(syntax.kind()) { Some(StructPat { syntax }) } else { None }
2898 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2903 pub fn field_pat_list(&self) -> Option<FieldPatList> {
2904 super::child_opt(self)
2907 pub fn path(&self) -> Option<Path> {
2908 super::child_opt(self)
2913 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2914 pub struct TokenTree {
2915 pub(crate) syntax: SyntaxNode,
2918 impl AstNode for TokenTree {
2919 fn can_cast(kind: SyntaxKind) -> bool {
2925 fn cast(syntax: SyntaxNode) -> Option<Self> {
2926 if Self::can_cast(syntax.kind()) { Some(TokenTree { syntax }) } else { None }
2928 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2935 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2936 pub struct TraitDef {
2937 pub(crate) syntax: SyntaxNode,
2940 impl AstNode for TraitDef {
2941 fn can_cast(kind: SyntaxKind) -> bool {
2947 fn cast(syntax: SyntaxNode) -> Option<Self> {
2948 if Self::can_cast(syntax.kind()) { Some(TraitDef { syntax }) } else { None }
2950 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2954 impl ast::VisibilityOwner for TraitDef {}
2955 impl ast::NameOwner for TraitDef {}
2956 impl ast::AttrsOwner for TraitDef {}
2957 impl ast::DocCommentsOwner for TraitDef {}
2958 impl ast::TypeParamsOwner for TraitDef {}
2959 impl ast::TypeBoundsOwner for TraitDef {}
2961 pub fn item_list(&self) -> Option<ItemList> {
2962 super::child_opt(self)
2967 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2968 pub struct TryBlockExpr {
2969 pub(crate) syntax: SyntaxNode,
2972 impl AstNode for TryBlockExpr {
2973 fn can_cast(kind: SyntaxKind) -> bool {
2975 TRY_BLOCK_EXPR => true,
2979 fn cast(syntax: SyntaxNode) -> Option<Self> {
2980 if Self::can_cast(syntax.kind()) { Some(TryBlockExpr { syntax }) } else { None }
2982 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2986 impl ast::TryBlockBodyOwner for TryBlockExpr {}
2987 impl TryBlockExpr {}
2990 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2991 pub struct TryExpr {
2992 pub(crate) syntax: SyntaxNode,
2995 impl AstNode for TryExpr {
2996 fn can_cast(kind: SyntaxKind) -> bool {
3002 fn cast(syntax: SyntaxNode) -> Option<Self> {
3003 if Self::can_cast(syntax.kind()) { Some(TryExpr { syntax }) } else { None }
3005 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3010 pub fn expr(&self) -> Option<Expr> {
3011 super::child_opt(self)
3016 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3017 pub struct TupleExpr {
3018 pub(crate) syntax: SyntaxNode,
3021 impl AstNode for TupleExpr {
3022 fn can_cast(kind: SyntaxKind) -> bool {
3028 fn cast(syntax: SyntaxNode) -> Option<Self> {
3029 if Self::can_cast(syntax.kind()) { Some(TupleExpr { syntax }) } else { None }
3031 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3036 pub fn exprs(&self) -> impl Iterator<Item = Expr> {
3037 super::children(self)
3042 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3043 pub struct TuplePat {
3044 pub(crate) syntax: SyntaxNode,
3047 impl AstNode for TuplePat {
3048 fn can_cast(kind: SyntaxKind) -> bool {
3054 fn cast(syntax: SyntaxNode) -> Option<Self> {
3055 if Self::can_cast(syntax.kind()) { Some(TuplePat { syntax }) } else { None }
3057 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3062 pub fn args(&self) -> impl Iterator<Item = Pat> {
3063 super::children(self)
3068 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3069 pub struct TupleStructPat {
3070 pub(crate) syntax: SyntaxNode,
3073 impl AstNode for TupleStructPat {
3074 fn can_cast(kind: SyntaxKind) -> bool {
3076 TUPLE_STRUCT_PAT => true,
3080 fn cast(syntax: SyntaxNode) -> Option<Self> {
3081 if Self::can_cast(syntax.kind()) { Some(TupleStructPat { syntax }) } else { None }
3083 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3087 impl TupleStructPat {
3088 pub fn args(&self) -> impl Iterator<Item = Pat> {
3089 super::children(self)
3092 pub fn path(&self) -> Option<Path> {
3093 super::child_opt(self)
3098 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3099 pub struct TupleType {
3100 pub(crate) syntax: SyntaxNode,
3103 impl AstNode for TupleType {
3104 fn can_cast(kind: SyntaxKind) -> bool {
3110 fn cast(syntax: SyntaxNode) -> Option<Self> {
3111 if Self::can_cast(syntax.kind()) { Some(TupleType { syntax }) } else { None }
3113 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3118 pub fn fields(&self) -> impl Iterator<Item = TypeRef> {
3119 super::children(self)
3124 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3125 pub struct TypeAliasDef {
3126 pub(crate) syntax: SyntaxNode,
3129 impl AstNode for TypeAliasDef {
3130 fn can_cast(kind: SyntaxKind) -> bool {
3132 TYPE_ALIAS_DEF => true,
3136 fn cast(syntax: SyntaxNode) -> Option<Self> {
3137 if Self::can_cast(syntax.kind()) { Some(TypeAliasDef { syntax }) } else { None }
3139 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3143 impl ast::VisibilityOwner for TypeAliasDef {}
3144 impl ast::NameOwner for TypeAliasDef {}
3145 impl ast::TypeParamsOwner for TypeAliasDef {}
3146 impl ast::AttrsOwner for TypeAliasDef {}
3147 impl ast::DocCommentsOwner for TypeAliasDef {}
3148 impl ast::TypeBoundsOwner for TypeAliasDef {}
3150 pub fn type_ref(&self) -> Option<TypeRef> {
3151 super::child_opt(self)
3156 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3157 pub struct TypeArg {
3158 pub(crate) syntax: SyntaxNode,
3161 impl AstNode for TypeArg {
3162 fn can_cast(kind: SyntaxKind) -> bool {
3168 fn cast(syntax: SyntaxNode) -> Option<Self> {
3169 if Self::can_cast(syntax.kind()) { Some(TypeArg { syntax }) } else { None }
3171 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3176 pub fn type_ref(&self) -> Option<TypeRef> {
3177 super::child_opt(self)
3182 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3183 pub struct TypeArgList {
3184 pub(crate) syntax: SyntaxNode,
3187 impl AstNode for TypeArgList {
3188 fn can_cast(kind: SyntaxKind) -> bool {
3190 TYPE_ARG_LIST => true,
3194 fn cast(syntax: SyntaxNode) -> Option<Self> {
3195 if Self::can_cast(syntax.kind()) { Some(TypeArgList { syntax }) } else { None }
3197 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3202 pub fn type_args(&self) -> impl Iterator<Item = TypeArg> {
3203 super::children(self)
3206 pub fn lifetime_args(&self) -> impl Iterator<Item = LifetimeArg> {
3207 super::children(self)
3210 pub fn assoc_type_args(&self) -> impl Iterator<Item = AssocTypeArg> {
3211 super::children(self)
3216 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3217 pub struct TypeBound {
3218 pub(crate) syntax: SyntaxNode,
3221 impl AstNode for TypeBound {
3222 fn can_cast(kind: SyntaxKind) -> bool {
3228 fn cast(syntax: SyntaxNode) -> Option<Self> {
3229 if Self::can_cast(syntax.kind()) { Some(TypeBound { syntax }) } else { None }
3231 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3236 pub fn type_ref(&self) -> Option<TypeRef> {
3237 super::child_opt(self)
3242 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3243 pub struct TypeBoundList {
3244 pub(crate) syntax: SyntaxNode,
3247 impl AstNode for TypeBoundList {
3248 fn can_cast(kind: SyntaxKind) -> bool {
3250 TYPE_BOUND_LIST => true,
3254 fn cast(syntax: SyntaxNode) -> Option<Self> {
3255 if Self::can_cast(syntax.kind()) { Some(TypeBoundList { syntax }) } else { None }
3257 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3261 impl TypeBoundList {
3262 pub fn bounds(&self) -> impl Iterator<Item = TypeBound> {
3263 super::children(self)
3268 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3269 pub struct TypeParam {
3270 pub(crate) syntax: SyntaxNode,
3273 impl AstNode for TypeParam {
3274 fn can_cast(kind: SyntaxKind) -> bool {
3280 fn cast(syntax: SyntaxNode) -> Option<Self> {
3281 if Self::can_cast(syntax.kind()) { Some(TypeParam { syntax }) } else { None }
3283 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3287 impl ast::NameOwner for TypeParam {}
3288 impl ast::AttrsOwner for TypeParam {}
3289 impl ast::TypeBoundsOwner for TypeParam {}
3290 impl ast::DefaultTypeParamOwner for TypeParam {}
3294 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3295 pub struct TypeParamList {
3296 pub(crate) syntax: SyntaxNode,
3299 impl AstNode for TypeParamList {
3300 fn can_cast(kind: SyntaxKind) -> bool {
3302 TYPE_PARAM_LIST => true,
3306 fn cast(syntax: SyntaxNode) -> Option<Self> {
3307 if Self::can_cast(syntax.kind()) { Some(TypeParamList { syntax }) } else { None }
3309 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3313 impl TypeParamList {
3314 pub fn type_params(&self) -> impl Iterator<Item = TypeParam> {
3315 super::children(self)
3318 pub fn lifetime_params(&self) -> impl Iterator<Item = LifetimeParam> {
3319 super::children(self)
3324 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3325 pub struct TypeRef {
3326 pub(crate) syntax: SyntaxNode,
3329 impl AstNode for TypeRef {
3330 fn can_cast(kind: SyntaxKind) -> bool {
3332 | PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3336 fn cast(syntax: SyntaxNode) -> Option<Self> {
3337 if Self::can_cast(syntax.kind()) { Some(TypeRef { syntax }) } else { None }
3339 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3343 #[derive(Debug, Clone, PartialEq, Eq)]
3344 pub enum TypeRefKind {
3345 ParenType(ParenType),
3346 TupleType(TupleType),
3347 NeverType(NeverType),
3349 PointerType(PointerType),
3350 ArrayType(ArrayType),
3351 SliceType(SliceType),
3352 ReferenceType(ReferenceType),
3353 PlaceholderType(PlaceholderType),
3354 FnPointerType(FnPointerType),
3356 ImplTraitType(ImplTraitType),
3357 DynTraitType(DynTraitType),
3359 impl From<ParenType> for TypeRef {
3360 fn from(n: ParenType) -> TypeRef { TypeRef { syntax: n.syntax } }
3362 impl From<TupleType> for TypeRef {
3363 fn from(n: TupleType) -> TypeRef { TypeRef { syntax: n.syntax } }
3365 impl From<NeverType> for TypeRef {
3366 fn from(n: NeverType) -> TypeRef { TypeRef { syntax: n.syntax } }
3368 impl From<PathType> for TypeRef {
3369 fn from(n: PathType) -> TypeRef { TypeRef { syntax: n.syntax } }
3371 impl From<PointerType> for TypeRef {
3372 fn from(n: PointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3374 impl From<ArrayType> for TypeRef {
3375 fn from(n: ArrayType) -> TypeRef { TypeRef { syntax: n.syntax } }
3377 impl From<SliceType> for TypeRef {
3378 fn from(n: SliceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3380 impl From<ReferenceType> for TypeRef {
3381 fn from(n: ReferenceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3383 impl From<PlaceholderType> for TypeRef {
3384 fn from(n: PlaceholderType) -> TypeRef { TypeRef { syntax: n.syntax } }
3386 impl From<FnPointerType> for TypeRef {
3387 fn from(n: FnPointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3389 impl From<ForType> for TypeRef {
3390 fn from(n: ForType) -> TypeRef { TypeRef { syntax: n.syntax } }
3392 impl From<ImplTraitType> for TypeRef {
3393 fn from(n: ImplTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3395 impl From<DynTraitType> for TypeRef {
3396 fn from(n: DynTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3399 pub fn kind(&self) -> TypeRefKind {
3400 match self.syntax.kind() {
3401 PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(self.syntax.clone()).unwrap()),
3402 TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(self.syntax.clone()).unwrap()),
3403 NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(self.syntax.clone()).unwrap()),
3404 PATH_TYPE => TypeRefKind::PathType(PathType::cast(self.syntax.clone()).unwrap()),
3405 POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(self.syntax.clone()).unwrap()),
3406 ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(self.syntax.clone()).unwrap()),
3407 SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(self.syntax.clone()).unwrap()),
3408 REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(self.syntax.clone()).unwrap()),
3409 PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(self.syntax.clone()).unwrap()),
3410 FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(self.syntax.clone()).unwrap()),
3411 FOR_TYPE => TypeRefKind::ForType(ForType::cast(self.syntax.clone()).unwrap()),
3412 IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(self.syntax.clone()).unwrap()),
3413 DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(self.syntax.clone()).unwrap()),
3414 _ => unreachable!(),
3422 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3423 pub struct UseItem {
3424 pub(crate) syntax: SyntaxNode,
3427 impl AstNode for UseItem {
3428 fn can_cast(kind: SyntaxKind) -> bool {
3434 fn cast(syntax: SyntaxNode) -> Option<Self> {
3435 if Self::can_cast(syntax.kind()) { Some(UseItem { syntax }) } else { None }
3437 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3441 impl ast::AttrsOwner for UseItem {}
3443 pub fn use_tree(&self) -> Option<UseTree> {
3444 super::child_opt(self)
3449 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3450 pub struct UseTree {
3451 pub(crate) syntax: SyntaxNode,
3454 impl AstNode for UseTree {
3455 fn can_cast(kind: SyntaxKind) -> bool {
3461 fn cast(syntax: SyntaxNode) -> Option<Self> {
3462 if Self::can_cast(syntax.kind()) { Some(UseTree { syntax }) } else { None }
3464 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3469 pub fn path(&self) -> Option<Path> {
3470 super::child_opt(self)
3473 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3474 super::child_opt(self)
3477 pub fn alias(&self) -> Option<Alias> {
3478 super::child_opt(self)
3483 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3484 pub struct UseTreeList {
3485 pub(crate) syntax: SyntaxNode,
3488 impl AstNode for UseTreeList {
3489 fn can_cast(kind: SyntaxKind) -> bool {
3491 USE_TREE_LIST => true,
3495 fn cast(syntax: SyntaxNode) -> Option<Self> {
3496 if Self::can_cast(syntax.kind()) { Some(UseTreeList { syntax }) } else { None }
3498 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3503 pub fn use_trees(&self) -> impl Iterator<Item = UseTree> {
3504 super::children(self)
3509 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3510 pub struct Visibility {
3511 pub(crate) syntax: SyntaxNode,
3514 impl AstNode for Visibility {
3515 fn can_cast(kind: SyntaxKind) -> bool {
3521 fn cast(syntax: SyntaxNode) -> Option<Self> {
3522 if Self::can_cast(syntax.kind()) { Some(Visibility { syntax }) } else { None }
3524 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3531 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3532 pub struct WhereClause {
3533 pub(crate) syntax: SyntaxNode,
3536 impl AstNode for WhereClause {
3537 fn can_cast(kind: SyntaxKind) -> bool {
3539 WHERE_CLAUSE => true,
3543 fn cast(syntax: SyntaxNode) -> Option<Self> {
3544 if Self::can_cast(syntax.kind()) { Some(WhereClause { syntax }) } else { None }
3546 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3551 pub fn predicates(&self) -> impl Iterator<Item = WherePred> {
3552 super::children(self)
3557 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3558 pub struct WherePred {
3559 pub(crate) syntax: SyntaxNode,
3562 impl AstNode for WherePred {
3563 fn can_cast(kind: SyntaxKind) -> bool {
3569 fn cast(syntax: SyntaxNode) -> Option<Self> {
3570 if Self::can_cast(syntax.kind()) { Some(WherePred { syntax }) } else { None }
3572 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3576 impl ast::TypeBoundsOwner for WherePred {}
3578 pub fn type_ref(&self) -> Option<TypeRef> {
3579 super::child_opt(self)
3584 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3585 pub struct WhileExpr {
3586 pub(crate) syntax: SyntaxNode,
3589 impl AstNode for WhileExpr {
3590 fn can_cast(kind: SyntaxKind) -> bool {
3596 fn cast(syntax: SyntaxNode) -> Option<Self> {
3597 if Self::can_cast(syntax.kind()) { Some(WhileExpr { syntax }) } else { None }
3599 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3603 impl ast::LoopBodyOwner for WhileExpr {}
3605 pub fn condition(&self) -> Option<Condition> {
3606 super::child_opt(self)