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 path(&self) -> Option<Path> {
170 AstChildren::new(&self.syntax).next()
172 pub fn input(&self) -> Option<AttrInput> {
173 AstChildren::new(&self.syntax).next()
176 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
179 TokenTree(TokenTree),
181 impl From<Literal> for AttrInput {
182 fn from(node: Literal) -> AttrInput {
183 AttrInput::Literal(node)
186 impl From<TokenTree> for AttrInput {
187 fn from(node: TokenTree) -> AttrInput {
188 AttrInput::TokenTree(node)
191 impl AstNode for AttrInput {
192 fn can_cast(kind: SyntaxKind) -> bool {
194 LITERAL | TOKEN_TREE => true,
198 fn cast(syntax: SyntaxNode) -> Option<Self> {
199 let res = match syntax.kind() {
200 LITERAL => AttrInput::Literal(Literal { syntax }),
201 TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }),
206 fn syntax(&self) -> &SyntaxNode {
208 AttrInput::Literal(it) => &it.syntax,
209 AttrInput::TokenTree(it) => &it.syntax,
214 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
215 pub struct AwaitExpr {
216 pub(crate) syntax: SyntaxNode,
218 impl AstNode for AwaitExpr {
219 fn can_cast(kind: SyntaxKind) -> bool {
225 fn cast(syntax: SyntaxNode) -> Option<Self> {
226 if Self::can_cast(syntax.kind()) {
227 Some(Self { syntax })
232 fn syntax(&self) -> &SyntaxNode {
237 pub fn expr(&self) -> Option<Expr> {
238 AstChildren::new(&self.syntax).next()
241 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
243 pub(crate) syntax: SyntaxNode,
245 impl AstNode for BinExpr {
246 fn can_cast(kind: SyntaxKind) -> bool {
252 fn cast(syntax: SyntaxNode) -> Option<Self> {
253 if Self::can_cast(syntax.kind()) {
254 Some(Self { syntax })
259 fn syntax(&self) -> &SyntaxNode {
264 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
266 pub(crate) syntax: SyntaxNode,
268 impl AstNode for BindPat {
269 fn can_cast(kind: SyntaxKind) -> bool {
275 fn cast(syntax: SyntaxNode) -> Option<Self> {
276 if Self::can_cast(syntax.kind()) {
277 Some(Self { syntax })
282 fn syntax(&self) -> &SyntaxNode {
286 impl ast::NameOwner for BindPat {}
288 pub fn pat(&self) -> Option<Pat> {
289 AstChildren::new(&self.syntax).next()
292 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
294 pub(crate) syntax: SyntaxNode,
296 impl AstNode for Block {
297 fn can_cast(kind: SyntaxKind) -> bool {
303 fn cast(syntax: SyntaxNode) -> Option<Self> {
304 if Self::can_cast(syntax.kind()) {
305 Some(Self { syntax })
310 fn syntax(&self) -> &SyntaxNode {
314 impl ast::AttrsOwner for Block {}
316 pub fn statements(&self) -> AstChildren<Stmt> {
317 AstChildren::new(&self.syntax)
319 pub fn expr(&self) -> Option<Expr> {
320 AstChildren::new(&self.syntax).next()
323 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
324 pub struct BlockExpr {
325 pub(crate) syntax: SyntaxNode,
327 impl AstNode for BlockExpr {
328 fn can_cast(kind: SyntaxKind) -> bool {
334 fn cast(syntax: SyntaxNode) -> Option<Self> {
335 if Self::can_cast(syntax.kind()) {
336 Some(Self { syntax })
341 fn syntax(&self) -> &SyntaxNode {
346 pub fn block(&self) -> Option<Block> {
347 AstChildren::new(&self.syntax).next()
350 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
352 pub(crate) syntax: SyntaxNode,
354 impl AstNode for BoxExpr {
355 fn can_cast(kind: SyntaxKind) -> bool {
361 fn cast(syntax: SyntaxNode) -> Option<Self> {
362 if Self::can_cast(syntax.kind()) {
363 Some(Self { syntax })
368 fn syntax(&self) -> &SyntaxNode {
373 pub fn expr(&self) -> Option<Expr> {
374 AstChildren::new(&self.syntax).next()
377 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
379 pub(crate) syntax: SyntaxNode,
381 impl AstNode for BoxPat {
382 fn can_cast(kind: SyntaxKind) -> bool {
388 fn cast(syntax: SyntaxNode) -> Option<Self> {
389 if Self::can_cast(syntax.kind()) {
390 Some(Self { syntax })
395 fn syntax(&self) -> &SyntaxNode {
400 pub fn pat(&self) -> Option<Pat> {
401 AstChildren::new(&self.syntax).next()
404 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
405 pub struct BreakExpr {
406 pub(crate) syntax: SyntaxNode,
408 impl AstNode for BreakExpr {
409 fn can_cast(kind: SyntaxKind) -> bool {
415 fn cast(syntax: SyntaxNode) -> Option<Self> {
416 if Self::can_cast(syntax.kind()) {
417 Some(Self { syntax })
422 fn syntax(&self) -> &SyntaxNode {
427 pub fn expr(&self) -> Option<Expr> {
428 AstChildren::new(&self.syntax).next()
431 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
432 pub struct CallExpr {
433 pub(crate) syntax: SyntaxNode,
435 impl AstNode for CallExpr {
436 fn can_cast(kind: SyntaxKind) -> bool {
442 fn cast(syntax: SyntaxNode) -> Option<Self> {
443 if Self::can_cast(syntax.kind()) {
444 Some(Self { syntax })
449 fn syntax(&self) -> &SyntaxNode {
453 impl ast::ArgListOwner for CallExpr {}
455 pub fn expr(&self) -> Option<Expr> {
456 AstChildren::new(&self.syntax).next()
459 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
460 pub struct CastExpr {
461 pub(crate) syntax: SyntaxNode,
463 impl AstNode for CastExpr {
464 fn can_cast(kind: SyntaxKind) -> bool {
470 fn cast(syntax: SyntaxNode) -> Option<Self> {
471 if Self::can_cast(syntax.kind()) {
472 Some(Self { syntax })
477 fn syntax(&self) -> &SyntaxNode {
482 pub fn expr(&self) -> Option<Expr> {
483 AstChildren::new(&self.syntax).next()
485 pub fn type_ref(&self) -> Option<TypeRef> {
486 AstChildren::new(&self.syntax).next()
489 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
490 pub struct Condition {
491 pub(crate) syntax: SyntaxNode,
493 impl AstNode for Condition {
494 fn can_cast(kind: SyntaxKind) -> bool {
500 fn cast(syntax: SyntaxNode) -> Option<Self> {
501 if Self::can_cast(syntax.kind()) {
502 Some(Self { syntax })
507 fn syntax(&self) -> &SyntaxNode {
512 pub fn pat(&self) -> Option<Pat> {
513 AstChildren::new(&self.syntax).next()
515 pub fn expr(&self) -> Option<Expr> {
516 AstChildren::new(&self.syntax).next()
519 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
520 pub struct ConstDef {
521 pub(crate) syntax: SyntaxNode,
523 impl AstNode for ConstDef {
524 fn can_cast(kind: SyntaxKind) -> bool {
530 fn cast(syntax: SyntaxNode) -> Option<Self> {
531 if Self::can_cast(syntax.kind()) {
532 Some(Self { syntax })
537 fn syntax(&self) -> &SyntaxNode {
541 impl ast::VisibilityOwner for ConstDef {}
542 impl ast::NameOwner for ConstDef {}
543 impl ast::TypeParamsOwner for ConstDef {}
544 impl ast::AttrsOwner for ConstDef {}
545 impl ast::DocCommentsOwner for ConstDef {}
546 impl ast::TypeAscriptionOwner for ConstDef {}
548 pub fn body(&self) -> Option<Expr> {
549 AstChildren::new(&self.syntax).next()
552 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
553 pub struct ContinueExpr {
554 pub(crate) syntax: SyntaxNode,
556 impl AstNode for ContinueExpr {
557 fn can_cast(kind: SyntaxKind) -> bool {
559 CONTINUE_EXPR => true,
563 fn cast(syntax: SyntaxNode) -> Option<Self> {
564 if Self::can_cast(syntax.kind()) {
565 Some(Self { syntax })
570 fn syntax(&self) -> &SyntaxNode {
575 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
576 pub struct DotDotPat {
577 pub(crate) syntax: SyntaxNode,
579 impl AstNode for DotDotPat {
580 fn can_cast(kind: SyntaxKind) -> bool {
586 fn cast(syntax: SyntaxNode) -> Option<Self> {
587 if Self::can_cast(syntax.kind()) {
588 Some(Self { syntax })
593 fn syntax(&self) -> &SyntaxNode {
598 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
599 pub struct DynTraitType {
600 pub(crate) syntax: SyntaxNode,
602 impl AstNode for DynTraitType {
603 fn can_cast(kind: SyntaxKind) -> bool {
605 DYN_TRAIT_TYPE => true,
609 fn cast(syntax: SyntaxNode) -> Option<Self> {
610 if Self::can_cast(syntax.kind()) {
611 Some(Self { syntax })
616 fn syntax(&self) -> &SyntaxNode {
620 impl ast::TypeBoundsOwner for DynTraitType {}
622 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
624 pub(crate) syntax: SyntaxNode,
626 impl AstNode for EnumDef {
627 fn can_cast(kind: SyntaxKind) -> bool {
633 fn cast(syntax: SyntaxNode) -> Option<Self> {
634 if Self::can_cast(syntax.kind()) {
635 Some(Self { syntax })
640 fn syntax(&self) -> &SyntaxNode {
644 impl ast::VisibilityOwner for EnumDef {}
645 impl ast::NameOwner for EnumDef {}
646 impl ast::TypeParamsOwner for EnumDef {}
647 impl ast::AttrsOwner for EnumDef {}
648 impl ast::DocCommentsOwner for EnumDef {}
650 pub fn variant_list(&self) -> Option<EnumVariantList> {
651 AstChildren::new(&self.syntax).next()
654 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
655 pub struct EnumVariant {
656 pub(crate) syntax: SyntaxNode,
658 impl AstNode for EnumVariant {
659 fn can_cast(kind: SyntaxKind) -> bool {
661 ENUM_VARIANT => true,
665 fn cast(syntax: SyntaxNode) -> Option<Self> {
666 if Self::can_cast(syntax.kind()) {
667 Some(Self { syntax })
672 fn syntax(&self) -> &SyntaxNode {
676 impl ast::NameOwner for EnumVariant {}
677 impl ast::DocCommentsOwner for EnumVariant {}
678 impl ast::AttrsOwner for EnumVariant {}
680 pub fn expr(&self) -> Option<Expr> {
681 AstChildren::new(&self.syntax).next()
684 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
685 pub struct EnumVariantList {
686 pub(crate) syntax: SyntaxNode,
688 impl AstNode for EnumVariantList {
689 fn can_cast(kind: SyntaxKind) -> bool {
691 ENUM_VARIANT_LIST => true,
695 fn cast(syntax: SyntaxNode) -> Option<Self> {
696 if Self::can_cast(syntax.kind()) {
697 Some(Self { syntax })
702 fn syntax(&self) -> &SyntaxNode {
706 impl EnumVariantList {
707 pub fn variants(&self) -> AstChildren<EnumVariant> {
708 AstChildren::new(&self.syntax)
711 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
713 TupleExpr(TupleExpr),
714 ArrayExpr(ArrayExpr),
715 ParenExpr(ParenExpr),
717 LambdaExpr(LambdaExpr),
721 WhileExpr(WhileExpr),
722 ContinueExpr(ContinueExpr),
723 BreakExpr(BreakExpr),
725 BlockExpr(BlockExpr),
726 ReturnExpr(ReturnExpr),
727 MatchExpr(MatchExpr),
728 RecordLit(RecordLit),
730 IndexExpr(IndexExpr),
731 MethodCallExpr(MethodCallExpr),
732 FieldExpr(FieldExpr),
733 AwaitExpr(AwaitExpr),
735 TryBlockExpr(TryBlockExpr),
738 PrefixExpr(PrefixExpr),
739 RangeExpr(RangeExpr),
742 MacroCall(MacroCall),
745 impl From<TupleExpr> for Expr {
746 fn from(node: TupleExpr) -> Expr {
747 Expr::TupleExpr(node)
750 impl From<ArrayExpr> for Expr {
751 fn from(node: ArrayExpr) -> Expr {
752 Expr::ArrayExpr(node)
755 impl From<ParenExpr> for Expr {
756 fn from(node: ParenExpr) -> Expr {
757 Expr::ParenExpr(node)
760 impl From<PathExpr> for Expr {
761 fn from(node: PathExpr) -> Expr {
765 impl From<LambdaExpr> for Expr {
766 fn from(node: LambdaExpr) -> Expr {
767 Expr::LambdaExpr(node)
770 impl From<IfExpr> for Expr {
771 fn from(node: IfExpr) -> Expr {
775 impl From<LoopExpr> for Expr {
776 fn from(node: LoopExpr) -> Expr {
780 impl From<ForExpr> for Expr {
781 fn from(node: ForExpr) -> Expr {
785 impl From<WhileExpr> for Expr {
786 fn from(node: WhileExpr) -> Expr {
787 Expr::WhileExpr(node)
790 impl From<ContinueExpr> for Expr {
791 fn from(node: ContinueExpr) -> Expr {
792 Expr::ContinueExpr(node)
795 impl From<BreakExpr> for Expr {
796 fn from(node: BreakExpr) -> Expr {
797 Expr::BreakExpr(node)
800 impl From<Label> for Expr {
801 fn from(node: Label) -> Expr {
805 impl From<BlockExpr> for Expr {
806 fn from(node: BlockExpr) -> Expr {
807 Expr::BlockExpr(node)
810 impl From<ReturnExpr> for Expr {
811 fn from(node: ReturnExpr) -> Expr {
812 Expr::ReturnExpr(node)
815 impl From<MatchExpr> for Expr {
816 fn from(node: MatchExpr) -> Expr {
817 Expr::MatchExpr(node)
820 impl From<RecordLit> for Expr {
821 fn from(node: RecordLit) -> Expr {
822 Expr::RecordLit(node)
825 impl From<CallExpr> for Expr {
826 fn from(node: CallExpr) -> Expr {
830 impl From<IndexExpr> for Expr {
831 fn from(node: IndexExpr) -> Expr {
832 Expr::IndexExpr(node)
835 impl From<MethodCallExpr> for Expr {
836 fn from(node: MethodCallExpr) -> Expr {
837 Expr::MethodCallExpr(node)
840 impl From<FieldExpr> for Expr {
841 fn from(node: FieldExpr) -> Expr {
842 Expr::FieldExpr(node)
845 impl From<AwaitExpr> for Expr {
846 fn from(node: AwaitExpr) -> Expr {
847 Expr::AwaitExpr(node)
850 impl From<TryExpr> for Expr {
851 fn from(node: TryExpr) -> Expr {
855 impl From<TryBlockExpr> for Expr {
856 fn from(node: TryBlockExpr) -> Expr {
857 Expr::TryBlockExpr(node)
860 impl From<CastExpr> for Expr {
861 fn from(node: CastExpr) -> Expr {
865 impl From<RefExpr> for Expr {
866 fn from(node: RefExpr) -> Expr {
870 impl From<PrefixExpr> for Expr {
871 fn from(node: PrefixExpr) -> Expr {
872 Expr::PrefixExpr(node)
875 impl From<RangeExpr> for Expr {
876 fn from(node: RangeExpr) -> Expr {
877 Expr::RangeExpr(node)
880 impl From<BinExpr> for Expr {
881 fn from(node: BinExpr) -> Expr {
885 impl From<Literal> for Expr {
886 fn from(node: Literal) -> Expr {
890 impl From<MacroCall> for Expr {
891 fn from(node: MacroCall) -> Expr {
892 Expr::MacroCall(node)
895 impl From<BoxExpr> for Expr {
896 fn from(node: BoxExpr) -> Expr {
900 impl AstNode for Expr {
901 fn can_cast(kind: SyntaxKind) -> bool {
903 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
904 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
905 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
906 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
907 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL
912 fn cast(syntax: SyntaxNode) -> Option<Self> {
913 let res = match syntax.kind() {
914 TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
915 ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }),
916 PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }),
917 PATH_EXPR => Expr::PathExpr(PathExpr { syntax }),
918 LAMBDA_EXPR => Expr::LambdaExpr(LambdaExpr { syntax }),
919 IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
920 LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
921 FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
922 WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
923 CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
924 BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
925 LABEL => Expr::Label(Label { syntax }),
926 BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
927 RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
928 MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
929 RECORD_LIT => Expr::RecordLit(RecordLit { syntax }),
930 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
931 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
932 METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
933 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
934 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
935 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
936 TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
937 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
938 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
939 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
940 RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }),
941 BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
942 LITERAL => Expr::Literal(Literal { syntax }),
943 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
944 BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }),
949 fn syntax(&self) -> &SyntaxNode {
951 Expr::TupleExpr(it) => &it.syntax,
952 Expr::ArrayExpr(it) => &it.syntax,
953 Expr::ParenExpr(it) => &it.syntax,
954 Expr::PathExpr(it) => &it.syntax,
955 Expr::LambdaExpr(it) => &it.syntax,
956 Expr::IfExpr(it) => &it.syntax,
957 Expr::LoopExpr(it) => &it.syntax,
958 Expr::ForExpr(it) => &it.syntax,
959 Expr::WhileExpr(it) => &it.syntax,
960 Expr::ContinueExpr(it) => &it.syntax,
961 Expr::BreakExpr(it) => &it.syntax,
962 Expr::Label(it) => &it.syntax,
963 Expr::BlockExpr(it) => &it.syntax,
964 Expr::ReturnExpr(it) => &it.syntax,
965 Expr::MatchExpr(it) => &it.syntax,
966 Expr::RecordLit(it) => &it.syntax,
967 Expr::CallExpr(it) => &it.syntax,
968 Expr::IndexExpr(it) => &it.syntax,
969 Expr::MethodCallExpr(it) => &it.syntax,
970 Expr::FieldExpr(it) => &it.syntax,
971 Expr::AwaitExpr(it) => &it.syntax,
972 Expr::TryExpr(it) => &it.syntax,
973 Expr::TryBlockExpr(it) => &it.syntax,
974 Expr::CastExpr(it) => &it.syntax,
975 Expr::RefExpr(it) => &it.syntax,
976 Expr::PrefixExpr(it) => &it.syntax,
977 Expr::RangeExpr(it) => &it.syntax,
978 Expr::BinExpr(it) => &it.syntax,
979 Expr::Literal(it) => &it.syntax,
980 Expr::MacroCall(it) => &it.syntax,
981 Expr::BoxExpr(it) => &it.syntax,
986 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
987 pub struct ExprStmt {
988 pub(crate) syntax: SyntaxNode,
990 impl AstNode for ExprStmt {
991 fn can_cast(kind: SyntaxKind) -> bool {
997 fn cast(syntax: SyntaxNode) -> Option<Self> {
998 if Self::can_cast(syntax.kind()) {
999 Some(Self { syntax })
1004 fn syntax(&self) -> &SyntaxNode {
1009 pub fn expr(&self) -> Option<Expr> {
1010 AstChildren::new(&self.syntax).next()
1013 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1014 pub struct ExternCrateItem {
1015 pub(crate) syntax: SyntaxNode,
1017 impl AstNode for ExternCrateItem {
1018 fn can_cast(kind: SyntaxKind) -> bool {
1020 EXTERN_CRATE_ITEM => 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 ast::AttrsOwner for ExternCrateItem {}
1036 impl ExternCrateItem {
1037 pub fn name_ref(&self) -> Option<NameRef> {
1038 AstChildren::new(&self.syntax).next()
1040 pub fn alias(&self) -> Option<Alias> {
1041 AstChildren::new(&self.syntax).next()
1044 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1045 pub struct FieldExpr {
1046 pub(crate) syntax: SyntaxNode,
1048 impl AstNode for FieldExpr {
1049 fn can_cast(kind: SyntaxKind) -> bool {
1055 fn cast(syntax: SyntaxNode) -> Option<Self> {
1056 if Self::can_cast(syntax.kind()) {
1057 Some(Self { syntax })
1062 fn syntax(&self) -> &SyntaxNode {
1067 pub fn expr(&self) -> Option<Expr> {
1068 AstChildren::new(&self.syntax).next()
1070 pub fn name_ref(&self) -> Option<NameRef> {
1071 AstChildren::new(&self.syntax).next()
1074 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1076 pub(crate) syntax: SyntaxNode,
1078 impl AstNode for FnDef {
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 {
1096 impl ast::VisibilityOwner for FnDef {}
1097 impl ast::NameOwner for FnDef {}
1098 impl ast::TypeParamsOwner for FnDef {}
1099 impl ast::AttrsOwner for FnDef {}
1100 impl ast::DocCommentsOwner for FnDef {}
1102 pub fn param_list(&self) -> Option<ParamList> {
1103 AstChildren::new(&self.syntax).next()
1105 pub fn body(&self) -> Option<BlockExpr> {
1106 AstChildren::new(&self.syntax).next()
1108 pub fn ret_type(&self) -> Option<RetType> {
1109 AstChildren::new(&self.syntax).next()
1112 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1113 pub struct FnPointerType {
1114 pub(crate) syntax: SyntaxNode,
1116 impl AstNode for FnPointerType {
1117 fn can_cast(kind: SyntaxKind) -> bool {
1119 FN_POINTER_TYPE => true,
1123 fn cast(syntax: SyntaxNode) -> Option<Self> {
1124 if Self::can_cast(syntax.kind()) {
1125 Some(Self { syntax })
1130 fn syntax(&self) -> &SyntaxNode {
1134 impl FnPointerType {
1135 pub fn param_list(&self) -> Option<ParamList> {
1136 AstChildren::new(&self.syntax).next()
1138 pub fn ret_type(&self) -> Option<RetType> {
1139 AstChildren::new(&self.syntax).next()
1142 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1143 pub struct ForExpr {
1144 pub(crate) syntax: SyntaxNode,
1146 impl AstNode for ForExpr {
1147 fn can_cast(kind: SyntaxKind) -> bool {
1153 fn cast(syntax: SyntaxNode) -> Option<Self> {
1154 if Self::can_cast(syntax.kind()) {
1155 Some(Self { syntax })
1160 fn syntax(&self) -> &SyntaxNode {
1164 impl ast::LoopBodyOwner for ForExpr {}
1166 pub fn pat(&self) -> Option<Pat> {
1167 AstChildren::new(&self.syntax).next()
1169 pub fn iterable(&self) -> Option<Expr> {
1170 AstChildren::new(&self.syntax).next()
1173 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1174 pub struct ForType {
1175 pub(crate) syntax: SyntaxNode,
1177 impl AstNode for ForType {
1178 fn can_cast(kind: SyntaxKind) -> bool {
1184 fn cast(syntax: SyntaxNode) -> Option<Self> {
1185 if Self::can_cast(syntax.kind()) {
1186 Some(Self { syntax })
1191 fn syntax(&self) -> &SyntaxNode {
1196 pub fn type_ref(&self) -> Option<TypeRef> {
1197 AstChildren::new(&self.syntax).next()
1200 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1202 pub(crate) syntax: SyntaxNode,
1204 impl AstNode for IfExpr {
1205 fn can_cast(kind: SyntaxKind) -> bool {
1211 fn cast(syntax: SyntaxNode) -> Option<Self> {
1212 if Self::can_cast(syntax.kind()) {
1213 Some(Self { syntax })
1218 fn syntax(&self) -> &SyntaxNode {
1223 pub fn condition(&self) -> Option<Condition> {
1224 AstChildren::new(&self.syntax).next()
1227 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1228 pub struct ImplBlock {
1229 pub(crate) syntax: SyntaxNode,
1231 impl AstNode for ImplBlock {
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 {
1249 impl ast::TypeParamsOwner for ImplBlock {}
1250 impl ast::AttrsOwner for ImplBlock {}
1252 pub fn item_list(&self) -> Option<ItemList> {
1253 AstChildren::new(&self.syntax).next()
1256 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1259 TypeAliasDef(TypeAliasDef),
1262 impl From<FnDef> for ImplItem {
1263 fn from(node: FnDef) -> ImplItem {
1264 ImplItem::FnDef(node)
1267 impl From<TypeAliasDef> for ImplItem {
1268 fn from(node: TypeAliasDef) -> ImplItem {
1269 ImplItem::TypeAliasDef(node)
1272 impl From<ConstDef> for ImplItem {
1273 fn from(node: ConstDef) -> ImplItem {
1274 ImplItem::ConstDef(node)
1277 impl AstNode for ImplItem {
1278 fn can_cast(kind: SyntaxKind) -> bool {
1280 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1284 fn cast(syntax: SyntaxNode) -> Option<Self> {
1285 let res = match syntax.kind() {
1286 FN_DEF => ImplItem::FnDef(FnDef { syntax }),
1287 TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }),
1288 CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }),
1293 fn syntax(&self) -> &SyntaxNode {
1295 ImplItem::FnDef(it) => &it.syntax,
1296 ImplItem::TypeAliasDef(it) => &it.syntax,
1297 ImplItem::ConstDef(it) => &it.syntax,
1301 impl ast::AttrsOwner for ImplItem {}
1303 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1304 pub struct ImplTraitType {
1305 pub(crate) syntax: SyntaxNode,
1307 impl AstNode for ImplTraitType {
1308 fn can_cast(kind: SyntaxKind) -> bool {
1310 IMPL_TRAIT_TYPE => true,
1314 fn cast(syntax: SyntaxNode) -> Option<Self> {
1315 if Self::can_cast(syntax.kind()) {
1316 Some(Self { syntax })
1321 fn syntax(&self) -> &SyntaxNode {
1325 impl ast::TypeBoundsOwner for ImplTraitType {}
1326 impl ImplTraitType {}
1327 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1328 pub struct IndexExpr {
1329 pub(crate) syntax: SyntaxNode,
1331 impl AstNode for IndexExpr {
1332 fn can_cast(kind: SyntaxKind) -> bool {
1338 fn cast(syntax: SyntaxNode) -> Option<Self> {
1339 if Self::can_cast(syntax.kind()) {
1340 Some(Self { syntax })
1345 fn syntax(&self) -> &SyntaxNode {
1350 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1351 pub struct ItemList {
1352 pub(crate) syntax: SyntaxNode,
1354 impl AstNode for ItemList {
1355 fn can_cast(kind: SyntaxKind) -> bool {
1361 fn cast(syntax: SyntaxNode) -> Option<Self> {
1362 if Self::can_cast(syntax.kind()) {
1363 Some(Self { syntax })
1368 fn syntax(&self) -> &SyntaxNode {
1372 impl ast::FnDefOwner for ItemList {}
1373 impl ast::ModuleItemOwner for ItemList {}
1375 pub fn impl_items(&self) -> AstChildren<ImplItem> {
1376 AstChildren::new(&self.syntax)
1379 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1381 pub(crate) syntax: SyntaxNode,
1383 impl AstNode for Label {
1384 fn can_cast(kind: SyntaxKind) -> bool {
1390 fn cast(syntax: SyntaxNode) -> Option<Self> {
1391 if Self::can_cast(syntax.kind()) {
1392 Some(Self { syntax })
1397 fn syntax(&self) -> &SyntaxNode {
1402 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1403 pub struct LambdaExpr {
1404 pub(crate) syntax: SyntaxNode,
1406 impl AstNode for LambdaExpr {
1407 fn can_cast(kind: SyntaxKind) -> bool {
1409 LAMBDA_EXPR => true,
1413 fn cast(syntax: SyntaxNode) -> Option<Self> {
1414 if Self::can_cast(syntax.kind()) {
1415 Some(Self { syntax })
1420 fn syntax(&self) -> &SyntaxNode {
1425 pub fn param_list(&self) -> Option<ParamList> {
1426 AstChildren::new(&self.syntax).next()
1428 pub fn body(&self) -> Option<Expr> {
1429 AstChildren::new(&self.syntax).next()
1432 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1433 pub struct LetStmt {
1434 pub(crate) syntax: SyntaxNode,
1436 impl AstNode for LetStmt {
1437 fn can_cast(kind: SyntaxKind) -> bool {
1443 fn cast(syntax: SyntaxNode) -> Option<Self> {
1444 if Self::can_cast(syntax.kind()) {
1445 Some(Self { syntax })
1450 fn syntax(&self) -> &SyntaxNode {
1454 impl ast::TypeAscriptionOwner for LetStmt {}
1456 pub fn pat(&self) -> Option<Pat> {
1457 AstChildren::new(&self.syntax).next()
1459 pub fn initializer(&self) -> Option<Expr> {
1460 AstChildren::new(&self.syntax).next()
1463 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1464 pub struct LifetimeArg {
1465 pub(crate) syntax: SyntaxNode,
1467 impl AstNode for LifetimeArg {
1468 fn can_cast(kind: SyntaxKind) -> bool {
1470 LIFETIME_ARG => true,
1474 fn cast(syntax: SyntaxNode) -> Option<Self> {
1475 if Self::can_cast(syntax.kind()) {
1476 Some(Self { syntax })
1481 fn syntax(&self) -> &SyntaxNode {
1486 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1487 pub struct LifetimeParam {
1488 pub(crate) syntax: SyntaxNode,
1490 impl AstNode for LifetimeParam {
1491 fn can_cast(kind: SyntaxKind) -> bool {
1493 LIFETIME_PARAM => true,
1497 fn cast(syntax: SyntaxNode) -> Option<Self> {
1498 if Self::can_cast(syntax.kind()) {
1499 Some(Self { syntax })
1504 fn syntax(&self) -> &SyntaxNode {
1508 impl ast::AttrsOwner for LifetimeParam {}
1509 impl LifetimeParam {}
1510 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1511 pub struct Literal {
1512 pub(crate) syntax: SyntaxNode,
1514 impl AstNode for Literal {
1515 fn can_cast(kind: SyntaxKind) -> bool {
1521 fn cast(syntax: SyntaxNode) -> Option<Self> {
1522 if Self::can_cast(syntax.kind()) {
1523 Some(Self { syntax })
1528 fn syntax(&self) -> &SyntaxNode {
1533 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1534 pub struct LiteralPat {
1535 pub(crate) syntax: SyntaxNode,
1537 impl AstNode for LiteralPat {
1538 fn can_cast(kind: SyntaxKind) -> bool {
1540 LITERAL_PAT => true,
1544 fn cast(syntax: SyntaxNode) -> Option<Self> {
1545 if Self::can_cast(syntax.kind()) {
1546 Some(Self { syntax })
1551 fn syntax(&self) -> &SyntaxNode {
1556 pub fn literal(&self) -> Option<Literal> {
1557 AstChildren::new(&self.syntax).next()
1560 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1561 pub struct LoopExpr {
1562 pub(crate) syntax: SyntaxNode,
1564 impl AstNode for LoopExpr {
1565 fn can_cast(kind: SyntaxKind) -> bool {
1571 fn cast(syntax: SyntaxNode) -> Option<Self> {
1572 if Self::can_cast(syntax.kind()) {
1573 Some(Self { syntax })
1578 fn syntax(&self) -> &SyntaxNode {
1582 impl ast::LoopBodyOwner for LoopExpr {}
1584 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1585 pub struct MacroCall {
1586 pub(crate) syntax: SyntaxNode,
1588 impl AstNode for MacroCall {
1589 fn can_cast(kind: SyntaxKind) -> bool {
1595 fn cast(syntax: SyntaxNode) -> Option<Self> {
1596 if Self::can_cast(syntax.kind()) {
1597 Some(Self { syntax })
1602 fn syntax(&self) -> &SyntaxNode {
1606 impl ast::NameOwner for MacroCall {}
1607 impl ast::AttrsOwner for MacroCall {}
1608 impl ast::DocCommentsOwner for MacroCall {}
1610 pub fn token_tree(&self) -> Option<TokenTree> {
1611 AstChildren::new(&self.syntax).next()
1613 pub fn path(&self) -> Option<Path> {
1614 AstChildren::new(&self.syntax).next()
1617 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1618 pub struct MacroItems {
1619 pub(crate) syntax: SyntaxNode,
1621 impl AstNode for MacroItems {
1622 fn can_cast(kind: SyntaxKind) -> bool {
1624 MACRO_ITEMS => true,
1628 fn cast(syntax: SyntaxNode) -> Option<Self> {
1629 if Self::can_cast(syntax.kind()) {
1630 Some(Self { syntax })
1635 fn syntax(&self) -> &SyntaxNode {
1639 impl ast::ModuleItemOwner for MacroItems {}
1640 impl ast::FnDefOwner for MacroItems {}
1642 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1643 pub struct MacroStmts {
1644 pub(crate) syntax: SyntaxNode,
1646 impl AstNode for MacroStmts {
1647 fn can_cast(kind: SyntaxKind) -> bool {
1649 MACRO_STMTS => true,
1653 fn cast(syntax: SyntaxNode) -> Option<Self> {
1654 if Self::can_cast(syntax.kind()) {
1655 Some(Self { syntax })
1660 fn syntax(&self) -> &SyntaxNode {
1665 pub fn statements(&self) -> AstChildren<Stmt> {
1666 AstChildren::new(&self.syntax)
1668 pub fn expr(&self) -> Option<Expr> {
1669 AstChildren::new(&self.syntax).next()
1672 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1673 pub struct MatchArm {
1674 pub(crate) syntax: SyntaxNode,
1676 impl AstNode for MatchArm {
1677 fn can_cast(kind: SyntaxKind) -> bool {
1683 fn cast(syntax: SyntaxNode) -> Option<Self> {
1684 if Self::can_cast(syntax.kind()) {
1685 Some(Self { syntax })
1690 fn syntax(&self) -> &SyntaxNode {
1694 impl ast::AttrsOwner for MatchArm {}
1696 pub fn pats(&self) -> AstChildren<Pat> {
1697 AstChildren::new(&self.syntax)
1699 pub fn guard(&self) -> Option<MatchGuard> {
1700 AstChildren::new(&self.syntax).next()
1702 pub fn expr(&self) -> Option<Expr> {
1703 AstChildren::new(&self.syntax).next()
1706 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1707 pub struct MatchArmList {
1708 pub(crate) syntax: SyntaxNode,
1710 impl AstNode for MatchArmList {
1711 fn can_cast(kind: SyntaxKind) -> bool {
1713 MATCH_ARM_LIST => true,
1717 fn cast(syntax: SyntaxNode) -> Option<Self> {
1718 if Self::can_cast(syntax.kind()) {
1719 Some(Self { syntax })
1724 fn syntax(&self) -> &SyntaxNode {
1728 impl ast::AttrsOwner for MatchArmList {}
1730 pub fn arms(&self) -> AstChildren<MatchArm> {
1731 AstChildren::new(&self.syntax)
1734 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1735 pub struct MatchExpr {
1736 pub(crate) syntax: SyntaxNode,
1738 impl AstNode for MatchExpr {
1739 fn can_cast(kind: SyntaxKind) -> bool {
1745 fn cast(syntax: SyntaxNode) -> Option<Self> {
1746 if Self::can_cast(syntax.kind()) {
1747 Some(Self { syntax })
1752 fn syntax(&self) -> &SyntaxNode {
1757 pub fn expr(&self) -> Option<Expr> {
1758 AstChildren::new(&self.syntax).next()
1760 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1761 AstChildren::new(&self.syntax).next()
1764 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1765 pub struct MatchGuard {
1766 pub(crate) syntax: SyntaxNode,
1768 impl AstNode for MatchGuard {
1769 fn can_cast(kind: SyntaxKind) -> bool {
1771 MATCH_GUARD => true,
1775 fn cast(syntax: SyntaxNode) -> Option<Self> {
1776 if Self::can_cast(syntax.kind()) {
1777 Some(Self { syntax })
1782 fn syntax(&self) -> &SyntaxNode {
1787 pub fn expr(&self) -> Option<Expr> {
1788 AstChildren::new(&self.syntax).next()
1791 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1792 pub struct MethodCallExpr {
1793 pub(crate) syntax: SyntaxNode,
1795 impl AstNode for MethodCallExpr {
1796 fn can_cast(kind: SyntaxKind) -> bool {
1798 METHOD_CALL_EXPR => true,
1802 fn cast(syntax: SyntaxNode) -> Option<Self> {
1803 if Self::can_cast(syntax.kind()) {
1804 Some(Self { syntax })
1809 fn syntax(&self) -> &SyntaxNode {
1813 impl ast::ArgListOwner for MethodCallExpr {}
1814 impl MethodCallExpr {
1815 pub fn expr(&self) -> Option<Expr> {
1816 AstChildren::new(&self.syntax).next()
1818 pub fn name_ref(&self) -> Option<NameRef> {
1819 AstChildren::new(&self.syntax).next()
1821 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1822 AstChildren::new(&self.syntax).next()
1825 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1827 pub(crate) syntax: SyntaxNode,
1829 impl AstNode for Module {
1830 fn can_cast(kind: SyntaxKind) -> bool {
1836 fn cast(syntax: SyntaxNode) -> Option<Self> {
1837 if Self::can_cast(syntax.kind()) {
1838 Some(Self { syntax })
1843 fn syntax(&self) -> &SyntaxNode {
1847 impl ast::VisibilityOwner for Module {}
1848 impl ast::NameOwner for Module {}
1849 impl ast::AttrsOwner for Module {}
1850 impl ast::DocCommentsOwner for Module {}
1852 pub fn item_list(&self) -> Option<ItemList> {
1853 AstChildren::new(&self.syntax).next()
1856 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1857 pub enum ModuleItem {
1858 StructDef(StructDef),
1863 TypeAliasDef(TypeAliasDef),
1864 ImplBlock(ImplBlock),
1866 ExternCrateItem(ExternCrateItem),
1868 StaticDef(StaticDef),
1871 impl From<StructDef> for ModuleItem {
1872 fn from(node: StructDef) -> ModuleItem {
1873 ModuleItem::StructDef(node)
1876 impl From<UnionDef> for ModuleItem {
1877 fn from(node: UnionDef) -> ModuleItem {
1878 ModuleItem::UnionDef(node)
1881 impl From<EnumDef> for ModuleItem {
1882 fn from(node: EnumDef) -> ModuleItem {
1883 ModuleItem::EnumDef(node)
1886 impl From<FnDef> for ModuleItem {
1887 fn from(node: FnDef) -> ModuleItem {
1888 ModuleItem::FnDef(node)
1891 impl From<TraitDef> for ModuleItem {
1892 fn from(node: TraitDef) -> ModuleItem {
1893 ModuleItem::TraitDef(node)
1896 impl From<TypeAliasDef> for ModuleItem {
1897 fn from(node: TypeAliasDef) -> ModuleItem {
1898 ModuleItem::TypeAliasDef(node)
1901 impl From<ImplBlock> for ModuleItem {
1902 fn from(node: ImplBlock) -> ModuleItem {
1903 ModuleItem::ImplBlock(node)
1906 impl From<UseItem> for ModuleItem {
1907 fn from(node: UseItem) -> ModuleItem {
1908 ModuleItem::UseItem(node)
1911 impl From<ExternCrateItem> for ModuleItem {
1912 fn from(node: ExternCrateItem) -> ModuleItem {
1913 ModuleItem::ExternCrateItem(node)
1916 impl From<ConstDef> for ModuleItem {
1917 fn from(node: ConstDef) -> ModuleItem {
1918 ModuleItem::ConstDef(node)
1921 impl From<StaticDef> for ModuleItem {
1922 fn from(node: StaticDef) -> ModuleItem {
1923 ModuleItem::StaticDef(node)
1926 impl From<Module> for ModuleItem {
1927 fn from(node: Module) -> ModuleItem {
1928 ModuleItem::Module(node)
1931 impl AstNode for ModuleItem {
1932 fn can_cast(kind: SyntaxKind) -> bool {
1934 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF
1935 | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1939 fn cast(syntax: SyntaxNode) -> Option<Self> {
1940 let res = match syntax.kind() {
1941 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
1942 UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }),
1943 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
1944 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
1945 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
1946 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
1947 IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
1948 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
1949 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
1950 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
1951 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
1952 MODULE => ModuleItem::Module(Module { syntax }),
1957 fn syntax(&self) -> &SyntaxNode {
1959 ModuleItem::StructDef(it) => &it.syntax,
1960 ModuleItem::UnionDef(it) => &it.syntax,
1961 ModuleItem::EnumDef(it) => &it.syntax,
1962 ModuleItem::FnDef(it) => &it.syntax,
1963 ModuleItem::TraitDef(it) => &it.syntax,
1964 ModuleItem::TypeAliasDef(it) => &it.syntax,
1965 ModuleItem::ImplBlock(it) => &it.syntax,
1966 ModuleItem::UseItem(it) => &it.syntax,
1967 ModuleItem::ExternCrateItem(it) => &it.syntax,
1968 ModuleItem::ConstDef(it) => &it.syntax,
1969 ModuleItem::StaticDef(it) => &it.syntax,
1970 ModuleItem::Module(it) => &it.syntax,
1974 impl ast::AttrsOwner for ModuleItem {}
1976 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1978 pub(crate) syntax: SyntaxNode,
1980 impl AstNode for Name {
1981 fn can_cast(kind: SyntaxKind) -> bool {
1987 fn cast(syntax: SyntaxNode) -> Option<Self> {
1988 if Self::can_cast(syntax.kind()) {
1989 Some(Self { syntax })
1994 fn syntax(&self) -> &SyntaxNode {
1999 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2000 pub struct NameRef {
2001 pub(crate) syntax: SyntaxNode,
2003 impl AstNode for NameRef {
2004 fn can_cast(kind: SyntaxKind) -> bool {
2010 fn cast(syntax: SyntaxNode) -> Option<Self> {
2011 if Self::can_cast(syntax.kind()) {
2012 Some(Self { syntax })
2017 fn syntax(&self) -> &SyntaxNode {
2022 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2023 pub struct NeverType {
2024 pub(crate) syntax: SyntaxNode,
2026 impl AstNode for NeverType {
2027 fn can_cast(kind: SyntaxKind) -> bool {
2033 fn cast(syntax: SyntaxNode) -> Option<Self> {
2034 if Self::can_cast(syntax.kind()) {
2035 Some(Self { syntax })
2040 fn syntax(&self) -> &SyntaxNode {
2045 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2046 pub enum NominalDef {
2047 StructDef(StructDef),
2051 impl From<StructDef> for NominalDef {
2052 fn from(node: StructDef) -> NominalDef {
2053 NominalDef::StructDef(node)
2056 impl From<EnumDef> for NominalDef {
2057 fn from(node: EnumDef) -> NominalDef {
2058 NominalDef::EnumDef(node)
2061 impl From<UnionDef> for NominalDef {
2062 fn from(node: UnionDef) -> NominalDef {
2063 NominalDef::UnionDef(node)
2066 impl AstNode for NominalDef {
2067 fn can_cast(kind: SyntaxKind) -> bool {
2069 STRUCT_DEF | ENUM_DEF | UNION_DEF => true,
2073 fn cast(syntax: SyntaxNode) -> Option<Self> {
2074 let res = match syntax.kind() {
2075 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
2076 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
2077 UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }),
2082 fn syntax(&self) -> &SyntaxNode {
2084 NominalDef::StructDef(it) => &it.syntax,
2085 NominalDef::EnumDef(it) => &it.syntax,
2086 NominalDef::UnionDef(it) => &it.syntax,
2090 impl ast::NameOwner for NominalDef {}
2091 impl ast::TypeParamsOwner for NominalDef {}
2092 impl ast::AttrsOwner for NominalDef {}
2094 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2096 pub(crate) syntax: SyntaxNode,
2098 impl AstNode for Param {
2099 fn can_cast(kind: SyntaxKind) -> bool {
2105 fn cast(syntax: SyntaxNode) -> Option<Self> {
2106 if Self::can_cast(syntax.kind()) {
2107 Some(Self { syntax })
2112 fn syntax(&self) -> &SyntaxNode {
2116 impl ast::TypeAscriptionOwner for Param {}
2117 impl ast::AttrsOwner for Param {}
2119 pub fn pat(&self) -> Option<Pat> {
2120 AstChildren::new(&self.syntax).next()
2123 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2124 pub struct ParamList {
2125 pub(crate) syntax: SyntaxNode,
2127 impl AstNode for ParamList {
2128 fn can_cast(kind: SyntaxKind) -> bool {
2134 fn cast(syntax: SyntaxNode) -> Option<Self> {
2135 if Self::can_cast(syntax.kind()) {
2136 Some(Self { syntax })
2141 fn syntax(&self) -> &SyntaxNode {
2146 pub fn params(&self) -> AstChildren<Param> {
2147 AstChildren::new(&self.syntax)
2149 pub fn self_param(&self) -> Option<SelfParam> {
2150 AstChildren::new(&self.syntax).next()
2153 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2154 pub struct ParenExpr {
2155 pub(crate) syntax: SyntaxNode,
2157 impl AstNode for ParenExpr {
2158 fn can_cast(kind: SyntaxKind) -> bool {
2164 fn cast(syntax: SyntaxNode) -> Option<Self> {
2165 if Self::can_cast(syntax.kind()) {
2166 Some(Self { syntax })
2171 fn syntax(&self) -> &SyntaxNode {
2176 pub fn expr(&self) -> Option<Expr> {
2177 AstChildren::new(&self.syntax).next()
2180 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2181 pub struct ParenType {
2182 pub(crate) syntax: SyntaxNode,
2184 impl AstNode for ParenType {
2185 fn can_cast(kind: SyntaxKind) -> bool {
2191 fn cast(syntax: SyntaxNode) -> Option<Self> {
2192 if Self::can_cast(syntax.kind()) {
2193 Some(Self { syntax })
2198 fn syntax(&self) -> &SyntaxNode {
2203 pub fn type_ref(&self) -> Option<TypeRef> {
2204 AstChildren::new(&self.syntax).next()
2207 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2212 PlaceholderPat(PlaceholderPat),
2213 DotDotPat(DotDotPat),
2215 RecordPat(RecordPat),
2216 TupleStructPat(TupleStructPat),
2220 LiteralPat(LiteralPat),
2222 impl From<RefPat> for Pat {
2223 fn from(node: RefPat) -> Pat {
2227 impl From<BoxPat> for Pat {
2228 fn from(node: BoxPat) -> Pat {
2232 impl From<BindPat> for Pat {
2233 fn from(node: BindPat) -> Pat {
2237 impl From<PlaceholderPat> for Pat {
2238 fn from(node: PlaceholderPat) -> Pat {
2239 Pat::PlaceholderPat(node)
2242 impl From<DotDotPat> for Pat {
2243 fn from(node: DotDotPat) -> Pat {
2244 Pat::DotDotPat(node)
2247 impl From<PathPat> for Pat {
2248 fn from(node: PathPat) -> Pat {
2252 impl From<RecordPat> for Pat {
2253 fn from(node: RecordPat) -> Pat {
2254 Pat::RecordPat(node)
2257 impl From<TupleStructPat> for Pat {
2258 fn from(node: TupleStructPat) -> Pat {
2259 Pat::TupleStructPat(node)
2262 impl From<TuplePat> for Pat {
2263 fn from(node: TuplePat) -> Pat {
2267 impl From<SlicePat> for Pat {
2268 fn from(node: SlicePat) -> Pat {
2272 impl From<RangePat> for Pat {
2273 fn from(node: RangePat) -> Pat {
2277 impl From<LiteralPat> for Pat {
2278 fn from(node: LiteralPat) -> Pat {
2279 Pat::LiteralPat(node)
2282 impl AstNode for Pat {
2283 fn can_cast(kind: SyntaxKind) -> bool {
2285 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT
2286 | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => {
2292 fn cast(syntax: SyntaxNode) -> Option<Self> {
2293 let res = match syntax.kind() {
2294 REF_PAT => Pat::RefPat(RefPat { syntax }),
2295 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2296 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2297 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2298 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
2299 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2300 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2301 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2302 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2303 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2304 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2305 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2310 fn syntax(&self) -> &SyntaxNode {
2312 Pat::RefPat(it) => &it.syntax,
2313 Pat::BoxPat(it) => &it.syntax,
2314 Pat::BindPat(it) => &it.syntax,
2315 Pat::PlaceholderPat(it) => &it.syntax,
2316 Pat::DotDotPat(it) => &it.syntax,
2317 Pat::PathPat(it) => &it.syntax,
2318 Pat::RecordPat(it) => &it.syntax,
2319 Pat::TupleStructPat(it) => &it.syntax,
2320 Pat::TuplePat(it) => &it.syntax,
2321 Pat::SlicePat(it) => &it.syntax,
2322 Pat::RangePat(it) => &it.syntax,
2323 Pat::LiteralPat(it) => &it.syntax,
2328 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2330 pub(crate) syntax: SyntaxNode,
2332 impl AstNode for Path {
2333 fn can_cast(kind: SyntaxKind) -> bool {
2339 fn cast(syntax: SyntaxNode) -> Option<Self> {
2340 if Self::can_cast(syntax.kind()) {
2341 Some(Self { syntax })
2346 fn syntax(&self) -> &SyntaxNode {
2351 pub fn segment(&self) -> Option<PathSegment> {
2352 AstChildren::new(&self.syntax).next()
2354 pub fn qualifier(&self) -> Option<Path> {
2355 AstChildren::new(&self.syntax).next()
2358 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2359 pub struct PathExpr {
2360 pub(crate) syntax: SyntaxNode,
2362 impl AstNode for PathExpr {
2363 fn can_cast(kind: SyntaxKind) -> bool {
2369 fn cast(syntax: SyntaxNode) -> Option<Self> {
2370 if Self::can_cast(syntax.kind()) {
2371 Some(Self { syntax })
2376 fn syntax(&self) -> &SyntaxNode {
2381 pub fn path(&self) -> Option<Path> {
2382 AstChildren::new(&self.syntax).next()
2385 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2386 pub struct PathPat {
2387 pub(crate) syntax: SyntaxNode,
2389 impl AstNode for PathPat {
2390 fn can_cast(kind: SyntaxKind) -> bool {
2396 fn cast(syntax: SyntaxNode) -> Option<Self> {
2397 if Self::can_cast(syntax.kind()) {
2398 Some(Self { syntax })
2403 fn syntax(&self) -> &SyntaxNode {
2408 pub fn path(&self) -> Option<Path> {
2409 AstChildren::new(&self.syntax).next()
2412 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2413 pub struct PathSegment {
2414 pub(crate) syntax: SyntaxNode,
2416 impl AstNode for PathSegment {
2417 fn can_cast(kind: SyntaxKind) -> bool {
2419 PATH_SEGMENT => true,
2423 fn cast(syntax: SyntaxNode) -> Option<Self> {
2424 if Self::can_cast(syntax.kind()) {
2425 Some(Self { syntax })
2430 fn syntax(&self) -> &SyntaxNode {
2435 pub fn name_ref(&self) -> Option<NameRef> {
2436 AstChildren::new(&self.syntax).next()
2438 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2439 AstChildren::new(&self.syntax).next()
2441 pub fn param_list(&self) -> Option<ParamList> {
2442 AstChildren::new(&self.syntax).next()
2444 pub fn ret_type(&self) -> Option<RetType> {
2445 AstChildren::new(&self.syntax).next()
2447 pub fn path_type(&self) -> Option<PathType> {
2448 AstChildren::new(&self.syntax).next()
2451 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2452 pub struct PathType {
2453 pub(crate) syntax: SyntaxNode,
2455 impl AstNode for PathType {
2456 fn can_cast(kind: SyntaxKind) -> bool {
2462 fn cast(syntax: SyntaxNode) -> Option<Self> {
2463 if Self::can_cast(syntax.kind()) {
2464 Some(Self { syntax })
2469 fn syntax(&self) -> &SyntaxNode {
2474 pub fn path(&self) -> Option<Path> {
2475 AstChildren::new(&self.syntax).next()
2478 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2479 pub struct PlaceholderPat {
2480 pub(crate) syntax: SyntaxNode,
2482 impl AstNode for PlaceholderPat {
2483 fn can_cast(kind: SyntaxKind) -> bool {
2485 PLACEHOLDER_PAT => true,
2489 fn cast(syntax: SyntaxNode) -> Option<Self> {
2490 if Self::can_cast(syntax.kind()) {
2491 Some(Self { syntax })
2496 fn syntax(&self) -> &SyntaxNode {
2500 impl PlaceholderPat {}
2501 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2502 pub struct PlaceholderType {
2503 pub(crate) syntax: SyntaxNode,
2505 impl AstNode for PlaceholderType {
2506 fn can_cast(kind: SyntaxKind) -> bool {
2508 PLACEHOLDER_TYPE => true,
2512 fn cast(syntax: SyntaxNode) -> Option<Self> {
2513 if Self::can_cast(syntax.kind()) {
2514 Some(Self { syntax })
2519 fn syntax(&self) -> &SyntaxNode {
2523 impl PlaceholderType {}
2524 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2525 pub struct PointerType {
2526 pub(crate) syntax: SyntaxNode,
2528 impl AstNode for PointerType {
2529 fn can_cast(kind: SyntaxKind) -> bool {
2531 POINTER_TYPE => true,
2535 fn cast(syntax: SyntaxNode) -> Option<Self> {
2536 if Self::can_cast(syntax.kind()) {
2537 Some(Self { syntax })
2542 fn syntax(&self) -> &SyntaxNode {
2547 pub fn type_ref(&self) -> Option<TypeRef> {
2548 AstChildren::new(&self.syntax).next()
2551 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2552 pub struct PrefixExpr {
2553 pub(crate) syntax: SyntaxNode,
2555 impl AstNode for PrefixExpr {
2556 fn can_cast(kind: SyntaxKind) -> bool {
2558 PREFIX_EXPR => true,
2562 fn cast(syntax: SyntaxNode) -> Option<Self> {
2563 if Self::can_cast(syntax.kind()) {
2564 Some(Self { syntax })
2569 fn syntax(&self) -> &SyntaxNode {
2574 pub fn expr(&self) -> Option<Expr> {
2575 AstChildren::new(&self.syntax).next()
2578 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2579 pub struct RangeExpr {
2580 pub(crate) syntax: SyntaxNode,
2582 impl AstNode for RangeExpr {
2583 fn can_cast(kind: SyntaxKind) -> bool {
2589 fn cast(syntax: SyntaxNode) -> Option<Self> {
2590 if Self::can_cast(syntax.kind()) {
2591 Some(Self { syntax })
2596 fn syntax(&self) -> &SyntaxNode {
2601 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2602 pub struct RangePat {
2603 pub(crate) syntax: SyntaxNode,
2605 impl AstNode for RangePat {
2606 fn can_cast(kind: SyntaxKind) -> bool {
2612 fn cast(syntax: SyntaxNode) -> Option<Self> {
2613 if Self::can_cast(syntax.kind()) {
2614 Some(Self { syntax })
2619 fn syntax(&self) -> &SyntaxNode {
2624 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2625 pub struct RecordField {
2626 pub(crate) syntax: SyntaxNode,
2628 impl AstNode for RecordField {
2629 fn can_cast(kind: SyntaxKind) -> bool {
2631 RECORD_FIELD => true,
2635 fn cast(syntax: SyntaxNode) -> Option<Self> {
2636 if Self::can_cast(syntax.kind()) {
2637 Some(Self { syntax })
2642 fn syntax(&self) -> &SyntaxNode {
2647 pub fn name_ref(&self) -> Option<NameRef> {
2648 AstChildren::new(&self.syntax).next()
2650 pub fn expr(&self) -> Option<Expr> {
2651 AstChildren::new(&self.syntax).next()
2654 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2655 pub struct RecordFieldDef {
2656 pub(crate) syntax: SyntaxNode,
2658 impl AstNode for RecordFieldDef {
2659 fn can_cast(kind: SyntaxKind) -> bool {
2661 RECORD_FIELD_DEF => true,
2665 fn cast(syntax: SyntaxNode) -> Option<Self> {
2666 if Self::can_cast(syntax.kind()) {
2667 Some(Self { syntax })
2672 fn syntax(&self) -> &SyntaxNode {
2676 impl ast::VisibilityOwner for RecordFieldDef {}
2677 impl ast::NameOwner for RecordFieldDef {}
2678 impl ast::AttrsOwner for RecordFieldDef {}
2679 impl ast::DocCommentsOwner for RecordFieldDef {}
2680 impl ast::TypeAscriptionOwner for RecordFieldDef {}
2681 impl RecordFieldDef {}
2682 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2683 pub struct RecordFieldDefList {
2684 pub(crate) syntax: SyntaxNode,
2686 impl AstNode for RecordFieldDefList {
2687 fn can_cast(kind: SyntaxKind) -> bool {
2689 RECORD_FIELD_DEF_LIST => true,
2693 fn cast(syntax: SyntaxNode) -> Option<Self> {
2694 if Self::can_cast(syntax.kind()) {
2695 Some(Self { syntax })
2700 fn syntax(&self) -> &SyntaxNode {
2704 impl RecordFieldDefList {
2705 pub fn fields(&self) -> AstChildren<RecordFieldDef> {
2706 AstChildren::new(&self.syntax)
2709 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2710 pub struct RecordFieldList {
2711 pub(crate) syntax: SyntaxNode,
2713 impl AstNode for RecordFieldList {
2714 fn can_cast(kind: SyntaxKind) -> bool {
2716 RECORD_FIELD_LIST => true,
2720 fn cast(syntax: SyntaxNode) -> Option<Self> {
2721 if Self::can_cast(syntax.kind()) {
2722 Some(Self { syntax })
2727 fn syntax(&self) -> &SyntaxNode {
2731 impl RecordFieldList {
2732 pub fn fields(&self) -> AstChildren<RecordField> {
2733 AstChildren::new(&self.syntax)
2735 pub fn spread(&self) -> Option<Expr> {
2736 AstChildren::new(&self.syntax).next()
2739 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2740 pub struct RecordFieldPat {
2741 pub(crate) syntax: SyntaxNode,
2743 impl AstNode for RecordFieldPat {
2744 fn can_cast(kind: SyntaxKind) -> bool {
2746 RECORD_FIELD_PAT => true,
2750 fn cast(syntax: SyntaxNode) -> Option<Self> {
2751 if Self::can_cast(syntax.kind()) {
2752 Some(Self { syntax })
2757 fn syntax(&self) -> &SyntaxNode {
2761 impl ast::NameOwner for RecordFieldPat {}
2762 impl RecordFieldPat {
2763 pub fn pat(&self) -> Option<Pat> {
2764 AstChildren::new(&self.syntax).next()
2767 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2768 pub struct RecordFieldPatList {
2769 pub(crate) syntax: SyntaxNode,
2771 impl AstNode for RecordFieldPatList {
2772 fn can_cast(kind: SyntaxKind) -> bool {
2774 RECORD_FIELD_PAT_LIST => true,
2778 fn cast(syntax: SyntaxNode) -> Option<Self> {
2779 if Self::can_cast(syntax.kind()) {
2780 Some(Self { syntax })
2785 fn syntax(&self) -> &SyntaxNode {
2789 impl RecordFieldPatList {
2790 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
2791 AstChildren::new(&self.syntax)
2793 pub fn bind_pats(&self) -> AstChildren<BindPat> {
2794 AstChildren::new(&self.syntax)
2797 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2798 pub struct RecordLit {
2799 pub(crate) syntax: SyntaxNode,
2801 impl AstNode for RecordLit {
2802 fn can_cast(kind: SyntaxKind) -> bool {
2808 fn cast(syntax: SyntaxNode) -> Option<Self> {
2809 if Self::can_cast(syntax.kind()) {
2810 Some(Self { syntax })
2815 fn syntax(&self) -> &SyntaxNode {
2820 pub fn path(&self) -> Option<Path> {
2821 AstChildren::new(&self.syntax).next()
2823 pub fn record_field_list(&self) -> Option<RecordFieldList> {
2824 AstChildren::new(&self.syntax).next()
2827 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2828 pub struct RecordPat {
2829 pub(crate) syntax: SyntaxNode,
2831 impl AstNode for RecordPat {
2832 fn can_cast(kind: SyntaxKind) -> bool {
2838 fn cast(syntax: SyntaxNode) -> Option<Self> {
2839 if Self::can_cast(syntax.kind()) {
2840 Some(Self { syntax })
2845 fn syntax(&self) -> &SyntaxNode {
2850 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
2851 AstChildren::new(&self.syntax).next()
2853 pub fn path(&self) -> Option<Path> {
2854 AstChildren::new(&self.syntax).next()
2857 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2858 pub struct RefExpr {
2859 pub(crate) syntax: SyntaxNode,
2861 impl AstNode for RefExpr {
2862 fn can_cast(kind: SyntaxKind) -> bool {
2868 fn cast(syntax: SyntaxNode) -> Option<Self> {
2869 if Self::can_cast(syntax.kind()) {
2870 Some(Self { syntax })
2875 fn syntax(&self) -> &SyntaxNode {
2880 pub fn expr(&self) -> Option<Expr> {
2881 AstChildren::new(&self.syntax).next()
2884 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2886 pub(crate) syntax: SyntaxNode,
2888 impl AstNode for RefPat {
2889 fn can_cast(kind: SyntaxKind) -> bool {
2895 fn cast(syntax: SyntaxNode) -> Option<Self> {
2896 if Self::can_cast(syntax.kind()) {
2897 Some(Self { syntax })
2902 fn syntax(&self) -> &SyntaxNode {
2907 pub fn pat(&self) -> Option<Pat> {
2908 AstChildren::new(&self.syntax).next()
2911 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2912 pub struct ReferenceType {
2913 pub(crate) syntax: SyntaxNode,
2915 impl AstNode for ReferenceType {
2916 fn can_cast(kind: SyntaxKind) -> bool {
2918 REFERENCE_TYPE => true,
2922 fn cast(syntax: SyntaxNode) -> Option<Self> {
2923 if Self::can_cast(syntax.kind()) {
2924 Some(Self { syntax })
2929 fn syntax(&self) -> &SyntaxNode {
2933 impl ReferenceType {
2934 pub fn type_ref(&self) -> Option<TypeRef> {
2935 AstChildren::new(&self.syntax).next()
2938 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2939 pub struct RetType {
2940 pub(crate) syntax: SyntaxNode,
2942 impl AstNode for RetType {
2943 fn can_cast(kind: SyntaxKind) -> bool {
2949 fn cast(syntax: SyntaxNode) -> Option<Self> {
2950 if Self::can_cast(syntax.kind()) {
2951 Some(Self { syntax })
2956 fn syntax(&self) -> &SyntaxNode {
2961 pub fn type_ref(&self) -> Option<TypeRef> {
2962 AstChildren::new(&self.syntax).next()
2965 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2966 pub struct ReturnExpr {
2967 pub(crate) syntax: SyntaxNode,
2969 impl AstNode for ReturnExpr {
2970 fn can_cast(kind: SyntaxKind) -> bool {
2972 RETURN_EXPR => true,
2976 fn cast(syntax: SyntaxNode) -> Option<Self> {
2977 if Self::can_cast(syntax.kind()) {
2978 Some(Self { syntax })
2983 fn syntax(&self) -> &SyntaxNode {
2988 pub fn expr(&self) -> Option<Expr> {
2989 AstChildren::new(&self.syntax).next()
2992 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2993 pub struct SelfParam {
2994 pub(crate) syntax: SyntaxNode,
2996 impl AstNode for SelfParam {
2997 fn can_cast(kind: SyntaxKind) -> bool {
3003 fn cast(syntax: SyntaxNode) -> Option<Self> {
3004 if Self::can_cast(syntax.kind()) {
3005 Some(Self { syntax })
3010 fn syntax(&self) -> &SyntaxNode {
3014 impl ast::TypeAscriptionOwner for SelfParam {}
3015 impl ast::AttrsOwner for SelfParam {}
3017 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3018 pub struct SlicePat {
3019 pub(crate) syntax: SyntaxNode,
3021 impl AstNode for SlicePat {
3022 fn can_cast(kind: SyntaxKind) -> bool {
3028 fn cast(syntax: SyntaxNode) -> Option<Self> {
3029 if Self::can_cast(syntax.kind()) {
3030 Some(Self { syntax })
3035 fn syntax(&self) -> &SyntaxNode {
3040 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3041 pub struct SliceType {
3042 pub(crate) syntax: SyntaxNode,
3044 impl AstNode for SliceType {
3045 fn can_cast(kind: SyntaxKind) -> bool {
3051 fn cast(syntax: SyntaxNode) -> Option<Self> {
3052 if Self::can_cast(syntax.kind()) {
3053 Some(Self { syntax })
3058 fn syntax(&self) -> &SyntaxNode {
3063 pub fn type_ref(&self) -> Option<TypeRef> {
3064 AstChildren::new(&self.syntax).next()
3067 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3068 pub struct SourceFile {
3069 pub(crate) syntax: SyntaxNode,
3071 impl AstNode for SourceFile {
3072 fn can_cast(kind: SyntaxKind) -> bool {
3074 SOURCE_FILE => true,
3078 fn cast(syntax: SyntaxNode) -> Option<Self> {
3079 if Self::can_cast(syntax.kind()) {
3080 Some(Self { syntax })
3085 fn syntax(&self) -> &SyntaxNode {
3089 impl ast::ModuleItemOwner for SourceFile {}
3090 impl ast::FnDefOwner for SourceFile {}
3092 pub fn modules(&self) -> AstChildren<Module> {
3093 AstChildren::new(&self.syntax)
3096 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3097 pub struct StaticDef {
3098 pub(crate) syntax: SyntaxNode,
3100 impl AstNode for StaticDef {
3101 fn can_cast(kind: SyntaxKind) -> bool {
3107 fn cast(syntax: SyntaxNode) -> Option<Self> {
3108 if Self::can_cast(syntax.kind()) {
3109 Some(Self { syntax })
3114 fn syntax(&self) -> &SyntaxNode {
3118 impl ast::VisibilityOwner for StaticDef {}
3119 impl ast::NameOwner for StaticDef {}
3120 impl ast::TypeParamsOwner for StaticDef {}
3121 impl ast::AttrsOwner for StaticDef {}
3122 impl ast::DocCommentsOwner for StaticDef {}
3123 impl ast::TypeAscriptionOwner for StaticDef {}
3125 pub fn body(&self) -> Option<Expr> {
3126 AstChildren::new(&self.syntax).next()
3129 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3134 impl From<ExprStmt> for Stmt {
3135 fn from(node: ExprStmt) -> Stmt {
3136 Stmt::ExprStmt(node)
3139 impl From<LetStmt> for Stmt {
3140 fn from(node: LetStmt) -> Stmt {
3144 impl AstNode for Stmt {
3145 fn can_cast(kind: SyntaxKind) -> bool {
3147 EXPR_STMT | LET_STMT => true,
3151 fn cast(syntax: SyntaxNode) -> Option<Self> {
3152 let res = match syntax.kind() {
3153 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
3154 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
3159 fn syntax(&self) -> &SyntaxNode {
3161 Stmt::ExprStmt(it) => &it.syntax,
3162 Stmt::LetStmt(it) => &it.syntax,
3167 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3168 pub struct StructDef {
3169 pub(crate) syntax: SyntaxNode,
3171 impl AstNode for StructDef {
3172 fn can_cast(kind: SyntaxKind) -> bool {
3178 fn cast(syntax: SyntaxNode) -> Option<Self> {
3179 if Self::can_cast(syntax.kind()) {
3180 Some(Self { syntax })
3185 fn syntax(&self) -> &SyntaxNode {
3189 impl ast::VisibilityOwner for StructDef {}
3190 impl ast::NameOwner for StructDef {}
3191 impl ast::TypeParamsOwner for StructDef {}
3192 impl ast::AttrsOwner for StructDef {}
3193 impl ast::DocCommentsOwner for StructDef {}
3195 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3196 pub struct TokenTree {
3197 pub(crate) syntax: SyntaxNode,
3199 impl AstNode for TokenTree {
3200 fn can_cast(kind: SyntaxKind) -> bool {
3206 fn cast(syntax: SyntaxNode) -> Option<Self> {
3207 if Self::can_cast(syntax.kind()) {
3208 Some(Self { syntax })
3213 fn syntax(&self) -> &SyntaxNode {
3218 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3219 pub struct TraitDef {
3220 pub(crate) syntax: SyntaxNode,
3222 impl AstNode for TraitDef {
3223 fn can_cast(kind: SyntaxKind) -> bool {
3229 fn cast(syntax: SyntaxNode) -> Option<Self> {
3230 if Self::can_cast(syntax.kind()) {
3231 Some(Self { syntax })
3236 fn syntax(&self) -> &SyntaxNode {
3240 impl ast::VisibilityOwner for TraitDef {}
3241 impl ast::NameOwner for TraitDef {}
3242 impl ast::AttrsOwner for TraitDef {}
3243 impl ast::DocCommentsOwner for TraitDef {}
3244 impl ast::TypeParamsOwner for TraitDef {}
3245 impl ast::TypeBoundsOwner for TraitDef {}
3247 pub fn item_list(&self) -> Option<ItemList> {
3248 AstChildren::new(&self.syntax).next()
3251 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3252 pub struct TryBlockExpr {
3253 pub(crate) syntax: SyntaxNode,
3255 impl AstNode for TryBlockExpr {
3256 fn can_cast(kind: SyntaxKind) -> bool {
3258 TRY_BLOCK_EXPR => true,
3262 fn cast(syntax: SyntaxNode) -> Option<Self> {
3263 if Self::can_cast(syntax.kind()) {
3264 Some(Self { syntax })
3269 fn syntax(&self) -> &SyntaxNode {
3274 pub fn body(&self) -> Option<BlockExpr> {
3275 AstChildren::new(&self.syntax).next()
3278 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3279 pub struct TryExpr {
3280 pub(crate) syntax: SyntaxNode,
3282 impl AstNode for TryExpr {
3283 fn can_cast(kind: SyntaxKind) -> bool {
3289 fn cast(syntax: SyntaxNode) -> Option<Self> {
3290 if Self::can_cast(syntax.kind()) {
3291 Some(Self { syntax })
3296 fn syntax(&self) -> &SyntaxNode {
3301 pub fn expr(&self) -> Option<Expr> {
3302 AstChildren::new(&self.syntax).next()
3305 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3306 pub struct TupleExpr {
3307 pub(crate) syntax: SyntaxNode,
3309 impl AstNode for TupleExpr {
3310 fn can_cast(kind: SyntaxKind) -> bool {
3316 fn cast(syntax: SyntaxNode) -> Option<Self> {
3317 if Self::can_cast(syntax.kind()) {
3318 Some(Self { syntax })
3323 fn syntax(&self) -> &SyntaxNode {
3328 pub fn exprs(&self) -> AstChildren<Expr> {
3329 AstChildren::new(&self.syntax)
3332 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3333 pub struct TupleFieldDef {
3334 pub(crate) syntax: SyntaxNode,
3336 impl AstNode for TupleFieldDef {
3337 fn can_cast(kind: SyntaxKind) -> bool {
3339 TUPLE_FIELD_DEF => true,
3343 fn cast(syntax: SyntaxNode) -> Option<Self> {
3344 if Self::can_cast(syntax.kind()) {
3345 Some(Self { syntax })
3350 fn syntax(&self) -> &SyntaxNode {
3354 impl ast::VisibilityOwner for TupleFieldDef {}
3355 impl ast::AttrsOwner for TupleFieldDef {}
3356 impl TupleFieldDef {
3357 pub fn type_ref(&self) -> Option<TypeRef> {
3358 AstChildren::new(&self.syntax).next()
3361 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3362 pub struct TupleFieldDefList {
3363 pub(crate) syntax: SyntaxNode,
3365 impl AstNode for TupleFieldDefList {
3366 fn can_cast(kind: SyntaxKind) -> bool {
3368 TUPLE_FIELD_DEF_LIST => true,
3372 fn cast(syntax: SyntaxNode) -> Option<Self> {
3373 if Self::can_cast(syntax.kind()) {
3374 Some(Self { syntax })
3379 fn syntax(&self) -> &SyntaxNode {
3383 impl TupleFieldDefList {
3384 pub fn fields(&self) -> AstChildren<TupleFieldDef> {
3385 AstChildren::new(&self.syntax)
3388 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3389 pub struct TuplePat {
3390 pub(crate) syntax: SyntaxNode,
3392 impl AstNode for TuplePat {
3393 fn can_cast(kind: SyntaxKind) -> bool {
3399 fn cast(syntax: SyntaxNode) -> Option<Self> {
3400 if Self::can_cast(syntax.kind()) {
3401 Some(Self { syntax })
3406 fn syntax(&self) -> &SyntaxNode {
3411 pub fn args(&self) -> AstChildren<Pat> {
3412 AstChildren::new(&self.syntax)
3415 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3416 pub struct TupleStructPat {
3417 pub(crate) syntax: SyntaxNode,
3419 impl AstNode for TupleStructPat {
3420 fn can_cast(kind: SyntaxKind) -> bool {
3422 TUPLE_STRUCT_PAT => true,
3426 fn cast(syntax: SyntaxNode) -> Option<Self> {
3427 if Self::can_cast(syntax.kind()) {
3428 Some(Self { syntax })
3433 fn syntax(&self) -> &SyntaxNode {
3437 impl TupleStructPat {
3438 pub fn args(&self) -> AstChildren<Pat> {
3439 AstChildren::new(&self.syntax)
3441 pub fn path(&self) -> Option<Path> {
3442 AstChildren::new(&self.syntax).next()
3445 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3446 pub struct TupleType {
3447 pub(crate) syntax: SyntaxNode,
3449 impl AstNode for TupleType {
3450 fn can_cast(kind: SyntaxKind) -> bool {
3456 fn cast(syntax: SyntaxNode) -> Option<Self> {
3457 if Self::can_cast(syntax.kind()) {
3458 Some(Self { syntax })
3463 fn syntax(&self) -> &SyntaxNode {
3468 pub fn fields(&self) -> AstChildren<TypeRef> {
3469 AstChildren::new(&self.syntax)
3472 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3473 pub struct TypeAliasDef {
3474 pub(crate) syntax: SyntaxNode,
3476 impl AstNode for TypeAliasDef {
3477 fn can_cast(kind: SyntaxKind) -> bool {
3479 TYPE_ALIAS_DEF => true,
3483 fn cast(syntax: SyntaxNode) -> Option<Self> {
3484 if Self::can_cast(syntax.kind()) {
3485 Some(Self { syntax })
3490 fn syntax(&self) -> &SyntaxNode {
3494 impl ast::VisibilityOwner for TypeAliasDef {}
3495 impl ast::NameOwner for TypeAliasDef {}
3496 impl ast::TypeParamsOwner for TypeAliasDef {}
3497 impl ast::AttrsOwner for TypeAliasDef {}
3498 impl ast::DocCommentsOwner for TypeAliasDef {}
3499 impl ast::TypeBoundsOwner for TypeAliasDef {}
3501 pub fn type_ref(&self) -> Option<TypeRef> {
3502 AstChildren::new(&self.syntax).next()
3505 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3506 pub struct TypeArg {
3507 pub(crate) syntax: SyntaxNode,
3509 impl AstNode for TypeArg {
3510 fn can_cast(kind: SyntaxKind) -> bool {
3516 fn cast(syntax: SyntaxNode) -> Option<Self> {
3517 if Self::can_cast(syntax.kind()) {
3518 Some(Self { syntax })
3523 fn syntax(&self) -> &SyntaxNode {
3528 pub fn type_ref(&self) -> Option<TypeRef> {
3529 AstChildren::new(&self.syntax).next()
3532 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3533 pub struct TypeArgList {
3534 pub(crate) syntax: SyntaxNode,
3536 impl AstNode for TypeArgList {
3537 fn can_cast(kind: SyntaxKind) -> bool {
3539 TYPE_ARG_LIST => true,
3543 fn cast(syntax: SyntaxNode) -> Option<Self> {
3544 if Self::can_cast(syntax.kind()) {
3545 Some(Self { syntax })
3550 fn syntax(&self) -> &SyntaxNode {
3555 pub fn type_args(&self) -> AstChildren<TypeArg> {
3556 AstChildren::new(&self.syntax)
3558 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3559 AstChildren::new(&self.syntax)
3561 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3562 AstChildren::new(&self.syntax)
3565 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3566 pub struct TypeBound {
3567 pub(crate) syntax: SyntaxNode,
3569 impl AstNode for TypeBound {
3570 fn can_cast(kind: SyntaxKind) -> bool {
3576 fn cast(syntax: SyntaxNode) -> Option<Self> {
3577 if Self::can_cast(syntax.kind()) {
3578 Some(Self { syntax })
3583 fn syntax(&self) -> &SyntaxNode {
3588 pub fn type_ref(&self) -> Option<TypeRef> {
3589 AstChildren::new(&self.syntax).next()
3592 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3593 pub struct TypeBoundList {
3594 pub(crate) syntax: SyntaxNode,
3596 impl AstNode for TypeBoundList {
3597 fn can_cast(kind: SyntaxKind) -> bool {
3599 TYPE_BOUND_LIST => true,
3603 fn cast(syntax: SyntaxNode) -> Option<Self> {
3604 if Self::can_cast(syntax.kind()) {
3605 Some(Self { syntax })
3610 fn syntax(&self) -> &SyntaxNode {
3614 impl TypeBoundList {
3615 pub fn bounds(&self) -> AstChildren<TypeBound> {
3616 AstChildren::new(&self.syntax)
3619 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3620 pub struct TypeParam {
3621 pub(crate) syntax: SyntaxNode,
3623 impl AstNode for TypeParam {
3624 fn can_cast(kind: SyntaxKind) -> bool {
3630 fn cast(syntax: SyntaxNode) -> Option<Self> {
3631 if Self::can_cast(syntax.kind()) {
3632 Some(Self { syntax })
3637 fn syntax(&self) -> &SyntaxNode {
3641 impl ast::NameOwner for TypeParam {}
3642 impl ast::AttrsOwner for TypeParam {}
3643 impl ast::TypeBoundsOwner for TypeParam {}
3645 pub fn default_type(&self) -> Option<TypeRef> {
3646 AstChildren::new(&self.syntax).next()
3649 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3650 pub struct TypeParamList {
3651 pub(crate) syntax: SyntaxNode,
3653 impl AstNode for TypeParamList {
3654 fn can_cast(kind: SyntaxKind) -> bool {
3656 TYPE_PARAM_LIST => true,
3660 fn cast(syntax: SyntaxNode) -> Option<Self> {
3661 if Self::can_cast(syntax.kind()) {
3662 Some(Self { syntax })
3667 fn syntax(&self) -> &SyntaxNode {
3671 impl TypeParamList {
3672 pub fn type_params(&self) -> AstChildren<TypeParam> {
3673 AstChildren::new(&self.syntax)
3675 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3676 AstChildren::new(&self.syntax)
3679 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3681 ParenType(ParenType),
3682 TupleType(TupleType),
3683 NeverType(NeverType),
3685 PointerType(PointerType),
3686 ArrayType(ArrayType),
3687 SliceType(SliceType),
3688 ReferenceType(ReferenceType),
3689 PlaceholderType(PlaceholderType),
3690 FnPointerType(FnPointerType),
3692 ImplTraitType(ImplTraitType),
3693 DynTraitType(DynTraitType),
3695 impl From<ParenType> for TypeRef {
3696 fn from(node: ParenType) -> TypeRef {
3697 TypeRef::ParenType(node)
3700 impl From<TupleType> for TypeRef {
3701 fn from(node: TupleType) -> TypeRef {
3702 TypeRef::TupleType(node)
3705 impl From<NeverType> for TypeRef {
3706 fn from(node: NeverType) -> TypeRef {
3707 TypeRef::NeverType(node)
3710 impl From<PathType> for TypeRef {
3711 fn from(node: PathType) -> TypeRef {
3712 TypeRef::PathType(node)
3715 impl From<PointerType> for TypeRef {
3716 fn from(node: PointerType) -> TypeRef {
3717 TypeRef::PointerType(node)
3720 impl From<ArrayType> for TypeRef {
3721 fn from(node: ArrayType) -> TypeRef {
3722 TypeRef::ArrayType(node)
3725 impl From<SliceType> for TypeRef {
3726 fn from(node: SliceType) -> TypeRef {
3727 TypeRef::SliceType(node)
3730 impl From<ReferenceType> for TypeRef {
3731 fn from(node: ReferenceType) -> TypeRef {
3732 TypeRef::ReferenceType(node)
3735 impl From<PlaceholderType> for TypeRef {
3736 fn from(node: PlaceholderType) -> TypeRef {
3737 TypeRef::PlaceholderType(node)
3740 impl From<FnPointerType> for TypeRef {
3741 fn from(node: FnPointerType) -> TypeRef {
3742 TypeRef::FnPointerType(node)
3745 impl From<ForType> for TypeRef {
3746 fn from(node: ForType) -> TypeRef {
3747 TypeRef::ForType(node)
3750 impl From<ImplTraitType> for TypeRef {
3751 fn from(node: ImplTraitType) -> TypeRef {
3752 TypeRef::ImplTraitType(node)
3755 impl From<DynTraitType> for TypeRef {
3756 fn from(node: DynTraitType) -> TypeRef {
3757 TypeRef::DynTraitType(node)
3760 impl AstNode for TypeRef {
3761 fn can_cast(kind: SyntaxKind) -> bool {
3763 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3764 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3765 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3769 fn cast(syntax: SyntaxNode) -> Option<Self> {
3770 let res = match syntax.kind() {
3771 PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
3772 TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
3773 NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
3774 PATH_TYPE => TypeRef::PathType(PathType { syntax }),
3775 POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
3776 ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
3777 SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
3778 REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
3779 PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
3780 FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
3781 FOR_TYPE => TypeRef::ForType(ForType { syntax }),
3782 IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
3783 DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
3788 fn syntax(&self) -> &SyntaxNode {
3790 TypeRef::ParenType(it) => &it.syntax,
3791 TypeRef::TupleType(it) => &it.syntax,
3792 TypeRef::NeverType(it) => &it.syntax,
3793 TypeRef::PathType(it) => &it.syntax,
3794 TypeRef::PointerType(it) => &it.syntax,
3795 TypeRef::ArrayType(it) => &it.syntax,
3796 TypeRef::SliceType(it) => &it.syntax,
3797 TypeRef::ReferenceType(it) => &it.syntax,
3798 TypeRef::PlaceholderType(it) => &it.syntax,
3799 TypeRef::FnPointerType(it) => &it.syntax,
3800 TypeRef::ForType(it) => &it.syntax,
3801 TypeRef::ImplTraitType(it) => &it.syntax,
3802 TypeRef::DynTraitType(it) => &it.syntax,
3807 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3808 pub struct UnionDef {
3809 pub(crate) syntax: SyntaxNode,
3811 impl AstNode for UnionDef {
3812 fn can_cast(kind: SyntaxKind) -> bool {
3818 fn cast(syntax: SyntaxNode) -> Option<Self> {
3819 if Self::can_cast(syntax.kind()) {
3820 Some(Self { syntax })
3825 fn syntax(&self) -> &SyntaxNode {
3829 impl ast::VisibilityOwner for UnionDef {}
3830 impl ast::NameOwner for UnionDef {}
3831 impl ast::TypeParamsOwner for UnionDef {}
3832 impl ast::AttrsOwner for UnionDef {}
3833 impl ast::DocCommentsOwner for UnionDef {}
3835 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> {
3836 AstChildren::new(&self.syntax).next()
3839 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3840 pub struct UseItem {
3841 pub(crate) syntax: SyntaxNode,
3843 impl AstNode for UseItem {
3844 fn can_cast(kind: SyntaxKind) -> bool {
3850 fn cast(syntax: SyntaxNode) -> Option<Self> {
3851 if Self::can_cast(syntax.kind()) {
3852 Some(Self { syntax })
3857 fn syntax(&self) -> &SyntaxNode {
3861 impl ast::AttrsOwner for UseItem {}
3863 pub fn use_tree(&self) -> Option<UseTree> {
3864 AstChildren::new(&self.syntax).next()
3867 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3868 pub struct UseTree {
3869 pub(crate) syntax: SyntaxNode,
3871 impl AstNode for UseTree {
3872 fn can_cast(kind: SyntaxKind) -> bool {
3878 fn cast(syntax: SyntaxNode) -> Option<Self> {
3879 if Self::can_cast(syntax.kind()) {
3880 Some(Self { syntax })
3885 fn syntax(&self) -> &SyntaxNode {
3890 pub fn path(&self) -> Option<Path> {
3891 AstChildren::new(&self.syntax).next()
3893 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3894 AstChildren::new(&self.syntax).next()
3896 pub fn alias(&self) -> Option<Alias> {
3897 AstChildren::new(&self.syntax).next()
3900 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3901 pub struct UseTreeList {
3902 pub(crate) syntax: SyntaxNode,
3904 impl AstNode for UseTreeList {
3905 fn can_cast(kind: SyntaxKind) -> bool {
3907 USE_TREE_LIST => true,
3911 fn cast(syntax: SyntaxNode) -> Option<Self> {
3912 if Self::can_cast(syntax.kind()) {
3913 Some(Self { syntax })
3918 fn syntax(&self) -> &SyntaxNode {
3923 pub fn use_trees(&self) -> AstChildren<UseTree> {
3924 AstChildren::new(&self.syntax)
3927 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3928 pub struct Visibility {
3929 pub(crate) syntax: SyntaxNode,
3931 impl AstNode for Visibility {
3932 fn can_cast(kind: SyntaxKind) -> bool {
3938 fn cast(syntax: SyntaxNode) -> Option<Self> {
3939 if Self::can_cast(syntax.kind()) {
3940 Some(Self { syntax })
3945 fn syntax(&self) -> &SyntaxNode {
3950 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3951 pub struct WhereClause {
3952 pub(crate) syntax: SyntaxNode,
3954 impl AstNode for WhereClause {
3955 fn can_cast(kind: SyntaxKind) -> bool {
3957 WHERE_CLAUSE => true,
3961 fn cast(syntax: SyntaxNode) -> Option<Self> {
3962 if Self::can_cast(syntax.kind()) {
3963 Some(Self { syntax })
3968 fn syntax(&self) -> &SyntaxNode {
3973 pub fn predicates(&self) -> AstChildren<WherePred> {
3974 AstChildren::new(&self.syntax)
3977 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3978 pub struct WherePred {
3979 pub(crate) syntax: SyntaxNode,
3981 impl AstNode for WherePred {
3982 fn can_cast(kind: SyntaxKind) -> bool {
3988 fn cast(syntax: SyntaxNode) -> Option<Self> {
3989 if Self::can_cast(syntax.kind()) {
3990 Some(Self { syntax })
3995 fn syntax(&self) -> &SyntaxNode {
3999 impl ast::TypeBoundsOwner for WherePred {}
4001 pub fn type_ref(&self) -> Option<TypeRef> {
4002 AstChildren::new(&self.syntax).next()
4005 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
4006 pub struct WhileExpr {
4007 pub(crate) syntax: SyntaxNode,
4009 impl AstNode for WhileExpr {
4010 fn can_cast(kind: SyntaxKind) -> bool {
4016 fn cast(syntax: SyntaxNode) -> Option<Self> {
4017 if Self::can_cast(syntax.kind()) {
4018 Some(Self { syntax })
4023 fn syntax(&self) -> &SyntaxNode {
4027 impl ast::LoopBodyOwner for WhileExpr {}
4029 pub fn condition(&self) -> Option<Condition> {
4030 AstChildren::new(&self.syntax).next()