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 {}
2017 pub fn pat(&self) -> Option<Pat> {
2018 super::child_opt(self)
2023 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2024 pub struct ParamList {
2025 pub(crate) syntax: SyntaxNode,
2028 impl AstNode for ParamList {
2029 fn can_cast(kind: SyntaxKind) -> bool {
2035 fn cast(syntax: SyntaxNode) -> Option<Self> {
2036 if Self::can_cast(syntax.kind()) { Some(ParamList { syntax }) } else { None }
2038 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2043 pub fn params(&self) -> impl Iterator<Item = Param> {
2044 super::children(self)
2047 pub fn self_param(&self) -> Option<SelfParam> {
2048 super::child_opt(self)
2053 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2054 pub struct ParenExpr {
2055 pub(crate) syntax: SyntaxNode,
2058 impl AstNode for ParenExpr {
2059 fn can_cast(kind: SyntaxKind) -> bool {
2065 fn cast(syntax: SyntaxNode) -> Option<Self> {
2066 if Self::can_cast(syntax.kind()) { Some(ParenExpr { syntax }) } else { None }
2068 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2073 pub fn expr(&self) -> Option<Expr> {
2074 super::child_opt(self)
2079 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2080 pub struct ParenType {
2081 pub(crate) syntax: SyntaxNode,
2084 impl AstNode for ParenType {
2085 fn can_cast(kind: SyntaxKind) -> bool {
2091 fn cast(syntax: SyntaxNode) -> Option<Self> {
2092 if Self::can_cast(syntax.kind()) { Some(ParenType { syntax }) } else { None }
2094 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2099 pub fn type_ref(&self) -> Option<TypeRef> {
2100 super::child_opt(self)
2105 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2107 pub(crate) syntax: SyntaxNode,
2110 impl AstNode for Pat {
2111 fn can_cast(kind: SyntaxKind) -> bool {
2113 | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2117 fn cast(syntax: SyntaxNode) -> Option<Self> {
2118 if Self::can_cast(syntax.kind()) { Some(Pat { syntax }) } else { None }
2120 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2124 #[derive(Debug, Clone, PartialEq, Eq)]
2128 PlaceholderPat(PlaceholderPat),
2130 StructPat(StructPat),
2131 TupleStructPat(TupleStructPat),
2135 LiteralPat(LiteralPat),
2137 impl From<RefPat> for Pat {
2138 fn from(n: RefPat) -> Pat { Pat { syntax: n.syntax } }
2140 impl From<BindPat> for Pat {
2141 fn from(n: BindPat) -> Pat { Pat { syntax: n.syntax } }
2143 impl From<PlaceholderPat> for Pat {
2144 fn from(n: PlaceholderPat) -> Pat { Pat { syntax: n.syntax } }
2146 impl From<PathPat> for Pat {
2147 fn from(n: PathPat) -> Pat { Pat { syntax: n.syntax } }
2149 impl From<StructPat> for Pat {
2150 fn from(n: StructPat) -> Pat { Pat { syntax: n.syntax } }
2152 impl From<TupleStructPat> for Pat {
2153 fn from(n: TupleStructPat) -> Pat { Pat { syntax: n.syntax } }
2155 impl From<TuplePat> for Pat {
2156 fn from(n: TuplePat) -> Pat { Pat { syntax: n.syntax } }
2158 impl From<SlicePat> for Pat {
2159 fn from(n: SlicePat) -> Pat { Pat { syntax: n.syntax } }
2161 impl From<RangePat> for Pat {
2162 fn from(n: RangePat) -> Pat { Pat { syntax: n.syntax } }
2164 impl From<LiteralPat> for Pat {
2165 fn from(n: LiteralPat) -> Pat { Pat { syntax: n.syntax } }
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!(),
2188 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2190 pub(crate) syntax: SyntaxNode,
2193 impl AstNode for Path {
2194 fn can_cast(kind: SyntaxKind) -> bool {
2200 fn cast(syntax: SyntaxNode) -> Option<Self> {
2201 if Self::can_cast(syntax.kind()) { Some(Path { syntax }) } else { None }
2203 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2208 pub fn segment(&self) -> Option<PathSegment> {
2209 super::child_opt(self)
2212 pub fn qualifier(&self) -> Option<Path> {
2213 super::child_opt(self)
2218 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2219 pub struct PathExpr {
2220 pub(crate) syntax: SyntaxNode,
2223 impl AstNode for PathExpr {
2224 fn can_cast(kind: SyntaxKind) -> bool {
2230 fn cast(syntax: SyntaxNode) -> Option<Self> {
2231 if Self::can_cast(syntax.kind()) { Some(PathExpr { syntax }) } else { None }
2233 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2238 pub fn path(&self) -> Option<Path> {
2239 super::child_opt(self)
2244 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2245 pub struct PathPat {
2246 pub(crate) syntax: SyntaxNode,
2249 impl AstNode for PathPat {
2250 fn can_cast(kind: SyntaxKind) -> bool {
2256 fn cast(syntax: SyntaxNode) -> Option<Self> {
2257 if Self::can_cast(syntax.kind()) { Some(PathPat { syntax }) } else { None }
2259 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2264 pub fn path(&self) -> Option<Path> {
2265 super::child_opt(self)
2270 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2271 pub struct PathSegment {
2272 pub(crate) syntax: SyntaxNode,
2275 impl AstNode for PathSegment {
2276 fn can_cast(kind: SyntaxKind) -> bool {
2278 PATH_SEGMENT => true,
2282 fn cast(syntax: SyntaxNode) -> Option<Self> {
2283 if Self::can_cast(syntax.kind()) { Some(PathSegment { syntax }) } else { None }
2285 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2290 pub fn name_ref(&self) -> Option<NameRef> {
2291 super::child_opt(self)
2294 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2295 super::child_opt(self)
2300 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2301 pub struct PathType {
2302 pub(crate) syntax: SyntaxNode,
2305 impl AstNode for PathType {
2306 fn can_cast(kind: SyntaxKind) -> bool {
2312 fn cast(syntax: SyntaxNode) -> Option<Self> {
2313 if Self::can_cast(syntax.kind()) { Some(PathType { syntax }) } else { None }
2315 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2320 pub fn path(&self) -> Option<Path> {
2321 super::child_opt(self)
2326 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2327 pub struct PlaceholderPat {
2328 pub(crate) syntax: SyntaxNode,
2331 impl AstNode for PlaceholderPat {
2332 fn can_cast(kind: SyntaxKind) -> bool {
2334 PLACEHOLDER_PAT => true,
2338 fn cast(syntax: SyntaxNode) -> Option<Self> {
2339 if Self::can_cast(syntax.kind()) { Some(PlaceholderPat { syntax }) } else { None }
2341 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2345 impl PlaceholderPat {}
2348 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2349 pub struct PlaceholderType {
2350 pub(crate) syntax: SyntaxNode,
2353 impl AstNode for PlaceholderType {
2354 fn can_cast(kind: SyntaxKind) -> bool {
2356 PLACEHOLDER_TYPE => true,
2360 fn cast(syntax: SyntaxNode) -> Option<Self> {
2361 if Self::can_cast(syntax.kind()) { Some(PlaceholderType { syntax }) } else { None }
2363 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2367 impl PlaceholderType {}
2370 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2371 pub struct PointerType {
2372 pub(crate) syntax: SyntaxNode,
2375 impl AstNode for PointerType {
2376 fn can_cast(kind: SyntaxKind) -> bool {
2378 POINTER_TYPE => true,
2382 fn cast(syntax: SyntaxNode) -> Option<Self> {
2383 if Self::can_cast(syntax.kind()) { Some(PointerType { syntax }) } else { None }
2385 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2390 pub fn type_ref(&self) -> Option<TypeRef> {
2391 super::child_opt(self)
2396 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2397 pub struct PosFieldDef {
2398 pub(crate) syntax: SyntaxNode,
2401 impl AstNode for PosFieldDef {
2402 fn can_cast(kind: SyntaxKind) -> bool {
2404 POS_FIELD_DEF => true,
2408 fn cast(syntax: SyntaxNode) -> Option<Self> {
2409 if Self::can_cast(syntax.kind()) { Some(PosFieldDef { syntax }) } else { None }
2411 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2415 impl ast::VisibilityOwner for PosFieldDef {}
2416 impl ast::AttrsOwner for PosFieldDef {}
2418 pub fn type_ref(&self) -> Option<TypeRef> {
2419 super::child_opt(self)
2424 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2425 pub struct PosFieldDefList {
2426 pub(crate) syntax: SyntaxNode,
2429 impl AstNode for PosFieldDefList {
2430 fn can_cast(kind: SyntaxKind) -> bool {
2432 POS_FIELD_DEF_LIST => true,
2436 fn cast(syntax: SyntaxNode) -> Option<Self> {
2437 if Self::can_cast(syntax.kind()) { Some(PosFieldDefList { syntax }) } else { None }
2439 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2443 impl PosFieldDefList {
2444 pub fn fields(&self) -> impl Iterator<Item = PosFieldDef> {
2445 super::children(self)
2450 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2451 pub struct PrefixExpr {
2452 pub(crate) syntax: SyntaxNode,
2455 impl AstNode for PrefixExpr {
2456 fn can_cast(kind: SyntaxKind) -> bool {
2458 PREFIX_EXPR => true,
2462 fn cast(syntax: SyntaxNode) -> Option<Self> {
2463 if Self::can_cast(syntax.kind()) { Some(PrefixExpr { syntax }) } else { None }
2465 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2470 pub fn expr(&self) -> Option<Expr> {
2471 super::child_opt(self)
2476 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2477 pub struct RangeExpr {
2478 pub(crate) syntax: SyntaxNode,
2481 impl AstNode for RangeExpr {
2482 fn can_cast(kind: SyntaxKind) -> bool {
2488 fn cast(syntax: SyntaxNode) -> Option<Self> {
2489 if Self::can_cast(syntax.kind()) { Some(RangeExpr { syntax }) } else { None }
2491 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2498 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2499 pub struct RangePat {
2500 pub(crate) syntax: SyntaxNode,
2503 impl AstNode for RangePat {
2504 fn can_cast(kind: SyntaxKind) -> bool {
2510 fn cast(syntax: SyntaxNode) -> Option<Self> {
2511 if Self::can_cast(syntax.kind()) { Some(RangePat { syntax }) } else { None }
2513 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2520 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2521 pub struct RefExpr {
2522 pub(crate) syntax: SyntaxNode,
2525 impl AstNode for RefExpr {
2526 fn can_cast(kind: SyntaxKind) -> bool {
2532 fn cast(syntax: SyntaxNode) -> Option<Self> {
2533 if Self::can_cast(syntax.kind()) { Some(RefExpr { syntax }) } else { None }
2535 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2540 pub fn expr(&self) -> Option<Expr> {
2541 super::child_opt(self)
2546 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2548 pub(crate) syntax: SyntaxNode,
2551 impl AstNode for RefPat {
2552 fn can_cast(kind: SyntaxKind) -> bool {
2558 fn cast(syntax: SyntaxNode) -> Option<Self> {
2559 if Self::can_cast(syntax.kind()) { Some(RefPat { syntax }) } else { None }
2561 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2566 pub fn pat(&self) -> Option<Pat> {
2567 super::child_opt(self)
2572 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2573 pub struct ReferenceType {
2574 pub(crate) syntax: SyntaxNode,
2577 impl AstNode for ReferenceType {
2578 fn can_cast(kind: SyntaxKind) -> bool {
2580 REFERENCE_TYPE => true,
2584 fn cast(syntax: SyntaxNode) -> Option<Self> {
2585 if Self::can_cast(syntax.kind()) { Some(ReferenceType { syntax }) } else { None }
2587 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2591 impl ReferenceType {
2592 pub fn type_ref(&self) -> Option<TypeRef> {
2593 super::child_opt(self)
2598 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2599 pub struct RetType {
2600 pub(crate) syntax: SyntaxNode,
2603 impl AstNode for RetType {
2604 fn can_cast(kind: SyntaxKind) -> bool {
2610 fn cast(syntax: SyntaxNode) -> Option<Self> {
2611 if Self::can_cast(syntax.kind()) { Some(RetType { syntax }) } else { None }
2613 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2618 pub fn type_ref(&self) -> Option<TypeRef> {
2619 super::child_opt(self)
2624 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2625 pub struct ReturnExpr {
2626 pub(crate) syntax: SyntaxNode,
2629 impl AstNode for ReturnExpr {
2630 fn can_cast(kind: SyntaxKind) -> bool {
2632 RETURN_EXPR => true,
2636 fn cast(syntax: SyntaxNode) -> Option<Self> {
2637 if Self::can_cast(syntax.kind()) { Some(ReturnExpr { syntax }) } else { None }
2639 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2644 pub fn expr(&self) -> Option<Expr> {
2645 super::child_opt(self)
2650 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2651 pub struct SelfParam {
2652 pub(crate) syntax: SyntaxNode,
2655 impl AstNode for SelfParam {
2656 fn can_cast(kind: SyntaxKind) -> bool {
2662 fn cast(syntax: SyntaxNode) -> Option<Self> {
2663 if Self::can_cast(syntax.kind()) { Some(SelfParam { syntax }) } else { None }
2665 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2669 impl ast::TypeAscriptionOwner for SelfParam {}
2673 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2674 pub struct SlicePat {
2675 pub(crate) syntax: SyntaxNode,
2678 impl AstNode for SlicePat {
2679 fn can_cast(kind: SyntaxKind) -> bool {
2685 fn cast(syntax: SyntaxNode) -> Option<Self> {
2686 if Self::can_cast(syntax.kind()) { Some(SlicePat { syntax }) } else { None }
2688 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2695 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2696 pub struct SliceType {
2697 pub(crate) syntax: SyntaxNode,
2700 impl AstNode for SliceType {
2701 fn can_cast(kind: SyntaxKind) -> bool {
2707 fn cast(syntax: SyntaxNode) -> Option<Self> {
2708 if Self::can_cast(syntax.kind()) { Some(SliceType { syntax }) } else { None }
2710 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2715 pub fn type_ref(&self) -> Option<TypeRef> {
2716 super::child_opt(self)
2721 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2722 pub struct SourceFile {
2723 pub(crate) syntax: SyntaxNode,
2726 impl AstNode for SourceFile {
2727 fn can_cast(kind: SyntaxKind) -> bool {
2729 SOURCE_FILE => true,
2733 fn cast(syntax: SyntaxNode) -> Option<Self> {
2734 if Self::can_cast(syntax.kind()) { Some(SourceFile { syntax }) } else { None }
2736 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2740 impl ast::ModuleItemOwner for SourceFile {}
2741 impl ast::FnDefOwner for SourceFile {}
2743 pub fn modules(&self) -> impl Iterator<Item = Module> {
2744 super::children(self)
2749 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2750 pub struct StaticDef {
2751 pub(crate) syntax: SyntaxNode,
2754 impl AstNode for StaticDef {
2755 fn can_cast(kind: SyntaxKind) -> bool {
2761 fn cast(syntax: SyntaxNode) -> Option<Self> {
2762 if Self::can_cast(syntax.kind()) { Some(StaticDef { syntax }) } else { None }
2764 fn syntax(&self) -> &SyntaxNode { &self.syntax }
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 {}
2775 pub fn body(&self) -> Option<Expr> {
2776 super::child_opt(self)
2781 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2783 pub(crate) syntax: SyntaxNode,
2786 impl AstNode for Stmt {
2787 fn can_cast(kind: SyntaxKind) -> bool {
2789 | EXPR_STMT | LET_STMT => true,
2793 fn cast(syntax: SyntaxNode) -> Option<Self> {
2794 if Self::can_cast(syntax.kind()) { Some(Stmt { syntax }) } else { None }
2796 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2800 #[derive(Debug, Clone, PartialEq, Eq)]
2805 impl From<ExprStmt> for Stmt {
2806 fn from(n: ExprStmt) -> Stmt { Stmt { syntax: n.syntax } }
2808 impl From<LetStmt> for Stmt {
2809 fn from(n: LetStmt) -> Stmt { Stmt { syntax: n.syntax } }
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!(),
2824 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2825 pub struct StructDef {
2826 pub(crate) syntax: SyntaxNode,
2829 impl AstNode for StructDef {
2830 fn can_cast(kind: SyntaxKind) -> bool {
2836 fn cast(syntax: SyntaxNode) -> Option<Self> {
2837 if Self::can_cast(syntax.kind()) { Some(StructDef { syntax }) } else { None }
2839 fn syntax(&self) -> &SyntaxNode { &self.syntax }
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 {}
2851 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2852 pub struct StructLit {
2853 pub(crate) syntax: SyntaxNode,
2856 impl AstNode for StructLit {
2857 fn can_cast(kind: SyntaxKind) -> bool {
2863 fn cast(syntax: SyntaxNode) -> Option<Self> {
2864 if Self::can_cast(syntax.kind()) { Some(StructLit { syntax }) } else { None }
2866 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2871 pub fn path(&self) -> Option<Path> {
2872 super::child_opt(self)
2875 pub fn named_field_list(&self) -> Option<NamedFieldList> {
2876 super::child_opt(self)
2881 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2882 pub struct StructPat {
2883 pub(crate) syntax: SyntaxNode,
2886 impl AstNode for StructPat {
2887 fn can_cast(kind: SyntaxKind) -> bool {
2893 fn cast(syntax: SyntaxNode) -> Option<Self> {
2894 if Self::can_cast(syntax.kind()) { Some(StructPat { syntax }) } else { None }
2896 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2901 pub fn field_pat_list(&self) -> Option<FieldPatList> {
2902 super::child_opt(self)
2905 pub fn path(&self) -> Option<Path> {
2906 super::child_opt(self)
2911 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2912 pub struct TokenTree {
2913 pub(crate) syntax: SyntaxNode,
2916 impl AstNode for TokenTree {
2917 fn can_cast(kind: SyntaxKind) -> bool {
2923 fn cast(syntax: SyntaxNode) -> Option<Self> {
2924 if Self::can_cast(syntax.kind()) { Some(TokenTree { syntax }) } else { None }
2926 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2933 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2934 pub struct TraitDef {
2935 pub(crate) syntax: SyntaxNode,
2938 impl AstNode for TraitDef {
2939 fn can_cast(kind: SyntaxKind) -> bool {
2945 fn cast(syntax: SyntaxNode) -> Option<Self> {
2946 if Self::can_cast(syntax.kind()) { Some(TraitDef { syntax }) } else { None }
2948 fn syntax(&self) -> &SyntaxNode { &self.syntax }
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 {}
2959 pub fn item_list(&self) -> Option<ItemList> {
2960 super::child_opt(self)
2965 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2966 pub struct TryBlockExpr {
2967 pub(crate) syntax: SyntaxNode,
2970 impl AstNode for TryBlockExpr {
2971 fn can_cast(kind: SyntaxKind) -> bool {
2973 TRY_BLOCK_EXPR => true,
2977 fn cast(syntax: SyntaxNode) -> Option<Self> {
2978 if Self::can_cast(syntax.kind()) { Some(TryBlockExpr { syntax }) } else { None }
2980 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2984 impl ast::TryBlockBodyOwner for TryBlockExpr {}
2985 impl TryBlockExpr {}
2988 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2989 pub struct TryExpr {
2990 pub(crate) syntax: SyntaxNode,
2993 impl AstNode for TryExpr {
2994 fn can_cast(kind: SyntaxKind) -> bool {
3000 fn cast(syntax: SyntaxNode) -> Option<Self> {
3001 if Self::can_cast(syntax.kind()) { Some(TryExpr { syntax }) } else { None }
3003 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3008 pub fn expr(&self) -> Option<Expr> {
3009 super::child_opt(self)
3014 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3015 pub struct TupleExpr {
3016 pub(crate) syntax: SyntaxNode,
3019 impl AstNode for TupleExpr {
3020 fn can_cast(kind: SyntaxKind) -> bool {
3026 fn cast(syntax: SyntaxNode) -> Option<Self> {
3027 if Self::can_cast(syntax.kind()) { Some(TupleExpr { syntax }) } else { None }
3029 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3034 pub fn exprs(&self) -> impl Iterator<Item = Expr> {
3035 super::children(self)
3040 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3041 pub struct TuplePat {
3042 pub(crate) syntax: SyntaxNode,
3045 impl AstNode for TuplePat {
3046 fn can_cast(kind: SyntaxKind) -> bool {
3052 fn cast(syntax: SyntaxNode) -> Option<Self> {
3053 if Self::can_cast(syntax.kind()) { Some(TuplePat { syntax }) } else { None }
3055 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3060 pub fn args(&self) -> impl Iterator<Item = Pat> {
3061 super::children(self)
3066 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3067 pub struct TupleStructPat {
3068 pub(crate) syntax: SyntaxNode,
3071 impl AstNode for TupleStructPat {
3072 fn can_cast(kind: SyntaxKind) -> bool {
3074 TUPLE_STRUCT_PAT => true,
3078 fn cast(syntax: SyntaxNode) -> Option<Self> {
3079 if Self::can_cast(syntax.kind()) { Some(TupleStructPat { syntax }) } else { None }
3081 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3085 impl TupleStructPat {
3086 pub fn args(&self) -> impl Iterator<Item = Pat> {
3087 super::children(self)
3090 pub fn path(&self) -> Option<Path> {
3091 super::child_opt(self)
3096 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3097 pub struct TupleType {
3098 pub(crate) syntax: SyntaxNode,
3101 impl AstNode for TupleType {
3102 fn can_cast(kind: SyntaxKind) -> bool {
3108 fn cast(syntax: SyntaxNode) -> Option<Self> {
3109 if Self::can_cast(syntax.kind()) { Some(TupleType { syntax }) } else { None }
3111 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3116 pub fn fields(&self) -> impl Iterator<Item = TypeRef> {
3117 super::children(self)
3122 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3123 pub struct TypeAliasDef {
3124 pub(crate) syntax: SyntaxNode,
3127 impl AstNode for TypeAliasDef {
3128 fn can_cast(kind: SyntaxKind) -> bool {
3130 TYPE_ALIAS_DEF => true,
3134 fn cast(syntax: SyntaxNode) -> Option<Self> {
3135 if Self::can_cast(syntax.kind()) { Some(TypeAliasDef { syntax }) } else { None }
3137 fn syntax(&self) -> &SyntaxNode { &self.syntax }
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 {}
3148 pub fn type_ref(&self) -> Option<TypeRef> {
3149 super::child_opt(self)
3154 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3155 pub struct TypeArg {
3156 pub(crate) syntax: SyntaxNode,
3159 impl AstNode for TypeArg {
3160 fn can_cast(kind: SyntaxKind) -> bool {
3166 fn cast(syntax: SyntaxNode) -> Option<Self> {
3167 if Self::can_cast(syntax.kind()) { Some(TypeArg { syntax }) } else { None }
3169 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3174 pub fn type_ref(&self) -> Option<TypeRef> {
3175 super::child_opt(self)
3180 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3181 pub struct TypeArgList {
3182 pub(crate) syntax: SyntaxNode,
3185 impl AstNode for TypeArgList {
3186 fn can_cast(kind: SyntaxKind) -> bool {
3188 TYPE_ARG_LIST => true,
3192 fn cast(syntax: SyntaxNode) -> Option<Self> {
3193 if Self::can_cast(syntax.kind()) { Some(TypeArgList { syntax }) } else { None }
3195 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3200 pub fn type_args(&self) -> impl Iterator<Item = TypeArg> {
3201 super::children(self)
3204 pub fn lifetime_args(&self) -> impl Iterator<Item = LifetimeArg> {
3205 super::children(self)
3208 pub fn assoc_type_args(&self) -> impl Iterator<Item = AssocTypeArg> {
3209 super::children(self)
3214 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3215 pub struct TypeBound {
3216 pub(crate) syntax: SyntaxNode,
3219 impl AstNode for TypeBound {
3220 fn can_cast(kind: SyntaxKind) -> bool {
3226 fn cast(syntax: SyntaxNode) -> Option<Self> {
3227 if Self::can_cast(syntax.kind()) { Some(TypeBound { syntax }) } else { None }
3229 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3234 pub fn type_ref(&self) -> Option<TypeRef> {
3235 super::child_opt(self)
3240 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3241 pub struct TypeBoundList {
3242 pub(crate) syntax: SyntaxNode,
3245 impl AstNode for TypeBoundList {
3246 fn can_cast(kind: SyntaxKind) -> bool {
3248 TYPE_BOUND_LIST => true,
3252 fn cast(syntax: SyntaxNode) -> Option<Self> {
3253 if Self::can_cast(syntax.kind()) { Some(TypeBoundList { syntax }) } else { None }
3255 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3259 impl TypeBoundList {
3260 pub fn bounds(&self) -> impl Iterator<Item = TypeBound> {
3261 super::children(self)
3266 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3267 pub struct TypeParam {
3268 pub(crate) syntax: SyntaxNode,
3271 impl AstNode for TypeParam {
3272 fn can_cast(kind: SyntaxKind) -> bool {
3278 fn cast(syntax: SyntaxNode) -> Option<Self> {
3279 if Self::can_cast(syntax.kind()) { Some(TypeParam { syntax }) } else { None }
3281 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3285 impl ast::NameOwner for TypeParam {}
3286 impl ast::AttrsOwner for TypeParam {}
3287 impl ast::TypeBoundsOwner for TypeParam {}
3288 impl ast::DefaultTypeParamOwner for TypeParam {}
3292 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3293 pub struct TypeParamList {
3294 pub(crate) syntax: SyntaxNode,
3297 impl AstNode for TypeParamList {
3298 fn can_cast(kind: SyntaxKind) -> bool {
3300 TYPE_PARAM_LIST => true,
3304 fn cast(syntax: SyntaxNode) -> Option<Self> {
3305 if Self::can_cast(syntax.kind()) { Some(TypeParamList { syntax }) } else { None }
3307 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3311 impl TypeParamList {
3312 pub fn type_params(&self) -> impl Iterator<Item = TypeParam> {
3313 super::children(self)
3316 pub fn lifetime_params(&self) -> impl Iterator<Item = LifetimeParam> {
3317 super::children(self)
3322 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3323 pub struct TypeRef {
3324 pub(crate) syntax: SyntaxNode,
3327 impl AstNode for TypeRef {
3328 fn can_cast(kind: SyntaxKind) -> bool {
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,
3334 fn cast(syntax: SyntaxNode) -> Option<Self> {
3335 if Self::can_cast(syntax.kind()) { Some(TypeRef { syntax }) } else { None }
3337 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3341 #[derive(Debug, Clone, PartialEq, Eq)]
3342 pub enum TypeRefKind {
3343 ParenType(ParenType),
3344 TupleType(TupleType),
3345 NeverType(NeverType),
3347 PointerType(PointerType),
3348 ArrayType(ArrayType),
3349 SliceType(SliceType),
3350 ReferenceType(ReferenceType),
3351 PlaceholderType(PlaceholderType),
3352 FnPointerType(FnPointerType),
3354 ImplTraitType(ImplTraitType),
3355 DynTraitType(DynTraitType),
3357 impl From<ParenType> for TypeRef {
3358 fn from(n: ParenType) -> TypeRef { TypeRef { syntax: n.syntax } }
3360 impl From<TupleType> for TypeRef {
3361 fn from(n: TupleType) -> TypeRef { TypeRef { syntax: n.syntax } }
3363 impl From<NeverType> for TypeRef {
3364 fn from(n: NeverType) -> TypeRef { TypeRef { syntax: n.syntax } }
3366 impl From<PathType> for TypeRef {
3367 fn from(n: PathType) -> TypeRef { TypeRef { syntax: n.syntax } }
3369 impl From<PointerType> for TypeRef {
3370 fn from(n: PointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3372 impl From<ArrayType> for TypeRef {
3373 fn from(n: ArrayType) -> TypeRef { TypeRef { syntax: n.syntax } }
3375 impl From<SliceType> for TypeRef {
3376 fn from(n: SliceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3378 impl From<ReferenceType> for TypeRef {
3379 fn from(n: ReferenceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3381 impl From<PlaceholderType> for TypeRef {
3382 fn from(n: PlaceholderType) -> TypeRef { TypeRef { syntax: n.syntax } }
3384 impl From<FnPointerType> for TypeRef {
3385 fn from(n: FnPointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3387 impl From<ForType> for TypeRef {
3388 fn from(n: ForType) -> TypeRef { TypeRef { syntax: n.syntax } }
3390 impl From<ImplTraitType> for TypeRef {
3391 fn from(n: ImplTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3393 impl From<DynTraitType> for TypeRef {
3394 fn from(n: DynTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
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!(),
3420 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3421 pub struct UseItem {
3422 pub(crate) syntax: SyntaxNode,
3425 impl AstNode for UseItem {
3426 fn can_cast(kind: SyntaxKind) -> bool {
3432 fn cast(syntax: SyntaxNode) -> Option<Self> {
3433 if Self::can_cast(syntax.kind()) { Some(UseItem { syntax }) } else { None }
3435 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3439 impl ast::AttrsOwner for UseItem {}
3441 pub fn use_tree(&self) -> Option<UseTree> {
3442 super::child_opt(self)
3447 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3448 pub struct UseTree {
3449 pub(crate) syntax: SyntaxNode,
3452 impl AstNode for UseTree {
3453 fn can_cast(kind: SyntaxKind) -> bool {
3459 fn cast(syntax: SyntaxNode) -> Option<Self> {
3460 if Self::can_cast(syntax.kind()) { Some(UseTree { syntax }) } else { None }
3462 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3467 pub fn path(&self) -> Option<Path> {
3468 super::child_opt(self)
3471 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3472 super::child_opt(self)
3475 pub fn alias(&self) -> Option<Alias> {
3476 super::child_opt(self)
3481 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3482 pub struct UseTreeList {
3483 pub(crate) syntax: SyntaxNode,
3486 impl AstNode for UseTreeList {
3487 fn can_cast(kind: SyntaxKind) -> bool {
3489 USE_TREE_LIST => true,
3493 fn cast(syntax: SyntaxNode) -> Option<Self> {
3494 if Self::can_cast(syntax.kind()) { Some(UseTreeList { syntax }) } else { None }
3496 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3501 pub fn use_trees(&self) -> impl Iterator<Item = UseTree> {
3502 super::children(self)
3507 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3508 pub struct Visibility {
3509 pub(crate) syntax: SyntaxNode,
3512 impl AstNode for Visibility {
3513 fn can_cast(kind: SyntaxKind) -> bool {
3519 fn cast(syntax: SyntaxNode) -> Option<Self> {
3520 if Self::can_cast(syntax.kind()) { Some(Visibility { syntax }) } else { None }
3522 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3529 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3530 pub struct WhereClause {
3531 pub(crate) syntax: SyntaxNode,
3534 impl AstNode for WhereClause {
3535 fn can_cast(kind: SyntaxKind) -> bool {
3537 WHERE_CLAUSE => true,
3541 fn cast(syntax: SyntaxNode) -> Option<Self> {
3542 if Self::can_cast(syntax.kind()) { Some(WhereClause { syntax }) } else { None }
3544 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3549 pub fn predicates(&self) -> impl Iterator<Item = WherePred> {
3550 super::children(self)
3555 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3556 pub struct WherePred {
3557 pub(crate) syntax: SyntaxNode,
3560 impl AstNode for WherePred {
3561 fn can_cast(kind: SyntaxKind) -> bool {
3567 fn cast(syntax: SyntaxNode) -> Option<Self> {
3568 if Self::can_cast(syntax.kind()) { Some(WherePred { syntax }) } else { None }
3570 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3574 impl ast::TypeBoundsOwner for WherePred {}
3576 pub fn type_ref(&self) -> Option<TypeRef> {
3577 super::child_opt(self)
3582 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3583 pub struct WhileExpr {
3584 pub(crate) syntax: SyntaxNode,
3587 impl AstNode for WhileExpr {
3588 fn can_cast(kind: SyntaxKind) -> bool {
3594 fn cast(syntax: SyntaxNode) -> Option<Self> {
3595 if Self::can_cast(syntax.kind()) { Some(WhileExpr { syntax }) } else { None }
3597 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3601 impl ast::LoopBodyOwner for WhileExpr {}
3603 pub fn condition(&self) -> Option<Condition> {
3604 super::child_opt(self)