1 // Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`
4 ast::{self, AstChildren, AstNode},
8 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
10 pub(crate) syntax: SyntaxNode,
12 impl AstNode for Alias {
13 fn can_cast(kind: SyntaxKind) -> bool {
19 fn cast(syntax: SyntaxNode) -> Option<Self> {
20 if Self::can_cast(syntax.kind()) {
26 fn syntax(&self) -> &SyntaxNode {
30 impl ast::NameOwner for Alias {}
32 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
34 pub(crate) syntax: SyntaxNode,
36 impl AstNode for ArgList {
37 fn can_cast(kind: SyntaxKind) -> bool {
43 fn cast(syntax: SyntaxNode) -> Option<Self> {
44 if Self::can_cast(syntax.kind()) {
50 fn syntax(&self) -> &SyntaxNode {
55 pub fn args(&self) -> AstChildren<Expr> {
56 AstChildren::new(&self.syntax)
59 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
60 pub struct ArrayExpr {
61 pub(crate) syntax: SyntaxNode,
63 impl AstNode for ArrayExpr {
64 fn can_cast(kind: SyntaxKind) -> bool {
70 fn cast(syntax: SyntaxNode) -> Option<Self> {
71 if Self::can_cast(syntax.kind()) {
77 fn syntax(&self) -> &SyntaxNode {
82 pub fn exprs(&self) -> AstChildren<Expr> {
83 AstChildren::new(&self.syntax)
86 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
87 pub struct ArrayType {
88 pub(crate) syntax: SyntaxNode,
90 impl AstNode for ArrayType {
91 fn can_cast(kind: SyntaxKind) -> bool {
97 fn cast(syntax: SyntaxNode) -> Option<Self> {
98 if Self::can_cast(syntax.kind()) {
104 fn syntax(&self) -> &SyntaxNode {
109 pub fn type_ref(&self) -> Option<TypeRef> {
110 AstChildren::new(&self.syntax).next()
112 pub fn expr(&self) -> Option<Expr> {
113 AstChildren::new(&self.syntax).next()
116 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
117 pub struct AssocTypeArg {
118 pub(crate) syntax: SyntaxNode,
120 impl AstNode for AssocTypeArg {
121 fn can_cast(kind: SyntaxKind) -> bool {
123 ASSOC_TYPE_ARG => true,
127 fn cast(syntax: SyntaxNode) -> Option<Self> {
128 if Self::can_cast(syntax.kind()) {
129 Some(Self { syntax })
134 fn syntax(&self) -> &SyntaxNode {
139 pub fn name_ref(&self) -> Option<NameRef> {
140 AstChildren::new(&self.syntax).next()
142 pub fn type_ref(&self) -> Option<TypeRef> {
143 AstChildren::new(&self.syntax).next()
146 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
148 pub(crate) syntax: SyntaxNode,
150 impl AstNode for Attr {
151 fn can_cast(kind: SyntaxKind) -> bool {
157 fn cast(syntax: SyntaxNode) -> Option<Self> {
158 if Self::can_cast(syntax.kind()) {
159 Some(Self { syntax })
164 fn syntax(&self) -> &SyntaxNode {
169 pub fn value(&self) -> Option<TokenTree> {
170 AstChildren::new(&self.syntax).next()
173 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
174 pub struct AwaitExpr {
175 pub(crate) syntax: SyntaxNode,
177 impl AstNode for AwaitExpr {
178 fn can_cast(kind: SyntaxKind) -> bool {
184 fn cast(syntax: SyntaxNode) -> Option<Self> {
185 if Self::can_cast(syntax.kind()) {
186 Some(Self { syntax })
191 fn syntax(&self) -> &SyntaxNode {
196 pub fn expr(&self) -> Option<Expr> {
197 AstChildren::new(&self.syntax).next()
200 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
202 pub(crate) syntax: SyntaxNode,
204 impl AstNode for BinExpr {
205 fn can_cast(kind: SyntaxKind) -> bool {
211 fn cast(syntax: SyntaxNode) -> Option<Self> {
212 if Self::can_cast(syntax.kind()) {
213 Some(Self { syntax })
218 fn syntax(&self) -> &SyntaxNode {
223 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
225 pub(crate) syntax: SyntaxNode,
227 impl AstNode for BindPat {
228 fn can_cast(kind: SyntaxKind) -> bool {
234 fn cast(syntax: SyntaxNode) -> Option<Self> {
235 if Self::can_cast(syntax.kind()) {
236 Some(Self { syntax })
241 fn syntax(&self) -> &SyntaxNode {
245 impl ast::NameOwner for BindPat {}
247 pub fn pat(&self) -> Option<Pat> {
248 AstChildren::new(&self.syntax).next()
251 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
253 pub(crate) syntax: SyntaxNode,
255 impl AstNode for Block {
256 fn can_cast(kind: SyntaxKind) -> bool {
262 fn cast(syntax: SyntaxNode) -> Option<Self> {
263 if Self::can_cast(syntax.kind()) {
264 Some(Self { syntax })
269 fn syntax(&self) -> &SyntaxNode {
273 impl ast::AttrsOwner for Block {}
275 pub fn statements(&self) -> AstChildren<Stmt> {
276 AstChildren::new(&self.syntax)
278 pub fn expr(&self) -> Option<Expr> {
279 AstChildren::new(&self.syntax).next()
282 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
283 pub struct BlockExpr {
284 pub(crate) syntax: SyntaxNode,
286 impl AstNode for BlockExpr {
287 fn can_cast(kind: SyntaxKind) -> bool {
293 fn cast(syntax: SyntaxNode) -> Option<Self> {
294 if Self::can_cast(syntax.kind()) {
295 Some(Self { syntax })
300 fn syntax(&self) -> &SyntaxNode {
305 pub fn block(&self) -> Option<Block> {
306 AstChildren::new(&self.syntax).next()
309 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
311 pub(crate) syntax: SyntaxNode,
313 impl AstNode for BoxPat {
314 fn can_cast(kind: SyntaxKind) -> bool {
320 fn cast(syntax: SyntaxNode) -> Option<Self> {
321 if Self::can_cast(syntax.kind()) {
322 Some(Self { syntax })
327 fn syntax(&self) -> &SyntaxNode {
332 pub fn pat(&self) -> Option<Pat> {
333 AstChildren::new(&self.syntax).next()
336 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
337 pub struct BreakExpr {
338 pub(crate) syntax: SyntaxNode,
340 impl AstNode for BreakExpr {
341 fn can_cast(kind: SyntaxKind) -> bool {
347 fn cast(syntax: SyntaxNode) -> Option<Self> {
348 if Self::can_cast(syntax.kind()) {
349 Some(Self { syntax })
354 fn syntax(&self) -> &SyntaxNode {
359 pub fn expr(&self) -> Option<Expr> {
360 AstChildren::new(&self.syntax).next()
363 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
364 pub struct CallExpr {
365 pub(crate) syntax: SyntaxNode,
367 impl AstNode for CallExpr {
368 fn can_cast(kind: SyntaxKind) -> bool {
374 fn cast(syntax: SyntaxNode) -> Option<Self> {
375 if Self::can_cast(syntax.kind()) {
376 Some(Self { syntax })
381 fn syntax(&self) -> &SyntaxNode {
385 impl ast::ArgListOwner for CallExpr {}
387 pub fn expr(&self) -> Option<Expr> {
388 AstChildren::new(&self.syntax).next()
391 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
392 pub struct CastExpr {
393 pub(crate) syntax: SyntaxNode,
395 impl AstNode for CastExpr {
396 fn can_cast(kind: SyntaxKind) -> bool {
402 fn cast(syntax: SyntaxNode) -> Option<Self> {
403 if Self::can_cast(syntax.kind()) {
404 Some(Self { syntax })
409 fn syntax(&self) -> &SyntaxNode {
414 pub fn expr(&self) -> Option<Expr> {
415 AstChildren::new(&self.syntax).next()
417 pub fn type_ref(&self) -> Option<TypeRef> {
418 AstChildren::new(&self.syntax).next()
421 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
422 pub struct Condition {
423 pub(crate) syntax: SyntaxNode,
425 impl AstNode for Condition {
426 fn can_cast(kind: SyntaxKind) -> bool {
432 fn cast(syntax: SyntaxNode) -> Option<Self> {
433 if Self::can_cast(syntax.kind()) {
434 Some(Self { syntax })
439 fn syntax(&self) -> &SyntaxNode {
444 pub fn pat(&self) -> Option<Pat> {
445 AstChildren::new(&self.syntax).next()
447 pub fn expr(&self) -> Option<Expr> {
448 AstChildren::new(&self.syntax).next()
451 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
452 pub struct ConstDef {
453 pub(crate) syntax: SyntaxNode,
455 impl AstNode for ConstDef {
456 fn can_cast(kind: SyntaxKind) -> bool {
462 fn cast(syntax: SyntaxNode) -> Option<Self> {
463 if Self::can_cast(syntax.kind()) {
464 Some(Self { syntax })
469 fn syntax(&self) -> &SyntaxNode {
473 impl ast::VisibilityOwner for ConstDef {}
474 impl ast::NameOwner for ConstDef {}
475 impl ast::TypeParamsOwner for ConstDef {}
476 impl ast::AttrsOwner for ConstDef {}
477 impl ast::DocCommentsOwner for ConstDef {}
478 impl ast::TypeAscriptionOwner for ConstDef {}
480 pub fn body(&self) -> Option<Expr> {
481 AstChildren::new(&self.syntax).next()
484 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
485 pub struct ContinueExpr {
486 pub(crate) syntax: SyntaxNode,
488 impl AstNode for ContinueExpr {
489 fn can_cast(kind: SyntaxKind) -> bool {
491 CONTINUE_EXPR => true,
495 fn cast(syntax: SyntaxNode) -> Option<Self> {
496 if Self::can_cast(syntax.kind()) {
497 Some(Self { syntax })
502 fn syntax(&self) -> &SyntaxNode {
507 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
508 pub struct DynTraitType {
509 pub(crate) syntax: SyntaxNode,
511 impl AstNode for DynTraitType {
512 fn can_cast(kind: SyntaxKind) -> bool {
514 DYN_TRAIT_TYPE => true,
518 fn cast(syntax: SyntaxNode) -> Option<Self> {
519 if Self::can_cast(syntax.kind()) {
520 Some(Self { syntax })
525 fn syntax(&self) -> &SyntaxNode {
529 impl ast::TypeBoundsOwner for DynTraitType {}
531 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
533 pub(crate) syntax: SyntaxNode,
535 impl AstNode for EnumDef {
536 fn can_cast(kind: SyntaxKind) -> bool {
542 fn cast(syntax: SyntaxNode) -> Option<Self> {
543 if Self::can_cast(syntax.kind()) {
544 Some(Self { syntax })
549 fn syntax(&self) -> &SyntaxNode {
553 impl ast::VisibilityOwner for EnumDef {}
554 impl ast::NameOwner for EnumDef {}
555 impl ast::TypeParamsOwner for EnumDef {}
556 impl ast::AttrsOwner for EnumDef {}
557 impl ast::DocCommentsOwner for EnumDef {}
559 pub fn variant_list(&self) -> Option<EnumVariantList> {
560 AstChildren::new(&self.syntax).next()
563 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
564 pub struct EnumVariant {
565 pub(crate) syntax: SyntaxNode,
567 impl AstNode for EnumVariant {
568 fn can_cast(kind: SyntaxKind) -> bool {
570 ENUM_VARIANT => true,
574 fn cast(syntax: SyntaxNode) -> Option<Self> {
575 if Self::can_cast(syntax.kind()) {
576 Some(Self { syntax })
581 fn syntax(&self) -> &SyntaxNode {
585 impl ast::NameOwner for EnumVariant {}
586 impl ast::DocCommentsOwner for EnumVariant {}
587 impl ast::AttrsOwner for EnumVariant {}
589 pub fn expr(&self) -> Option<Expr> {
590 AstChildren::new(&self.syntax).next()
593 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
594 pub struct EnumVariantList {
595 pub(crate) syntax: SyntaxNode,
597 impl AstNode for EnumVariantList {
598 fn can_cast(kind: SyntaxKind) -> bool {
600 ENUM_VARIANT_LIST => true,
604 fn cast(syntax: SyntaxNode) -> Option<Self> {
605 if Self::can_cast(syntax.kind()) {
606 Some(Self { syntax })
611 fn syntax(&self) -> &SyntaxNode {
615 impl EnumVariantList {
616 pub fn variants(&self) -> AstChildren<EnumVariant> {
617 AstChildren::new(&self.syntax)
620 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
622 TupleExpr(TupleExpr),
623 ArrayExpr(ArrayExpr),
624 ParenExpr(ParenExpr),
626 LambdaExpr(LambdaExpr),
630 WhileExpr(WhileExpr),
631 ContinueExpr(ContinueExpr),
632 BreakExpr(BreakExpr),
634 BlockExpr(BlockExpr),
635 ReturnExpr(ReturnExpr),
636 MatchExpr(MatchExpr),
637 RecordLit(RecordLit),
639 IndexExpr(IndexExpr),
640 MethodCallExpr(MethodCallExpr),
641 FieldExpr(FieldExpr),
642 AwaitExpr(AwaitExpr),
644 TryBlockExpr(TryBlockExpr),
647 PrefixExpr(PrefixExpr),
648 RangeExpr(RangeExpr),
651 MacroCall(MacroCall),
653 impl From<TupleExpr> for Expr {
654 fn from(node: TupleExpr) -> Expr {
655 Expr::TupleExpr(node)
658 impl From<ArrayExpr> for Expr {
659 fn from(node: ArrayExpr) -> Expr {
660 Expr::ArrayExpr(node)
663 impl From<ParenExpr> for Expr {
664 fn from(node: ParenExpr) -> Expr {
665 Expr::ParenExpr(node)
668 impl From<PathExpr> for Expr {
669 fn from(node: PathExpr) -> Expr {
673 impl From<LambdaExpr> for Expr {
674 fn from(node: LambdaExpr) -> Expr {
675 Expr::LambdaExpr(node)
678 impl From<IfExpr> for Expr {
679 fn from(node: IfExpr) -> Expr {
683 impl From<LoopExpr> for Expr {
684 fn from(node: LoopExpr) -> Expr {
688 impl From<ForExpr> for Expr {
689 fn from(node: ForExpr) -> Expr {
693 impl From<WhileExpr> for Expr {
694 fn from(node: WhileExpr) -> Expr {
695 Expr::WhileExpr(node)
698 impl From<ContinueExpr> for Expr {
699 fn from(node: ContinueExpr) -> Expr {
700 Expr::ContinueExpr(node)
703 impl From<BreakExpr> for Expr {
704 fn from(node: BreakExpr) -> Expr {
705 Expr::BreakExpr(node)
708 impl From<Label> for Expr {
709 fn from(node: Label) -> Expr {
713 impl From<BlockExpr> for Expr {
714 fn from(node: BlockExpr) -> Expr {
715 Expr::BlockExpr(node)
718 impl From<ReturnExpr> for Expr {
719 fn from(node: ReturnExpr) -> Expr {
720 Expr::ReturnExpr(node)
723 impl From<MatchExpr> for Expr {
724 fn from(node: MatchExpr) -> Expr {
725 Expr::MatchExpr(node)
728 impl From<RecordLit> for Expr {
729 fn from(node: RecordLit) -> Expr {
730 Expr::RecordLit(node)
733 impl From<CallExpr> for Expr {
734 fn from(node: CallExpr) -> Expr {
738 impl From<IndexExpr> for Expr {
739 fn from(node: IndexExpr) -> Expr {
740 Expr::IndexExpr(node)
743 impl From<MethodCallExpr> for Expr {
744 fn from(node: MethodCallExpr) -> Expr {
745 Expr::MethodCallExpr(node)
748 impl From<FieldExpr> for Expr {
749 fn from(node: FieldExpr) -> Expr {
750 Expr::FieldExpr(node)
753 impl From<AwaitExpr> for Expr {
754 fn from(node: AwaitExpr) -> Expr {
755 Expr::AwaitExpr(node)
758 impl From<TryExpr> for Expr {
759 fn from(node: TryExpr) -> Expr {
763 impl From<TryBlockExpr> for Expr {
764 fn from(node: TryBlockExpr) -> Expr {
765 Expr::TryBlockExpr(node)
768 impl From<CastExpr> for Expr {
769 fn from(node: CastExpr) -> Expr {
773 impl From<RefExpr> for Expr {
774 fn from(node: RefExpr) -> Expr {
778 impl From<PrefixExpr> for Expr {
779 fn from(node: PrefixExpr) -> Expr {
780 Expr::PrefixExpr(node)
783 impl From<RangeExpr> for Expr {
784 fn from(node: RangeExpr) -> Expr {
785 Expr::RangeExpr(node)
788 impl From<BinExpr> for Expr {
789 fn from(node: BinExpr) -> Expr {
793 impl From<Literal> for Expr {
794 fn from(node: Literal) -> Expr {
798 impl From<MacroCall> for Expr {
799 fn from(node: MacroCall) -> Expr {
800 Expr::MacroCall(node)
803 impl AstNode for Expr {
804 fn can_cast(kind: SyntaxKind) -> bool {
806 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
807 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
808 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
809 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
810 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => {
816 fn cast(syntax: SyntaxNode) -> Option<Self> {
817 let res = match syntax.kind() {
818 TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
819 ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }),
820 PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }),
821 PATH_EXPR => Expr::PathExpr(PathExpr { syntax }),
822 LAMBDA_EXPR => Expr::LambdaExpr(LambdaExpr { syntax }),
823 IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
824 LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
825 FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
826 WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
827 CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
828 BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
829 LABEL => Expr::Label(Label { syntax }),
830 BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
831 RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
832 MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
833 RECORD_LIT => Expr::RecordLit(RecordLit { syntax }),
834 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
835 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
836 METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
837 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
838 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
839 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
840 TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
841 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
842 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
843 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
844 RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }),
845 BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
846 LITERAL => Expr::Literal(Literal { syntax }),
847 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
852 fn syntax(&self) -> &SyntaxNode {
854 Expr::TupleExpr(it) => &it.syntax,
855 Expr::ArrayExpr(it) => &it.syntax,
856 Expr::ParenExpr(it) => &it.syntax,
857 Expr::PathExpr(it) => &it.syntax,
858 Expr::LambdaExpr(it) => &it.syntax,
859 Expr::IfExpr(it) => &it.syntax,
860 Expr::LoopExpr(it) => &it.syntax,
861 Expr::ForExpr(it) => &it.syntax,
862 Expr::WhileExpr(it) => &it.syntax,
863 Expr::ContinueExpr(it) => &it.syntax,
864 Expr::BreakExpr(it) => &it.syntax,
865 Expr::Label(it) => &it.syntax,
866 Expr::BlockExpr(it) => &it.syntax,
867 Expr::ReturnExpr(it) => &it.syntax,
868 Expr::MatchExpr(it) => &it.syntax,
869 Expr::RecordLit(it) => &it.syntax,
870 Expr::CallExpr(it) => &it.syntax,
871 Expr::IndexExpr(it) => &it.syntax,
872 Expr::MethodCallExpr(it) => &it.syntax,
873 Expr::FieldExpr(it) => &it.syntax,
874 Expr::AwaitExpr(it) => &it.syntax,
875 Expr::TryExpr(it) => &it.syntax,
876 Expr::TryBlockExpr(it) => &it.syntax,
877 Expr::CastExpr(it) => &it.syntax,
878 Expr::RefExpr(it) => &it.syntax,
879 Expr::PrefixExpr(it) => &it.syntax,
880 Expr::RangeExpr(it) => &it.syntax,
881 Expr::BinExpr(it) => &it.syntax,
882 Expr::Literal(it) => &it.syntax,
883 Expr::MacroCall(it) => &it.syntax,
888 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
889 pub struct ExprStmt {
890 pub(crate) syntax: SyntaxNode,
892 impl AstNode for ExprStmt {
893 fn can_cast(kind: SyntaxKind) -> bool {
899 fn cast(syntax: SyntaxNode) -> Option<Self> {
900 if Self::can_cast(syntax.kind()) {
901 Some(Self { syntax })
906 fn syntax(&self) -> &SyntaxNode {
911 pub fn expr(&self) -> Option<Expr> {
912 AstChildren::new(&self.syntax).next()
915 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
916 pub struct ExternCrateItem {
917 pub(crate) syntax: SyntaxNode,
919 impl AstNode for ExternCrateItem {
920 fn can_cast(kind: SyntaxKind) -> bool {
922 EXTERN_CRATE_ITEM => true,
926 fn cast(syntax: SyntaxNode) -> Option<Self> {
927 if Self::can_cast(syntax.kind()) {
928 Some(Self { syntax })
933 fn syntax(&self) -> &SyntaxNode {
937 impl ExternCrateItem {
938 pub fn name_ref(&self) -> Option<NameRef> {
939 AstChildren::new(&self.syntax).next()
941 pub fn alias(&self) -> Option<Alias> {
942 AstChildren::new(&self.syntax).next()
945 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
946 pub struct FieldExpr {
947 pub(crate) syntax: SyntaxNode,
949 impl AstNode for FieldExpr {
950 fn can_cast(kind: SyntaxKind) -> bool {
956 fn cast(syntax: SyntaxNode) -> Option<Self> {
957 if Self::can_cast(syntax.kind()) {
958 Some(Self { syntax })
963 fn syntax(&self) -> &SyntaxNode {
968 pub fn expr(&self) -> Option<Expr> {
969 AstChildren::new(&self.syntax).next()
971 pub fn name_ref(&self) -> Option<NameRef> {
972 AstChildren::new(&self.syntax).next()
975 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
977 pub(crate) syntax: SyntaxNode,
979 impl AstNode for FnDef {
980 fn can_cast(kind: SyntaxKind) -> bool {
986 fn cast(syntax: SyntaxNode) -> Option<Self> {
987 if Self::can_cast(syntax.kind()) {
988 Some(Self { syntax })
993 fn syntax(&self) -> &SyntaxNode {
997 impl ast::VisibilityOwner for FnDef {}
998 impl ast::NameOwner for FnDef {}
999 impl ast::TypeParamsOwner for FnDef {}
1000 impl ast::AttrsOwner for FnDef {}
1001 impl ast::DocCommentsOwner for FnDef {}
1003 pub fn param_list(&self) -> Option<ParamList> {
1004 AstChildren::new(&self.syntax).next()
1006 pub fn body(&self) -> Option<Block> {
1007 AstChildren::new(&self.syntax).next()
1009 pub fn ret_type(&self) -> Option<RetType> {
1010 AstChildren::new(&self.syntax).next()
1013 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1014 pub struct FnPointerType {
1015 pub(crate) syntax: SyntaxNode,
1017 impl AstNode for FnPointerType {
1018 fn can_cast(kind: SyntaxKind) -> bool {
1020 FN_POINTER_TYPE => true,
1024 fn cast(syntax: SyntaxNode) -> Option<Self> {
1025 if Self::can_cast(syntax.kind()) {
1026 Some(Self { syntax })
1031 fn syntax(&self) -> &SyntaxNode {
1035 impl FnPointerType {
1036 pub fn param_list(&self) -> Option<ParamList> {
1037 AstChildren::new(&self.syntax).next()
1039 pub fn ret_type(&self) -> Option<RetType> {
1040 AstChildren::new(&self.syntax).next()
1043 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1044 pub struct ForExpr {
1045 pub(crate) syntax: SyntaxNode,
1047 impl AstNode for ForExpr {
1048 fn can_cast(kind: SyntaxKind) -> bool {
1054 fn cast(syntax: SyntaxNode) -> Option<Self> {
1055 if Self::can_cast(syntax.kind()) {
1056 Some(Self { syntax })
1061 fn syntax(&self) -> &SyntaxNode {
1065 impl ast::LoopBodyOwner for ForExpr {}
1067 pub fn pat(&self) -> Option<Pat> {
1068 AstChildren::new(&self.syntax).next()
1070 pub fn iterable(&self) -> Option<Expr> {
1071 AstChildren::new(&self.syntax).next()
1074 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1075 pub struct ForType {
1076 pub(crate) syntax: SyntaxNode,
1078 impl AstNode for ForType {
1079 fn can_cast(kind: SyntaxKind) -> bool {
1085 fn cast(syntax: SyntaxNode) -> Option<Self> {
1086 if Self::can_cast(syntax.kind()) {
1087 Some(Self { syntax })
1092 fn syntax(&self) -> &SyntaxNode {
1097 pub fn type_ref(&self) -> Option<TypeRef> {
1098 AstChildren::new(&self.syntax).next()
1101 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1103 pub(crate) syntax: SyntaxNode,
1105 impl AstNode for IfExpr {
1106 fn can_cast(kind: SyntaxKind) -> bool {
1112 fn cast(syntax: SyntaxNode) -> Option<Self> {
1113 if Self::can_cast(syntax.kind()) {
1114 Some(Self { syntax })
1119 fn syntax(&self) -> &SyntaxNode {
1124 pub fn condition(&self) -> Option<Condition> {
1125 AstChildren::new(&self.syntax).next()
1128 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1129 pub struct ImplBlock {
1130 pub(crate) syntax: SyntaxNode,
1132 impl AstNode for ImplBlock {
1133 fn can_cast(kind: SyntaxKind) -> bool {
1139 fn cast(syntax: SyntaxNode) -> Option<Self> {
1140 if Self::can_cast(syntax.kind()) {
1141 Some(Self { syntax })
1146 fn syntax(&self) -> &SyntaxNode {
1150 impl ast::TypeParamsOwner for ImplBlock {}
1151 impl ast::AttrsOwner for ImplBlock {}
1153 pub fn item_list(&self) -> Option<ItemList> {
1154 AstChildren::new(&self.syntax).next()
1157 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1160 TypeAliasDef(TypeAliasDef),
1163 impl From<FnDef> for ImplItem {
1164 fn from(node: FnDef) -> ImplItem {
1165 ImplItem::FnDef(node)
1168 impl From<TypeAliasDef> for ImplItem {
1169 fn from(node: TypeAliasDef) -> ImplItem {
1170 ImplItem::TypeAliasDef(node)
1173 impl From<ConstDef> for ImplItem {
1174 fn from(node: ConstDef) -> ImplItem {
1175 ImplItem::ConstDef(node)
1178 impl AstNode for ImplItem {
1179 fn can_cast(kind: SyntaxKind) -> bool {
1181 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1185 fn cast(syntax: SyntaxNode) -> Option<Self> {
1186 let res = match syntax.kind() {
1187 FN_DEF => ImplItem::FnDef(FnDef { syntax }),
1188 TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }),
1189 CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }),
1194 fn syntax(&self) -> &SyntaxNode {
1196 ImplItem::FnDef(it) => &it.syntax,
1197 ImplItem::TypeAliasDef(it) => &it.syntax,
1198 ImplItem::ConstDef(it) => &it.syntax,
1203 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1204 pub struct ImplTraitType {
1205 pub(crate) syntax: SyntaxNode,
1207 impl AstNode for ImplTraitType {
1208 fn can_cast(kind: SyntaxKind) -> bool {
1210 IMPL_TRAIT_TYPE => true,
1214 fn cast(syntax: SyntaxNode) -> Option<Self> {
1215 if Self::can_cast(syntax.kind()) {
1216 Some(Self { syntax })
1221 fn syntax(&self) -> &SyntaxNode {
1225 impl ast::TypeBoundsOwner for ImplTraitType {}
1226 impl ImplTraitType {}
1227 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1228 pub struct IndexExpr {
1229 pub(crate) syntax: SyntaxNode,
1231 impl AstNode for IndexExpr {
1232 fn can_cast(kind: SyntaxKind) -> bool {
1238 fn cast(syntax: SyntaxNode) -> Option<Self> {
1239 if Self::can_cast(syntax.kind()) {
1240 Some(Self { syntax })
1245 fn syntax(&self) -> &SyntaxNode {
1250 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1251 pub struct ItemList {
1252 pub(crate) syntax: SyntaxNode,
1254 impl AstNode for ItemList {
1255 fn can_cast(kind: SyntaxKind) -> bool {
1261 fn cast(syntax: SyntaxNode) -> Option<Self> {
1262 if Self::can_cast(syntax.kind()) {
1263 Some(Self { syntax })
1268 fn syntax(&self) -> &SyntaxNode {
1272 impl ast::FnDefOwner for ItemList {}
1273 impl ast::ModuleItemOwner for ItemList {}
1275 pub fn impl_items(&self) -> AstChildren<ImplItem> {
1276 AstChildren::new(&self.syntax)
1279 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1281 pub(crate) syntax: SyntaxNode,
1283 impl AstNode for Label {
1284 fn can_cast(kind: SyntaxKind) -> bool {
1290 fn cast(syntax: SyntaxNode) -> Option<Self> {
1291 if Self::can_cast(syntax.kind()) {
1292 Some(Self { syntax })
1297 fn syntax(&self) -> &SyntaxNode {
1302 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1303 pub struct LambdaExpr {
1304 pub(crate) syntax: SyntaxNode,
1306 impl AstNode for LambdaExpr {
1307 fn can_cast(kind: SyntaxKind) -> bool {
1309 LAMBDA_EXPR => true,
1313 fn cast(syntax: SyntaxNode) -> Option<Self> {
1314 if Self::can_cast(syntax.kind()) {
1315 Some(Self { syntax })
1320 fn syntax(&self) -> &SyntaxNode {
1325 pub fn param_list(&self) -> Option<ParamList> {
1326 AstChildren::new(&self.syntax).next()
1328 pub fn body(&self) -> Option<Expr> {
1329 AstChildren::new(&self.syntax).next()
1332 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1333 pub struct LetStmt {
1334 pub(crate) syntax: SyntaxNode,
1336 impl AstNode for LetStmt {
1337 fn can_cast(kind: SyntaxKind) -> bool {
1343 fn cast(syntax: SyntaxNode) -> Option<Self> {
1344 if Self::can_cast(syntax.kind()) {
1345 Some(Self { syntax })
1350 fn syntax(&self) -> &SyntaxNode {
1354 impl ast::TypeAscriptionOwner for LetStmt {}
1356 pub fn pat(&self) -> Option<Pat> {
1357 AstChildren::new(&self.syntax).next()
1359 pub fn initializer(&self) -> Option<Expr> {
1360 AstChildren::new(&self.syntax).next()
1363 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1364 pub struct LifetimeArg {
1365 pub(crate) syntax: SyntaxNode,
1367 impl AstNode for LifetimeArg {
1368 fn can_cast(kind: SyntaxKind) -> bool {
1370 LIFETIME_ARG => true,
1374 fn cast(syntax: SyntaxNode) -> Option<Self> {
1375 if Self::can_cast(syntax.kind()) {
1376 Some(Self { syntax })
1381 fn syntax(&self) -> &SyntaxNode {
1386 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1387 pub struct LifetimeParam {
1388 pub(crate) syntax: SyntaxNode,
1390 impl AstNode for LifetimeParam {
1391 fn can_cast(kind: SyntaxKind) -> bool {
1393 LIFETIME_PARAM => true,
1397 fn cast(syntax: SyntaxNode) -> Option<Self> {
1398 if Self::can_cast(syntax.kind()) {
1399 Some(Self { syntax })
1404 fn syntax(&self) -> &SyntaxNode {
1408 impl ast::AttrsOwner for LifetimeParam {}
1409 impl LifetimeParam {}
1410 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1411 pub struct Literal {
1412 pub(crate) syntax: SyntaxNode,
1414 impl AstNode for Literal {
1415 fn can_cast(kind: SyntaxKind) -> bool {
1421 fn cast(syntax: SyntaxNode) -> Option<Self> {
1422 if Self::can_cast(syntax.kind()) {
1423 Some(Self { syntax })
1428 fn syntax(&self) -> &SyntaxNode {
1433 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1434 pub struct LiteralPat {
1435 pub(crate) syntax: SyntaxNode,
1437 impl AstNode for LiteralPat {
1438 fn can_cast(kind: SyntaxKind) -> bool {
1440 LITERAL_PAT => true,
1444 fn cast(syntax: SyntaxNode) -> Option<Self> {
1445 if Self::can_cast(syntax.kind()) {
1446 Some(Self { syntax })
1451 fn syntax(&self) -> &SyntaxNode {
1456 pub fn literal(&self) -> Option<Literal> {
1457 AstChildren::new(&self.syntax).next()
1460 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1461 pub struct LoopExpr {
1462 pub(crate) syntax: SyntaxNode,
1464 impl AstNode for LoopExpr {
1465 fn can_cast(kind: SyntaxKind) -> bool {
1471 fn cast(syntax: SyntaxNode) -> Option<Self> {
1472 if Self::can_cast(syntax.kind()) {
1473 Some(Self { syntax })
1478 fn syntax(&self) -> &SyntaxNode {
1482 impl ast::LoopBodyOwner for LoopExpr {}
1484 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1485 pub struct MacroCall {
1486 pub(crate) syntax: SyntaxNode,
1488 impl AstNode for MacroCall {
1489 fn can_cast(kind: SyntaxKind) -> bool {
1495 fn cast(syntax: SyntaxNode) -> Option<Self> {
1496 if Self::can_cast(syntax.kind()) {
1497 Some(Self { syntax })
1502 fn syntax(&self) -> &SyntaxNode {
1506 impl ast::NameOwner for MacroCall {}
1507 impl ast::AttrsOwner for MacroCall {}
1508 impl ast::DocCommentsOwner for MacroCall {}
1510 pub fn token_tree(&self) -> Option<TokenTree> {
1511 AstChildren::new(&self.syntax).next()
1513 pub fn path(&self) -> Option<Path> {
1514 AstChildren::new(&self.syntax).next()
1517 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1518 pub struct MacroItems {
1519 pub(crate) syntax: SyntaxNode,
1521 impl AstNode for MacroItems {
1522 fn can_cast(kind: SyntaxKind) -> bool {
1524 MACRO_ITEMS => true,
1528 fn cast(syntax: SyntaxNode) -> Option<Self> {
1529 if Self::can_cast(syntax.kind()) {
1530 Some(Self { syntax })
1535 fn syntax(&self) -> &SyntaxNode {
1539 impl ast::ModuleItemOwner for MacroItems {}
1540 impl ast::FnDefOwner for MacroItems {}
1542 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1543 pub struct MacroStmts {
1544 pub(crate) syntax: SyntaxNode,
1546 impl AstNode for MacroStmts {
1547 fn can_cast(kind: SyntaxKind) -> bool {
1549 MACRO_STMTS => true,
1553 fn cast(syntax: SyntaxNode) -> Option<Self> {
1554 if Self::can_cast(syntax.kind()) {
1555 Some(Self { syntax })
1560 fn syntax(&self) -> &SyntaxNode {
1565 pub fn statements(&self) -> AstChildren<Stmt> {
1566 AstChildren::new(&self.syntax)
1568 pub fn expr(&self) -> Option<Expr> {
1569 AstChildren::new(&self.syntax).next()
1572 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1573 pub struct MatchArm {
1574 pub(crate) syntax: SyntaxNode,
1576 impl AstNode for MatchArm {
1577 fn can_cast(kind: SyntaxKind) -> bool {
1583 fn cast(syntax: SyntaxNode) -> Option<Self> {
1584 if Self::can_cast(syntax.kind()) {
1585 Some(Self { syntax })
1590 fn syntax(&self) -> &SyntaxNode {
1594 impl ast::AttrsOwner for MatchArm {}
1596 pub fn pats(&self) -> AstChildren<Pat> {
1597 AstChildren::new(&self.syntax)
1599 pub fn guard(&self) -> Option<MatchGuard> {
1600 AstChildren::new(&self.syntax).next()
1602 pub fn expr(&self) -> Option<Expr> {
1603 AstChildren::new(&self.syntax).next()
1606 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1607 pub struct MatchArmList {
1608 pub(crate) syntax: SyntaxNode,
1610 impl AstNode for MatchArmList {
1611 fn can_cast(kind: SyntaxKind) -> bool {
1613 MATCH_ARM_LIST => true,
1617 fn cast(syntax: SyntaxNode) -> Option<Self> {
1618 if Self::can_cast(syntax.kind()) {
1619 Some(Self { syntax })
1624 fn syntax(&self) -> &SyntaxNode {
1628 impl ast::AttrsOwner for MatchArmList {}
1630 pub fn arms(&self) -> AstChildren<MatchArm> {
1631 AstChildren::new(&self.syntax)
1634 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1635 pub struct MatchExpr {
1636 pub(crate) syntax: SyntaxNode,
1638 impl AstNode for MatchExpr {
1639 fn can_cast(kind: SyntaxKind) -> bool {
1645 fn cast(syntax: SyntaxNode) -> Option<Self> {
1646 if Self::can_cast(syntax.kind()) {
1647 Some(Self { syntax })
1652 fn syntax(&self) -> &SyntaxNode {
1657 pub fn expr(&self) -> Option<Expr> {
1658 AstChildren::new(&self.syntax).next()
1660 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1661 AstChildren::new(&self.syntax).next()
1664 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1665 pub struct MatchGuard {
1666 pub(crate) syntax: SyntaxNode,
1668 impl AstNode for MatchGuard {
1669 fn can_cast(kind: SyntaxKind) -> bool {
1671 MATCH_GUARD => true,
1675 fn cast(syntax: SyntaxNode) -> Option<Self> {
1676 if Self::can_cast(syntax.kind()) {
1677 Some(Self { syntax })
1682 fn syntax(&self) -> &SyntaxNode {
1687 pub fn expr(&self) -> Option<Expr> {
1688 AstChildren::new(&self.syntax).next()
1691 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1692 pub struct MethodCallExpr {
1693 pub(crate) syntax: SyntaxNode,
1695 impl AstNode for MethodCallExpr {
1696 fn can_cast(kind: SyntaxKind) -> bool {
1698 METHOD_CALL_EXPR => true,
1702 fn cast(syntax: SyntaxNode) -> Option<Self> {
1703 if Self::can_cast(syntax.kind()) {
1704 Some(Self { syntax })
1709 fn syntax(&self) -> &SyntaxNode {
1713 impl ast::ArgListOwner for MethodCallExpr {}
1714 impl MethodCallExpr {
1715 pub fn expr(&self) -> Option<Expr> {
1716 AstChildren::new(&self.syntax).next()
1718 pub fn name_ref(&self) -> Option<NameRef> {
1719 AstChildren::new(&self.syntax).next()
1721 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1722 AstChildren::new(&self.syntax).next()
1725 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1727 pub(crate) syntax: SyntaxNode,
1729 impl AstNode for Module {
1730 fn can_cast(kind: SyntaxKind) -> bool {
1736 fn cast(syntax: SyntaxNode) -> Option<Self> {
1737 if Self::can_cast(syntax.kind()) {
1738 Some(Self { syntax })
1743 fn syntax(&self) -> &SyntaxNode {
1747 impl ast::VisibilityOwner for Module {}
1748 impl ast::NameOwner for Module {}
1749 impl ast::AttrsOwner for Module {}
1750 impl ast::DocCommentsOwner for Module {}
1752 pub fn item_list(&self) -> Option<ItemList> {
1753 AstChildren::new(&self.syntax).next()
1756 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1757 pub enum ModuleItem {
1758 StructDef(StructDef),
1762 TypeAliasDef(TypeAliasDef),
1763 ImplBlock(ImplBlock),
1765 ExternCrateItem(ExternCrateItem),
1767 StaticDef(StaticDef),
1770 impl From<StructDef> for ModuleItem {
1771 fn from(node: StructDef) -> ModuleItem {
1772 ModuleItem::StructDef(node)
1775 impl From<EnumDef> for ModuleItem {
1776 fn from(node: EnumDef) -> ModuleItem {
1777 ModuleItem::EnumDef(node)
1780 impl From<FnDef> for ModuleItem {
1781 fn from(node: FnDef) -> ModuleItem {
1782 ModuleItem::FnDef(node)
1785 impl From<TraitDef> for ModuleItem {
1786 fn from(node: TraitDef) -> ModuleItem {
1787 ModuleItem::TraitDef(node)
1790 impl From<TypeAliasDef> for ModuleItem {
1791 fn from(node: TypeAliasDef) -> ModuleItem {
1792 ModuleItem::TypeAliasDef(node)
1795 impl From<ImplBlock> for ModuleItem {
1796 fn from(node: ImplBlock) -> ModuleItem {
1797 ModuleItem::ImplBlock(node)
1800 impl From<UseItem> for ModuleItem {
1801 fn from(node: UseItem) -> ModuleItem {
1802 ModuleItem::UseItem(node)
1805 impl From<ExternCrateItem> for ModuleItem {
1806 fn from(node: ExternCrateItem) -> ModuleItem {
1807 ModuleItem::ExternCrateItem(node)
1810 impl From<ConstDef> for ModuleItem {
1811 fn from(node: ConstDef) -> ModuleItem {
1812 ModuleItem::ConstDef(node)
1815 impl From<StaticDef> for ModuleItem {
1816 fn from(node: StaticDef) -> ModuleItem {
1817 ModuleItem::StaticDef(node)
1820 impl From<Module> for ModuleItem {
1821 fn from(node: Module) -> ModuleItem {
1822 ModuleItem::Module(node)
1825 impl AstNode for ModuleItem {
1826 fn can_cast(kind: SyntaxKind) -> bool {
1828 STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM
1829 | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1833 fn cast(syntax: SyntaxNode) -> Option<Self> {
1834 let res = match syntax.kind() {
1835 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
1836 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
1837 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
1838 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
1839 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
1840 IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
1841 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
1842 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
1843 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
1844 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
1845 MODULE => ModuleItem::Module(Module { syntax }),
1850 fn syntax(&self) -> &SyntaxNode {
1852 ModuleItem::StructDef(it) => &it.syntax,
1853 ModuleItem::EnumDef(it) => &it.syntax,
1854 ModuleItem::FnDef(it) => &it.syntax,
1855 ModuleItem::TraitDef(it) => &it.syntax,
1856 ModuleItem::TypeAliasDef(it) => &it.syntax,
1857 ModuleItem::ImplBlock(it) => &it.syntax,
1858 ModuleItem::UseItem(it) => &it.syntax,
1859 ModuleItem::ExternCrateItem(it) => &it.syntax,
1860 ModuleItem::ConstDef(it) => &it.syntax,
1861 ModuleItem::StaticDef(it) => &it.syntax,
1862 ModuleItem::Module(it) => &it.syntax,
1867 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1869 pub(crate) syntax: SyntaxNode,
1871 impl AstNode for Name {
1872 fn can_cast(kind: SyntaxKind) -> bool {
1878 fn cast(syntax: SyntaxNode) -> Option<Self> {
1879 if Self::can_cast(syntax.kind()) {
1880 Some(Self { syntax })
1885 fn syntax(&self) -> &SyntaxNode {
1890 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1891 pub struct NameRef {
1892 pub(crate) syntax: SyntaxNode,
1894 impl AstNode for NameRef {
1895 fn can_cast(kind: SyntaxKind) -> bool {
1901 fn cast(syntax: SyntaxNode) -> Option<Self> {
1902 if Self::can_cast(syntax.kind()) {
1903 Some(Self { syntax })
1908 fn syntax(&self) -> &SyntaxNode {
1913 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1914 pub struct NeverType {
1915 pub(crate) syntax: SyntaxNode,
1917 impl AstNode for NeverType {
1918 fn can_cast(kind: SyntaxKind) -> bool {
1924 fn cast(syntax: SyntaxNode) -> Option<Self> {
1925 if Self::can_cast(syntax.kind()) {
1926 Some(Self { syntax })
1931 fn syntax(&self) -> &SyntaxNode {
1936 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1937 pub enum NominalDef {
1938 StructDef(StructDef),
1941 impl From<StructDef> for NominalDef {
1942 fn from(node: StructDef) -> NominalDef {
1943 NominalDef::StructDef(node)
1946 impl From<EnumDef> for NominalDef {
1947 fn from(node: EnumDef) -> NominalDef {
1948 NominalDef::EnumDef(node)
1951 impl AstNode for NominalDef {
1952 fn can_cast(kind: SyntaxKind) -> bool {
1954 STRUCT_DEF | ENUM_DEF => true,
1958 fn cast(syntax: SyntaxNode) -> Option<Self> {
1959 let res = match syntax.kind() {
1960 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
1961 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
1966 fn syntax(&self) -> &SyntaxNode {
1968 NominalDef::StructDef(it) => &it.syntax,
1969 NominalDef::EnumDef(it) => &it.syntax,
1973 impl ast::NameOwner for NominalDef {}
1974 impl ast::TypeParamsOwner for NominalDef {}
1975 impl ast::AttrsOwner for NominalDef {}
1977 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1979 pub(crate) syntax: SyntaxNode,
1981 impl AstNode for Param {
1982 fn can_cast(kind: SyntaxKind) -> bool {
1988 fn cast(syntax: SyntaxNode) -> Option<Self> {
1989 if Self::can_cast(syntax.kind()) {
1990 Some(Self { syntax })
1995 fn syntax(&self) -> &SyntaxNode {
1999 impl ast::TypeAscriptionOwner for Param {}
2000 impl ast::AttrsOwner for Param {}
2002 pub fn pat(&self) -> Option<Pat> {
2003 AstChildren::new(&self.syntax).next()
2006 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2007 pub struct ParamList {
2008 pub(crate) syntax: SyntaxNode,
2010 impl AstNode for ParamList {
2011 fn can_cast(kind: SyntaxKind) -> bool {
2017 fn cast(syntax: SyntaxNode) -> Option<Self> {
2018 if Self::can_cast(syntax.kind()) {
2019 Some(Self { syntax })
2024 fn syntax(&self) -> &SyntaxNode {
2029 pub fn params(&self) -> AstChildren<Param> {
2030 AstChildren::new(&self.syntax)
2032 pub fn self_param(&self) -> Option<SelfParam> {
2033 AstChildren::new(&self.syntax).next()
2036 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2037 pub struct ParenExpr {
2038 pub(crate) syntax: SyntaxNode,
2040 impl AstNode for ParenExpr {
2041 fn can_cast(kind: SyntaxKind) -> bool {
2047 fn cast(syntax: SyntaxNode) -> Option<Self> {
2048 if Self::can_cast(syntax.kind()) {
2049 Some(Self { syntax })
2054 fn syntax(&self) -> &SyntaxNode {
2059 pub fn expr(&self) -> Option<Expr> {
2060 AstChildren::new(&self.syntax).next()
2063 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2064 pub struct ParenType {
2065 pub(crate) syntax: SyntaxNode,
2067 impl AstNode for ParenType {
2068 fn can_cast(kind: SyntaxKind) -> bool {
2074 fn cast(syntax: SyntaxNode) -> Option<Self> {
2075 if Self::can_cast(syntax.kind()) {
2076 Some(Self { syntax })
2081 fn syntax(&self) -> &SyntaxNode {
2086 pub fn type_ref(&self) -> Option<TypeRef> {
2087 AstChildren::new(&self.syntax).next()
2090 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2095 PlaceholderPat(PlaceholderPat),
2097 RecordPat(RecordPat),
2098 TupleStructPat(TupleStructPat),
2102 LiteralPat(LiteralPat),
2104 impl From<RefPat> for Pat {
2105 fn from(node: RefPat) -> Pat {
2109 impl From<BoxPat> for Pat {
2110 fn from(node: BoxPat) -> Pat {
2114 impl From<BindPat> for Pat {
2115 fn from(node: BindPat) -> Pat {
2119 impl From<PlaceholderPat> for Pat {
2120 fn from(node: PlaceholderPat) -> Pat {
2121 Pat::PlaceholderPat(node)
2124 impl From<PathPat> for Pat {
2125 fn from(node: PathPat) -> Pat {
2129 impl From<RecordPat> for Pat {
2130 fn from(node: RecordPat) -> Pat {
2131 Pat::RecordPat(node)
2134 impl From<TupleStructPat> for Pat {
2135 fn from(node: TupleStructPat) -> Pat {
2136 Pat::TupleStructPat(node)
2139 impl From<TuplePat> for Pat {
2140 fn from(node: TuplePat) -> Pat {
2144 impl From<SlicePat> for Pat {
2145 fn from(node: SlicePat) -> Pat {
2149 impl From<RangePat> for Pat {
2150 fn from(node: RangePat) -> Pat {
2154 impl From<LiteralPat> for Pat {
2155 fn from(node: LiteralPat) -> Pat {
2156 Pat::LiteralPat(node)
2159 impl AstNode for Pat {
2160 fn can_cast(kind: SyntaxKind) -> bool {
2162 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT
2163 | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2167 fn cast(syntax: SyntaxNode) -> Option<Self> {
2168 let res = match syntax.kind() {
2169 REF_PAT => Pat::RefPat(RefPat { syntax }),
2170 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2171 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2172 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2173 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2174 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2175 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2176 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2177 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2178 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2179 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2184 fn syntax(&self) -> &SyntaxNode {
2186 Pat::RefPat(it) => &it.syntax,
2187 Pat::BoxPat(it) => &it.syntax,
2188 Pat::BindPat(it) => &it.syntax,
2189 Pat::PlaceholderPat(it) => &it.syntax,
2190 Pat::PathPat(it) => &it.syntax,
2191 Pat::RecordPat(it) => &it.syntax,
2192 Pat::TupleStructPat(it) => &it.syntax,
2193 Pat::TuplePat(it) => &it.syntax,
2194 Pat::SlicePat(it) => &it.syntax,
2195 Pat::RangePat(it) => &it.syntax,
2196 Pat::LiteralPat(it) => &it.syntax,
2201 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2203 pub(crate) syntax: SyntaxNode,
2205 impl AstNode for Path {
2206 fn can_cast(kind: SyntaxKind) -> bool {
2212 fn cast(syntax: SyntaxNode) -> Option<Self> {
2213 if Self::can_cast(syntax.kind()) {
2214 Some(Self { syntax })
2219 fn syntax(&self) -> &SyntaxNode {
2224 pub fn segment(&self) -> Option<PathSegment> {
2225 AstChildren::new(&self.syntax).next()
2227 pub fn qualifier(&self) -> Option<Path> {
2228 AstChildren::new(&self.syntax).next()
2231 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2232 pub struct PathExpr {
2233 pub(crate) syntax: SyntaxNode,
2235 impl AstNode for PathExpr {
2236 fn can_cast(kind: SyntaxKind) -> bool {
2242 fn cast(syntax: SyntaxNode) -> Option<Self> {
2243 if Self::can_cast(syntax.kind()) {
2244 Some(Self { syntax })
2249 fn syntax(&self) -> &SyntaxNode {
2254 pub fn path(&self) -> Option<Path> {
2255 AstChildren::new(&self.syntax).next()
2258 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2259 pub struct PathPat {
2260 pub(crate) syntax: SyntaxNode,
2262 impl AstNode for PathPat {
2263 fn can_cast(kind: SyntaxKind) -> bool {
2269 fn cast(syntax: SyntaxNode) -> Option<Self> {
2270 if Self::can_cast(syntax.kind()) {
2271 Some(Self { syntax })
2276 fn syntax(&self) -> &SyntaxNode {
2281 pub fn path(&self) -> Option<Path> {
2282 AstChildren::new(&self.syntax).next()
2285 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2286 pub struct PathSegment {
2287 pub(crate) syntax: SyntaxNode,
2289 impl AstNode for PathSegment {
2290 fn can_cast(kind: SyntaxKind) -> bool {
2292 PATH_SEGMENT => true,
2296 fn cast(syntax: SyntaxNode) -> Option<Self> {
2297 if Self::can_cast(syntax.kind()) {
2298 Some(Self { syntax })
2303 fn syntax(&self) -> &SyntaxNode {
2308 pub fn name_ref(&self) -> Option<NameRef> {
2309 AstChildren::new(&self.syntax).next()
2311 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2312 AstChildren::new(&self.syntax).next()
2315 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2316 pub struct PathType {
2317 pub(crate) syntax: SyntaxNode,
2319 impl AstNode for PathType {
2320 fn can_cast(kind: SyntaxKind) -> bool {
2326 fn cast(syntax: SyntaxNode) -> Option<Self> {
2327 if Self::can_cast(syntax.kind()) {
2328 Some(Self { syntax })
2333 fn syntax(&self) -> &SyntaxNode {
2338 pub fn path(&self) -> Option<Path> {
2339 AstChildren::new(&self.syntax).next()
2342 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2343 pub struct PlaceholderPat {
2344 pub(crate) syntax: SyntaxNode,
2346 impl AstNode for PlaceholderPat {
2347 fn can_cast(kind: SyntaxKind) -> bool {
2349 PLACEHOLDER_PAT => true,
2353 fn cast(syntax: SyntaxNode) -> Option<Self> {
2354 if Self::can_cast(syntax.kind()) {
2355 Some(Self { syntax })
2360 fn syntax(&self) -> &SyntaxNode {
2364 impl PlaceholderPat {}
2365 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2366 pub struct PlaceholderType {
2367 pub(crate) syntax: SyntaxNode,
2369 impl AstNode for PlaceholderType {
2370 fn can_cast(kind: SyntaxKind) -> bool {
2372 PLACEHOLDER_TYPE => true,
2376 fn cast(syntax: SyntaxNode) -> Option<Self> {
2377 if Self::can_cast(syntax.kind()) {
2378 Some(Self { syntax })
2383 fn syntax(&self) -> &SyntaxNode {
2387 impl PlaceholderType {}
2388 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2389 pub struct PointerType {
2390 pub(crate) syntax: SyntaxNode,
2392 impl AstNode for PointerType {
2393 fn can_cast(kind: SyntaxKind) -> bool {
2395 POINTER_TYPE => true,
2399 fn cast(syntax: SyntaxNode) -> Option<Self> {
2400 if Self::can_cast(syntax.kind()) {
2401 Some(Self { syntax })
2406 fn syntax(&self) -> &SyntaxNode {
2411 pub fn type_ref(&self) -> Option<TypeRef> {
2412 AstChildren::new(&self.syntax).next()
2415 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2416 pub struct PrefixExpr {
2417 pub(crate) syntax: SyntaxNode,
2419 impl AstNode for PrefixExpr {
2420 fn can_cast(kind: SyntaxKind) -> bool {
2422 PREFIX_EXPR => true,
2426 fn cast(syntax: SyntaxNode) -> Option<Self> {
2427 if Self::can_cast(syntax.kind()) {
2428 Some(Self { syntax })
2433 fn syntax(&self) -> &SyntaxNode {
2438 pub fn expr(&self) -> Option<Expr> {
2439 AstChildren::new(&self.syntax).next()
2442 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2443 pub struct RangeExpr {
2444 pub(crate) syntax: SyntaxNode,
2446 impl AstNode for RangeExpr {
2447 fn can_cast(kind: SyntaxKind) -> bool {
2453 fn cast(syntax: SyntaxNode) -> Option<Self> {
2454 if Self::can_cast(syntax.kind()) {
2455 Some(Self { syntax })
2460 fn syntax(&self) -> &SyntaxNode {
2465 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2466 pub struct RangePat {
2467 pub(crate) syntax: SyntaxNode,
2469 impl AstNode for RangePat {
2470 fn can_cast(kind: SyntaxKind) -> bool {
2476 fn cast(syntax: SyntaxNode) -> Option<Self> {
2477 if Self::can_cast(syntax.kind()) {
2478 Some(Self { syntax })
2483 fn syntax(&self) -> &SyntaxNode {
2488 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2489 pub struct RecordField {
2490 pub(crate) syntax: SyntaxNode,
2492 impl AstNode for RecordField {
2493 fn can_cast(kind: SyntaxKind) -> bool {
2495 RECORD_FIELD => true,
2499 fn cast(syntax: SyntaxNode) -> Option<Self> {
2500 if Self::can_cast(syntax.kind()) {
2501 Some(Self { syntax })
2506 fn syntax(&self) -> &SyntaxNode {
2511 pub fn name_ref(&self) -> Option<NameRef> {
2512 AstChildren::new(&self.syntax).next()
2514 pub fn expr(&self) -> Option<Expr> {
2515 AstChildren::new(&self.syntax).next()
2518 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2519 pub struct RecordFieldDef {
2520 pub(crate) syntax: SyntaxNode,
2522 impl AstNode for RecordFieldDef {
2523 fn can_cast(kind: SyntaxKind) -> bool {
2525 RECORD_FIELD_DEF => true,
2529 fn cast(syntax: SyntaxNode) -> Option<Self> {
2530 if Self::can_cast(syntax.kind()) {
2531 Some(Self { syntax })
2536 fn syntax(&self) -> &SyntaxNode {
2540 impl ast::VisibilityOwner for RecordFieldDef {}
2541 impl ast::NameOwner for RecordFieldDef {}
2542 impl ast::AttrsOwner for RecordFieldDef {}
2543 impl ast::DocCommentsOwner for RecordFieldDef {}
2544 impl ast::TypeAscriptionOwner for RecordFieldDef {}
2545 impl RecordFieldDef {}
2546 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2547 pub struct RecordFieldDefList {
2548 pub(crate) syntax: SyntaxNode,
2550 impl AstNode for RecordFieldDefList {
2551 fn can_cast(kind: SyntaxKind) -> bool {
2553 RECORD_FIELD_DEF_LIST => true,
2557 fn cast(syntax: SyntaxNode) -> Option<Self> {
2558 if Self::can_cast(syntax.kind()) {
2559 Some(Self { syntax })
2564 fn syntax(&self) -> &SyntaxNode {
2568 impl RecordFieldDefList {
2569 pub fn fields(&self) -> AstChildren<RecordFieldDef> {
2570 AstChildren::new(&self.syntax)
2573 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2574 pub struct RecordFieldList {
2575 pub(crate) syntax: SyntaxNode,
2577 impl AstNode for RecordFieldList {
2578 fn can_cast(kind: SyntaxKind) -> bool {
2580 RECORD_FIELD_LIST => true,
2584 fn cast(syntax: SyntaxNode) -> Option<Self> {
2585 if Self::can_cast(syntax.kind()) {
2586 Some(Self { syntax })
2591 fn syntax(&self) -> &SyntaxNode {
2595 impl RecordFieldList {
2596 pub fn fields(&self) -> AstChildren<RecordField> {
2597 AstChildren::new(&self.syntax)
2599 pub fn spread(&self) -> Option<Expr> {
2600 AstChildren::new(&self.syntax).next()
2603 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2604 pub struct RecordFieldPat {
2605 pub(crate) syntax: SyntaxNode,
2607 impl AstNode for RecordFieldPat {
2608 fn can_cast(kind: SyntaxKind) -> bool {
2610 RECORD_FIELD_PAT => true,
2614 fn cast(syntax: SyntaxNode) -> Option<Self> {
2615 if Self::can_cast(syntax.kind()) {
2616 Some(Self { syntax })
2621 fn syntax(&self) -> &SyntaxNode {
2625 impl ast::NameOwner for RecordFieldPat {}
2626 impl RecordFieldPat {
2627 pub fn pat(&self) -> Option<Pat> {
2628 AstChildren::new(&self.syntax).next()
2631 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2632 pub struct RecordFieldPatList {
2633 pub(crate) syntax: SyntaxNode,
2635 impl AstNode for RecordFieldPatList {
2636 fn can_cast(kind: SyntaxKind) -> bool {
2638 RECORD_FIELD_PAT_LIST => true,
2642 fn cast(syntax: SyntaxNode) -> Option<Self> {
2643 if Self::can_cast(syntax.kind()) {
2644 Some(Self { syntax })
2649 fn syntax(&self) -> &SyntaxNode {
2653 impl RecordFieldPatList {
2654 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
2655 AstChildren::new(&self.syntax)
2657 pub fn bind_pats(&self) -> AstChildren<BindPat> {
2658 AstChildren::new(&self.syntax)
2661 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2662 pub struct RecordLit {
2663 pub(crate) syntax: SyntaxNode,
2665 impl AstNode for RecordLit {
2666 fn can_cast(kind: SyntaxKind) -> bool {
2672 fn cast(syntax: SyntaxNode) -> Option<Self> {
2673 if Self::can_cast(syntax.kind()) {
2674 Some(Self { syntax })
2679 fn syntax(&self) -> &SyntaxNode {
2684 pub fn path(&self) -> Option<Path> {
2685 AstChildren::new(&self.syntax).next()
2687 pub fn record_field_list(&self) -> Option<RecordFieldList> {
2688 AstChildren::new(&self.syntax).next()
2691 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2692 pub struct RecordPat {
2693 pub(crate) syntax: SyntaxNode,
2695 impl AstNode for RecordPat {
2696 fn can_cast(kind: SyntaxKind) -> bool {
2702 fn cast(syntax: SyntaxNode) -> Option<Self> {
2703 if Self::can_cast(syntax.kind()) {
2704 Some(Self { syntax })
2709 fn syntax(&self) -> &SyntaxNode {
2714 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
2715 AstChildren::new(&self.syntax).next()
2717 pub fn path(&self) -> Option<Path> {
2718 AstChildren::new(&self.syntax).next()
2721 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2722 pub struct RefExpr {
2723 pub(crate) syntax: SyntaxNode,
2725 impl AstNode for RefExpr {
2726 fn can_cast(kind: SyntaxKind) -> bool {
2732 fn cast(syntax: SyntaxNode) -> Option<Self> {
2733 if Self::can_cast(syntax.kind()) {
2734 Some(Self { syntax })
2739 fn syntax(&self) -> &SyntaxNode {
2744 pub fn expr(&self) -> Option<Expr> {
2745 AstChildren::new(&self.syntax).next()
2748 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2750 pub(crate) syntax: SyntaxNode,
2752 impl AstNode for RefPat {
2753 fn can_cast(kind: SyntaxKind) -> bool {
2759 fn cast(syntax: SyntaxNode) -> Option<Self> {
2760 if Self::can_cast(syntax.kind()) {
2761 Some(Self { syntax })
2766 fn syntax(&self) -> &SyntaxNode {
2771 pub fn pat(&self) -> Option<Pat> {
2772 AstChildren::new(&self.syntax).next()
2775 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2776 pub struct ReferenceType {
2777 pub(crate) syntax: SyntaxNode,
2779 impl AstNode for ReferenceType {
2780 fn can_cast(kind: SyntaxKind) -> bool {
2782 REFERENCE_TYPE => true,
2786 fn cast(syntax: SyntaxNode) -> Option<Self> {
2787 if Self::can_cast(syntax.kind()) {
2788 Some(Self { syntax })
2793 fn syntax(&self) -> &SyntaxNode {
2797 impl ReferenceType {
2798 pub fn type_ref(&self) -> Option<TypeRef> {
2799 AstChildren::new(&self.syntax).next()
2802 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2803 pub struct RetType {
2804 pub(crate) syntax: SyntaxNode,
2806 impl AstNode for RetType {
2807 fn can_cast(kind: SyntaxKind) -> bool {
2813 fn cast(syntax: SyntaxNode) -> Option<Self> {
2814 if Self::can_cast(syntax.kind()) {
2815 Some(Self { syntax })
2820 fn syntax(&self) -> &SyntaxNode {
2825 pub fn type_ref(&self) -> Option<TypeRef> {
2826 AstChildren::new(&self.syntax).next()
2829 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2830 pub struct ReturnExpr {
2831 pub(crate) syntax: SyntaxNode,
2833 impl AstNode for ReturnExpr {
2834 fn can_cast(kind: SyntaxKind) -> bool {
2836 RETURN_EXPR => true,
2840 fn cast(syntax: SyntaxNode) -> Option<Self> {
2841 if Self::can_cast(syntax.kind()) {
2842 Some(Self { syntax })
2847 fn syntax(&self) -> &SyntaxNode {
2852 pub fn expr(&self) -> Option<Expr> {
2853 AstChildren::new(&self.syntax).next()
2856 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2857 pub struct SelfParam {
2858 pub(crate) syntax: SyntaxNode,
2860 impl AstNode for SelfParam {
2861 fn can_cast(kind: SyntaxKind) -> bool {
2867 fn cast(syntax: SyntaxNode) -> Option<Self> {
2868 if Self::can_cast(syntax.kind()) {
2869 Some(Self { syntax })
2874 fn syntax(&self) -> &SyntaxNode {
2878 impl ast::TypeAscriptionOwner for SelfParam {}
2879 impl ast::AttrsOwner for SelfParam {}
2881 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2882 pub struct SlicePat {
2883 pub(crate) syntax: SyntaxNode,
2885 impl AstNode for SlicePat {
2886 fn can_cast(kind: SyntaxKind) -> bool {
2892 fn cast(syntax: SyntaxNode) -> Option<Self> {
2893 if Self::can_cast(syntax.kind()) {
2894 Some(Self { syntax })
2899 fn syntax(&self) -> &SyntaxNode {
2904 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2905 pub struct SliceType {
2906 pub(crate) syntax: SyntaxNode,
2908 impl AstNode for SliceType {
2909 fn can_cast(kind: SyntaxKind) -> bool {
2915 fn cast(syntax: SyntaxNode) -> Option<Self> {
2916 if Self::can_cast(syntax.kind()) {
2917 Some(Self { syntax })
2922 fn syntax(&self) -> &SyntaxNode {
2927 pub fn type_ref(&self) -> Option<TypeRef> {
2928 AstChildren::new(&self.syntax).next()
2931 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2932 pub struct SourceFile {
2933 pub(crate) syntax: SyntaxNode,
2935 impl AstNode for SourceFile {
2936 fn can_cast(kind: SyntaxKind) -> bool {
2938 SOURCE_FILE => true,
2942 fn cast(syntax: SyntaxNode) -> Option<Self> {
2943 if Self::can_cast(syntax.kind()) {
2944 Some(Self { syntax })
2949 fn syntax(&self) -> &SyntaxNode {
2953 impl ast::ModuleItemOwner for SourceFile {}
2954 impl ast::FnDefOwner for SourceFile {}
2956 pub fn modules(&self) -> AstChildren<Module> {
2957 AstChildren::new(&self.syntax)
2960 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2961 pub struct StaticDef {
2962 pub(crate) syntax: SyntaxNode,
2964 impl AstNode for StaticDef {
2965 fn can_cast(kind: SyntaxKind) -> bool {
2971 fn cast(syntax: SyntaxNode) -> Option<Self> {
2972 if Self::can_cast(syntax.kind()) {
2973 Some(Self { syntax })
2978 fn syntax(&self) -> &SyntaxNode {
2982 impl ast::VisibilityOwner for StaticDef {}
2983 impl ast::NameOwner for StaticDef {}
2984 impl ast::TypeParamsOwner for StaticDef {}
2985 impl ast::AttrsOwner for StaticDef {}
2986 impl ast::DocCommentsOwner for StaticDef {}
2987 impl ast::TypeAscriptionOwner for StaticDef {}
2989 pub fn body(&self) -> Option<Expr> {
2990 AstChildren::new(&self.syntax).next()
2993 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2998 impl From<ExprStmt> for Stmt {
2999 fn from(node: ExprStmt) -> Stmt {
3000 Stmt::ExprStmt(node)
3003 impl From<LetStmt> for Stmt {
3004 fn from(node: LetStmt) -> Stmt {
3008 impl AstNode for Stmt {
3009 fn can_cast(kind: SyntaxKind) -> bool {
3011 EXPR_STMT | LET_STMT => true,
3015 fn cast(syntax: SyntaxNode) -> Option<Self> {
3016 let res = match syntax.kind() {
3017 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
3018 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
3023 fn syntax(&self) -> &SyntaxNode {
3025 Stmt::ExprStmt(it) => &it.syntax,
3026 Stmt::LetStmt(it) => &it.syntax,
3031 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3032 pub struct StructDef {
3033 pub(crate) syntax: SyntaxNode,
3035 impl AstNode for StructDef {
3036 fn can_cast(kind: SyntaxKind) -> bool {
3042 fn cast(syntax: SyntaxNode) -> Option<Self> {
3043 if Self::can_cast(syntax.kind()) {
3044 Some(Self { syntax })
3049 fn syntax(&self) -> &SyntaxNode {
3053 impl ast::VisibilityOwner for StructDef {}
3054 impl ast::NameOwner for StructDef {}
3055 impl ast::TypeParamsOwner for StructDef {}
3056 impl ast::AttrsOwner for StructDef {}
3057 impl ast::DocCommentsOwner for StructDef {}
3059 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3060 pub struct TokenTree {
3061 pub(crate) syntax: SyntaxNode,
3063 impl AstNode for TokenTree {
3064 fn can_cast(kind: SyntaxKind) -> bool {
3070 fn cast(syntax: SyntaxNode) -> Option<Self> {
3071 if Self::can_cast(syntax.kind()) {
3072 Some(Self { syntax })
3077 fn syntax(&self) -> &SyntaxNode {
3082 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3083 pub struct TraitDef {
3084 pub(crate) syntax: SyntaxNode,
3086 impl AstNode for TraitDef {
3087 fn can_cast(kind: SyntaxKind) -> bool {
3093 fn cast(syntax: SyntaxNode) -> Option<Self> {
3094 if Self::can_cast(syntax.kind()) {
3095 Some(Self { syntax })
3100 fn syntax(&self) -> &SyntaxNode {
3104 impl ast::VisibilityOwner for TraitDef {}
3105 impl ast::NameOwner for TraitDef {}
3106 impl ast::AttrsOwner for TraitDef {}
3107 impl ast::DocCommentsOwner for TraitDef {}
3108 impl ast::TypeParamsOwner for TraitDef {}
3109 impl ast::TypeBoundsOwner for TraitDef {}
3111 pub fn item_list(&self) -> Option<ItemList> {
3112 AstChildren::new(&self.syntax).next()
3115 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3116 pub struct TryBlockExpr {
3117 pub(crate) syntax: SyntaxNode,
3119 impl AstNode for TryBlockExpr {
3120 fn can_cast(kind: SyntaxKind) -> bool {
3122 TRY_BLOCK_EXPR => true,
3126 fn cast(syntax: SyntaxNode) -> Option<Self> {
3127 if Self::can_cast(syntax.kind()) {
3128 Some(Self { syntax })
3133 fn syntax(&self) -> &SyntaxNode {
3138 pub fn block(&self) -> Option<Block> {
3139 AstChildren::new(&self.syntax).next()
3142 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3143 pub struct TryExpr {
3144 pub(crate) syntax: SyntaxNode,
3146 impl AstNode for TryExpr {
3147 fn can_cast(kind: SyntaxKind) -> bool {
3153 fn cast(syntax: SyntaxNode) -> Option<Self> {
3154 if Self::can_cast(syntax.kind()) {
3155 Some(Self { syntax })
3160 fn syntax(&self) -> &SyntaxNode {
3165 pub fn expr(&self) -> Option<Expr> {
3166 AstChildren::new(&self.syntax).next()
3169 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3170 pub struct TupleExpr {
3171 pub(crate) syntax: SyntaxNode,
3173 impl AstNode for TupleExpr {
3174 fn can_cast(kind: SyntaxKind) -> bool {
3180 fn cast(syntax: SyntaxNode) -> Option<Self> {
3181 if Self::can_cast(syntax.kind()) {
3182 Some(Self { syntax })
3187 fn syntax(&self) -> &SyntaxNode {
3192 pub fn exprs(&self) -> AstChildren<Expr> {
3193 AstChildren::new(&self.syntax)
3196 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3197 pub struct TupleFieldDef {
3198 pub(crate) syntax: SyntaxNode,
3200 impl AstNode for TupleFieldDef {
3201 fn can_cast(kind: SyntaxKind) -> bool {
3203 TUPLE_FIELD_DEF => true,
3207 fn cast(syntax: SyntaxNode) -> Option<Self> {
3208 if Self::can_cast(syntax.kind()) {
3209 Some(Self { syntax })
3214 fn syntax(&self) -> &SyntaxNode {
3218 impl ast::VisibilityOwner for TupleFieldDef {}
3219 impl ast::AttrsOwner for TupleFieldDef {}
3220 impl TupleFieldDef {
3221 pub fn type_ref(&self) -> Option<TypeRef> {
3222 AstChildren::new(&self.syntax).next()
3225 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3226 pub struct TupleFieldDefList {
3227 pub(crate) syntax: SyntaxNode,
3229 impl AstNode for TupleFieldDefList {
3230 fn can_cast(kind: SyntaxKind) -> bool {
3232 TUPLE_FIELD_DEF_LIST => true,
3236 fn cast(syntax: SyntaxNode) -> Option<Self> {
3237 if Self::can_cast(syntax.kind()) {
3238 Some(Self { syntax })
3243 fn syntax(&self) -> &SyntaxNode {
3247 impl TupleFieldDefList {
3248 pub fn fields(&self) -> AstChildren<TupleFieldDef> {
3249 AstChildren::new(&self.syntax)
3252 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3253 pub struct TuplePat {
3254 pub(crate) syntax: SyntaxNode,
3256 impl AstNode for TuplePat {
3257 fn can_cast(kind: SyntaxKind) -> bool {
3263 fn cast(syntax: SyntaxNode) -> Option<Self> {
3264 if Self::can_cast(syntax.kind()) {
3265 Some(Self { syntax })
3270 fn syntax(&self) -> &SyntaxNode {
3275 pub fn args(&self) -> AstChildren<Pat> {
3276 AstChildren::new(&self.syntax)
3279 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3280 pub struct TupleStructPat {
3281 pub(crate) syntax: SyntaxNode,
3283 impl AstNode for TupleStructPat {
3284 fn can_cast(kind: SyntaxKind) -> bool {
3286 TUPLE_STRUCT_PAT => true,
3290 fn cast(syntax: SyntaxNode) -> Option<Self> {
3291 if Self::can_cast(syntax.kind()) {
3292 Some(Self { syntax })
3297 fn syntax(&self) -> &SyntaxNode {
3301 impl TupleStructPat {
3302 pub fn args(&self) -> AstChildren<Pat> {
3303 AstChildren::new(&self.syntax)
3305 pub fn path(&self) -> Option<Path> {
3306 AstChildren::new(&self.syntax).next()
3309 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3310 pub struct TupleType {
3311 pub(crate) syntax: SyntaxNode,
3313 impl AstNode for TupleType {
3314 fn can_cast(kind: SyntaxKind) -> bool {
3320 fn cast(syntax: SyntaxNode) -> Option<Self> {
3321 if Self::can_cast(syntax.kind()) {
3322 Some(Self { syntax })
3327 fn syntax(&self) -> &SyntaxNode {
3332 pub fn fields(&self) -> AstChildren<TypeRef> {
3333 AstChildren::new(&self.syntax)
3336 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3337 pub struct TypeAliasDef {
3338 pub(crate) syntax: SyntaxNode,
3340 impl AstNode for TypeAliasDef {
3341 fn can_cast(kind: SyntaxKind) -> bool {
3343 TYPE_ALIAS_DEF => true,
3347 fn cast(syntax: SyntaxNode) -> Option<Self> {
3348 if Self::can_cast(syntax.kind()) {
3349 Some(Self { syntax })
3354 fn syntax(&self) -> &SyntaxNode {
3358 impl ast::VisibilityOwner for TypeAliasDef {}
3359 impl ast::NameOwner for TypeAliasDef {}
3360 impl ast::TypeParamsOwner for TypeAliasDef {}
3361 impl ast::AttrsOwner for TypeAliasDef {}
3362 impl ast::DocCommentsOwner for TypeAliasDef {}
3363 impl ast::TypeBoundsOwner for TypeAliasDef {}
3365 pub fn type_ref(&self) -> Option<TypeRef> {
3366 AstChildren::new(&self.syntax).next()
3369 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3370 pub struct TypeArg {
3371 pub(crate) syntax: SyntaxNode,
3373 impl AstNode for TypeArg {
3374 fn can_cast(kind: SyntaxKind) -> bool {
3380 fn cast(syntax: SyntaxNode) -> Option<Self> {
3381 if Self::can_cast(syntax.kind()) {
3382 Some(Self { syntax })
3387 fn syntax(&self) -> &SyntaxNode {
3392 pub fn type_ref(&self) -> Option<TypeRef> {
3393 AstChildren::new(&self.syntax).next()
3396 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3397 pub struct TypeArgList {
3398 pub(crate) syntax: SyntaxNode,
3400 impl AstNode for TypeArgList {
3401 fn can_cast(kind: SyntaxKind) -> bool {
3403 TYPE_ARG_LIST => true,
3407 fn cast(syntax: SyntaxNode) -> Option<Self> {
3408 if Self::can_cast(syntax.kind()) {
3409 Some(Self { syntax })
3414 fn syntax(&self) -> &SyntaxNode {
3419 pub fn type_args(&self) -> AstChildren<TypeArg> {
3420 AstChildren::new(&self.syntax)
3422 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3423 AstChildren::new(&self.syntax)
3425 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3426 AstChildren::new(&self.syntax)
3429 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3430 pub struct TypeBound {
3431 pub(crate) syntax: SyntaxNode,
3433 impl AstNode for TypeBound {
3434 fn can_cast(kind: SyntaxKind) -> bool {
3440 fn cast(syntax: SyntaxNode) -> Option<Self> {
3441 if Self::can_cast(syntax.kind()) {
3442 Some(Self { syntax })
3447 fn syntax(&self) -> &SyntaxNode {
3452 pub fn type_ref(&self) -> Option<TypeRef> {
3453 AstChildren::new(&self.syntax).next()
3456 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3457 pub struct TypeBoundList {
3458 pub(crate) syntax: SyntaxNode,
3460 impl AstNode for TypeBoundList {
3461 fn can_cast(kind: SyntaxKind) -> bool {
3463 TYPE_BOUND_LIST => true,
3467 fn cast(syntax: SyntaxNode) -> Option<Self> {
3468 if Self::can_cast(syntax.kind()) {
3469 Some(Self { syntax })
3474 fn syntax(&self) -> &SyntaxNode {
3478 impl TypeBoundList {
3479 pub fn bounds(&self) -> AstChildren<TypeBound> {
3480 AstChildren::new(&self.syntax)
3483 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3484 pub struct TypeParam {
3485 pub(crate) syntax: SyntaxNode,
3487 impl AstNode for TypeParam {
3488 fn can_cast(kind: SyntaxKind) -> bool {
3494 fn cast(syntax: SyntaxNode) -> Option<Self> {
3495 if Self::can_cast(syntax.kind()) {
3496 Some(Self { syntax })
3501 fn syntax(&self) -> &SyntaxNode {
3505 impl ast::NameOwner for TypeParam {}
3506 impl ast::AttrsOwner for TypeParam {}
3507 impl ast::TypeBoundsOwner for TypeParam {}
3508 impl ast::DefaultTypeParamOwner for TypeParam {}
3510 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3511 pub struct TypeParamList {
3512 pub(crate) syntax: SyntaxNode,
3514 impl AstNode for TypeParamList {
3515 fn can_cast(kind: SyntaxKind) -> bool {
3517 TYPE_PARAM_LIST => true,
3521 fn cast(syntax: SyntaxNode) -> Option<Self> {
3522 if Self::can_cast(syntax.kind()) {
3523 Some(Self { syntax })
3528 fn syntax(&self) -> &SyntaxNode {
3532 impl TypeParamList {
3533 pub fn type_params(&self) -> AstChildren<TypeParam> {
3534 AstChildren::new(&self.syntax)
3536 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3537 AstChildren::new(&self.syntax)
3540 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3542 ParenType(ParenType),
3543 TupleType(TupleType),
3544 NeverType(NeverType),
3546 PointerType(PointerType),
3547 ArrayType(ArrayType),
3548 SliceType(SliceType),
3549 ReferenceType(ReferenceType),
3550 PlaceholderType(PlaceholderType),
3551 FnPointerType(FnPointerType),
3553 ImplTraitType(ImplTraitType),
3554 DynTraitType(DynTraitType),
3556 impl From<ParenType> for TypeRef {
3557 fn from(node: ParenType) -> TypeRef {
3558 TypeRef::ParenType(node)
3561 impl From<TupleType> for TypeRef {
3562 fn from(node: TupleType) -> TypeRef {
3563 TypeRef::TupleType(node)
3566 impl From<NeverType> for TypeRef {
3567 fn from(node: NeverType) -> TypeRef {
3568 TypeRef::NeverType(node)
3571 impl From<PathType> for TypeRef {
3572 fn from(node: PathType) -> TypeRef {
3573 TypeRef::PathType(node)
3576 impl From<PointerType> for TypeRef {
3577 fn from(node: PointerType) -> TypeRef {
3578 TypeRef::PointerType(node)
3581 impl From<ArrayType> for TypeRef {
3582 fn from(node: ArrayType) -> TypeRef {
3583 TypeRef::ArrayType(node)
3586 impl From<SliceType> for TypeRef {
3587 fn from(node: SliceType) -> TypeRef {
3588 TypeRef::SliceType(node)
3591 impl From<ReferenceType> for TypeRef {
3592 fn from(node: ReferenceType) -> TypeRef {
3593 TypeRef::ReferenceType(node)
3596 impl From<PlaceholderType> for TypeRef {
3597 fn from(node: PlaceholderType) -> TypeRef {
3598 TypeRef::PlaceholderType(node)
3601 impl From<FnPointerType> for TypeRef {
3602 fn from(node: FnPointerType) -> TypeRef {
3603 TypeRef::FnPointerType(node)
3606 impl From<ForType> for TypeRef {
3607 fn from(node: ForType) -> TypeRef {
3608 TypeRef::ForType(node)
3611 impl From<ImplTraitType> for TypeRef {
3612 fn from(node: ImplTraitType) -> TypeRef {
3613 TypeRef::ImplTraitType(node)
3616 impl From<DynTraitType> for TypeRef {
3617 fn from(node: DynTraitType) -> TypeRef {
3618 TypeRef::DynTraitType(node)
3621 impl AstNode for TypeRef {
3622 fn can_cast(kind: SyntaxKind) -> bool {
3624 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3625 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3626 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3630 fn cast(syntax: SyntaxNode) -> Option<Self> {
3631 let res = match syntax.kind() {
3632 PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
3633 TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
3634 NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
3635 PATH_TYPE => TypeRef::PathType(PathType { syntax }),
3636 POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
3637 ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
3638 SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
3639 REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
3640 PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
3641 FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
3642 FOR_TYPE => TypeRef::ForType(ForType { syntax }),
3643 IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
3644 DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
3649 fn syntax(&self) -> &SyntaxNode {
3651 TypeRef::ParenType(it) => &it.syntax,
3652 TypeRef::TupleType(it) => &it.syntax,
3653 TypeRef::NeverType(it) => &it.syntax,
3654 TypeRef::PathType(it) => &it.syntax,
3655 TypeRef::PointerType(it) => &it.syntax,
3656 TypeRef::ArrayType(it) => &it.syntax,
3657 TypeRef::SliceType(it) => &it.syntax,
3658 TypeRef::ReferenceType(it) => &it.syntax,
3659 TypeRef::PlaceholderType(it) => &it.syntax,
3660 TypeRef::FnPointerType(it) => &it.syntax,
3661 TypeRef::ForType(it) => &it.syntax,
3662 TypeRef::ImplTraitType(it) => &it.syntax,
3663 TypeRef::DynTraitType(it) => &it.syntax,
3668 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3669 pub struct UseItem {
3670 pub(crate) syntax: SyntaxNode,
3672 impl AstNode for UseItem {
3673 fn can_cast(kind: SyntaxKind) -> bool {
3679 fn cast(syntax: SyntaxNode) -> Option<Self> {
3680 if Self::can_cast(syntax.kind()) {
3681 Some(Self { syntax })
3686 fn syntax(&self) -> &SyntaxNode {
3690 impl ast::AttrsOwner for UseItem {}
3692 pub fn use_tree(&self) -> Option<UseTree> {
3693 AstChildren::new(&self.syntax).next()
3696 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3697 pub struct UseTree {
3698 pub(crate) syntax: SyntaxNode,
3700 impl AstNode for UseTree {
3701 fn can_cast(kind: SyntaxKind) -> bool {
3707 fn cast(syntax: SyntaxNode) -> Option<Self> {
3708 if Self::can_cast(syntax.kind()) {
3709 Some(Self { syntax })
3714 fn syntax(&self) -> &SyntaxNode {
3719 pub fn path(&self) -> Option<Path> {
3720 AstChildren::new(&self.syntax).next()
3722 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3723 AstChildren::new(&self.syntax).next()
3725 pub fn alias(&self) -> Option<Alias> {
3726 AstChildren::new(&self.syntax).next()
3729 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3730 pub struct UseTreeList {
3731 pub(crate) syntax: SyntaxNode,
3733 impl AstNode for UseTreeList {
3734 fn can_cast(kind: SyntaxKind) -> bool {
3736 USE_TREE_LIST => true,
3740 fn cast(syntax: SyntaxNode) -> Option<Self> {
3741 if Self::can_cast(syntax.kind()) {
3742 Some(Self { syntax })
3747 fn syntax(&self) -> &SyntaxNode {
3752 pub fn use_trees(&self) -> AstChildren<UseTree> {
3753 AstChildren::new(&self.syntax)
3756 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3757 pub struct Visibility {
3758 pub(crate) syntax: SyntaxNode,
3760 impl AstNode for Visibility {
3761 fn can_cast(kind: SyntaxKind) -> bool {
3767 fn cast(syntax: SyntaxNode) -> Option<Self> {
3768 if Self::can_cast(syntax.kind()) {
3769 Some(Self { syntax })
3774 fn syntax(&self) -> &SyntaxNode {
3779 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3780 pub struct WhereClause {
3781 pub(crate) syntax: SyntaxNode,
3783 impl AstNode for WhereClause {
3784 fn can_cast(kind: SyntaxKind) -> bool {
3786 WHERE_CLAUSE => true,
3790 fn cast(syntax: SyntaxNode) -> Option<Self> {
3791 if Self::can_cast(syntax.kind()) {
3792 Some(Self { syntax })
3797 fn syntax(&self) -> &SyntaxNode {
3802 pub fn predicates(&self) -> AstChildren<WherePred> {
3803 AstChildren::new(&self.syntax)
3806 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3807 pub struct WherePred {
3808 pub(crate) syntax: SyntaxNode,
3810 impl AstNode for WherePred {
3811 fn can_cast(kind: SyntaxKind) -> bool {
3817 fn cast(syntax: SyntaxNode) -> Option<Self> {
3818 if Self::can_cast(syntax.kind()) {
3819 Some(Self { syntax })
3824 fn syntax(&self) -> &SyntaxNode {
3828 impl ast::TypeBoundsOwner for WherePred {}
3830 pub fn type_ref(&self) -> Option<TypeRef> {
3831 AstChildren::new(&self.syntax).next()
3834 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3835 pub struct WhileExpr {
3836 pub(crate) syntax: SyntaxNode,
3838 impl AstNode for WhileExpr {
3839 fn can_cast(kind: SyntaxKind) -> bool {
3845 fn cast(syntax: SyntaxNode) -> Option<Self> {
3846 if Self::can_cast(syntax.kind()) {
3847 Some(Self { syntax })
3852 fn syntax(&self) -> &SyntaxNode {
3856 impl ast::LoopBodyOwner for WhileExpr {}
3858 pub fn condition(&self) -> Option<Condition> {
3859 AstChildren::new(&self.syntax).next()