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),
1862 TypeAliasDef(TypeAliasDef),
1863 ImplBlock(ImplBlock),
1865 ExternCrateItem(ExternCrateItem),
1867 StaticDef(StaticDef),
1870 impl From<StructDef> for ModuleItem {
1871 fn from(node: StructDef) -> ModuleItem {
1872 ModuleItem::StructDef(node)
1875 impl From<EnumDef> for ModuleItem {
1876 fn from(node: EnumDef) -> ModuleItem {
1877 ModuleItem::EnumDef(node)
1880 impl From<FnDef> for ModuleItem {
1881 fn from(node: FnDef) -> ModuleItem {
1882 ModuleItem::FnDef(node)
1885 impl From<TraitDef> for ModuleItem {
1886 fn from(node: TraitDef) -> ModuleItem {
1887 ModuleItem::TraitDef(node)
1890 impl From<TypeAliasDef> for ModuleItem {
1891 fn from(node: TypeAliasDef) -> ModuleItem {
1892 ModuleItem::TypeAliasDef(node)
1895 impl From<ImplBlock> for ModuleItem {
1896 fn from(node: ImplBlock) -> ModuleItem {
1897 ModuleItem::ImplBlock(node)
1900 impl From<UseItem> for ModuleItem {
1901 fn from(node: UseItem) -> ModuleItem {
1902 ModuleItem::UseItem(node)
1905 impl From<ExternCrateItem> for ModuleItem {
1906 fn from(node: ExternCrateItem) -> ModuleItem {
1907 ModuleItem::ExternCrateItem(node)
1910 impl From<ConstDef> for ModuleItem {
1911 fn from(node: ConstDef) -> ModuleItem {
1912 ModuleItem::ConstDef(node)
1915 impl From<StaticDef> for ModuleItem {
1916 fn from(node: StaticDef) -> ModuleItem {
1917 ModuleItem::StaticDef(node)
1920 impl From<Module> for ModuleItem {
1921 fn from(node: Module) -> ModuleItem {
1922 ModuleItem::Module(node)
1925 impl AstNode for ModuleItem {
1926 fn can_cast(kind: SyntaxKind) -> bool {
1928 STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM
1929 | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1933 fn cast(syntax: SyntaxNode) -> Option<Self> {
1934 let res = match syntax.kind() {
1935 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
1936 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
1937 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
1938 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
1939 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
1940 IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
1941 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
1942 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
1943 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
1944 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
1945 MODULE => ModuleItem::Module(Module { syntax }),
1950 fn syntax(&self) -> &SyntaxNode {
1952 ModuleItem::StructDef(it) => &it.syntax,
1953 ModuleItem::EnumDef(it) => &it.syntax,
1954 ModuleItem::FnDef(it) => &it.syntax,
1955 ModuleItem::TraitDef(it) => &it.syntax,
1956 ModuleItem::TypeAliasDef(it) => &it.syntax,
1957 ModuleItem::ImplBlock(it) => &it.syntax,
1958 ModuleItem::UseItem(it) => &it.syntax,
1959 ModuleItem::ExternCrateItem(it) => &it.syntax,
1960 ModuleItem::ConstDef(it) => &it.syntax,
1961 ModuleItem::StaticDef(it) => &it.syntax,
1962 ModuleItem::Module(it) => &it.syntax,
1966 impl ast::AttrsOwner for ModuleItem {}
1968 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1970 pub(crate) syntax: SyntaxNode,
1972 impl AstNode for Name {
1973 fn can_cast(kind: SyntaxKind) -> bool {
1979 fn cast(syntax: SyntaxNode) -> Option<Self> {
1980 if Self::can_cast(syntax.kind()) {
1981 Some(Self { syntax })
1986 fn syntax(&self) -> &SyntaxNode {
1991 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1992 pub struct NameRef {
1993 pub(crate) syntax: SyntaxNode,
1995 impl AstNode for NameRef {
1996 fn can_cast(kind: SyntaxKind) -> bool {
2002 fn cast(syntax: SyntaxNode) -> Option<Self> {
2003 if Self::can_cast(syntax.kind()) {
2004 Some(Self { syntax })
2009 fn syntax(&self) -> &SyntaxNode {
2014 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2015 pub struct NeverType {
2016 pub(crate) syntax: SyntaxNode,
2018 impl AstNode for NeverType {
2019 fn can_cast(kind: SyntaxKind) -> bool {
2025 fn cast(syntax: SyntaxNode) -> Option<Self> {
2026 if Self::can_cast(syntax.kind()) {
2027 Some(Self { syntax })
2032 fn syntax(&self) -> &SyntaxNode {
2037 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2038 pub enum NominalDef {
2039 StructDef(StructDef),
2042 impl From<StructDef> for NominalDef {
2043 fn from(node: StructDef) -> NominalDef {
2044 NominalDef::StructDef(node)
2047 impl From<EnumDef> for NominalDef {
2048 fn from(node: EnumDef) -> NominalDef {
2049 NominalDef::EnumDef(node)
2052 impl AstNode for NominalDef {
2053 fn can_cast(kind: SyntaxKind) -> bool {
2055 STRUCT_DEF | ENUM_DEF => true,
2059 fn cast(syntax: SyntaxNode) -> Option<Self> {
2060 let res = match syntax.kind() {
2061 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
2062 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
2067 fn syntax(&self) -> &SyntaxNode {
2069 NominalDef::StructDef(it) => &it.syntax,
2070 NominalDef::EnumDef(it) => &it.syntax,
2074 impl ast::NameOwner for NominalDef {}
2075 impl ast::TypeParamsOwner for NominalDef {}
2076 impl ast::AttrsOwner for NominalDef {}
2078 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2080 pub(crate) syntax: SyntaxNode,
2082 impl AstNode for Param {
2083 fn can_cast(kind: SyntaxKind) -> bool {
2089 fn cast(syntax: SyntaxNode) -> Option<Self> {
2090 if Self::can_cast(syntax.kind()) {
2091 Some(Self { syntax })
2096 fn syntax(&self) -> &SyntaxNode {
2100 impl ast::TypeAscriptionOwner for Param {}
2101 impl ast::AttrsOwner for Param {}
2103 pub fn pat(&self) -> Option<Pat> {
2104 AstChildren::new(&self.syntax).next()
2107 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2108 pub struct ParamList {
2109 pub(crate) syntax: SyntaxNode,
2111 impl AstNode for ParamList {
2112 fn can_cast(kind: SyntaxKind) -> bool {
2118 fn cast(syntax: SyntaxNode) -> Option<Self> {
2119 if Self::can_cast(syntax.kind()) {
2120 Some(Self { syntax })
2125 fn syntax(&self) -> &SyntaxNode {
2130 pub fn params(&self) -> AstChildren<Param> {
2131 AstChildren::new(&self.syntax)
2133 pub fn self_param(&self) -> Option<SelfParam> {
2134 AstChildren::new(&self.syntax).next()
2137 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2138 pub struct ParenExpr {
2139 pub(crate) syntax: SyntaxNode,
2141 impl AstNode for ParenExpr {
2142 fn can_cast(kind: SyntaxKind) -> bool {
2148 fn cast(syntax: SyntaxNode) -> Option<Self> {
2149 if Self::can_cast(syntax.kind()) {
2150 Some(Self { syntax })
2155 fn syntax(&self) -> &SyntaxNode {
2160 pub fn expr(&self) -> Option<Expr> {
2161 AstChildren::new(&self.syntax).next()
2164 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2165 pub struct ParenType {
2166 pub(crate) syntax: SyntaxNode,
2168 impl AstNode for ParenType {
2169 fn can_cast(kind: SyntaxKind) -> bool {
2175 fn cast(syntax: SyntaxNode) -> Option<Self> {
2176 if Self::can_cast(syntax.kind()) {
2177 Some(Self { syntax })
2182 fn syntax(&self) -> &SyntaxNode {
2187 pub fn type_ref(&self) -> Option<TypeRef> {
2188 AstChildren::new(&self.syntax).next()
2191 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2196 PlaceholderPat(PlaceholderPat),
2197 DotDotPat(DotDotPat),
2199 RecordPat(RecordPat),
2200 TupleStructPat(TupleStructPat),
2204 LiteralPat(LiteralPat),
2206 impl From<RefPat> for Pat {
2207 fn from(node: RefPat) -> Pat {
2211 impl From<BoxPat> for Pat {
2212 fn from(node: BoxPat) -> Pat {
2216 impl From<BindPat> for Pat {
2217 fn from(node: BindPat) -> Pat {
2221 impl From<PlaceholderPat> for Pat {
2222 fn from(node: PlaceholderPat) -> Pat {
2223 Pat::PlaceholderPat(node)
2226 impl From<DotDotPat> for Pat {
2227 fn from(node: DotDotPat) -> Pat {
2228 Pat::DotDotPat(node)
2231 impl From<PathPat> for Pat {
2232 fn from(node: PathPat) -> Pat {
2236 impl From<RecordPat> for Pat {
2237 fn from(node: RecordPat) -> Pat {
2238 Pat::RecordPat(node)
2241 impl From<TupleStructPat> for Pat {
2242 fn from(node: TupleStructPat) -> Pat {
2243 Pat::TupleStructPat(node)
2246 impl From<TuplePat> for Pat {
2247 fn from(node: TuplePat) -> Pat {
2251 impl From<SlicePat> for Pat {
2252 fn from(node: SlicePat) -> Pat {
2256 impl From<RangePat> for Pat {
2257 fn from(node: RangePat) -> Pat {
2261 impl From<LiteralPat> for Pat {
2262 fn from(node: LiteralPat) -> Pat {
2263 Pat::LiteralPat(node)
2266 impl AstNode for Pat {
2267 fn can_cast(kind: SyntaxKind) -> bool {
2269 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT
2270 | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => {
2276 fn cast(syntax: SyntaxNode) -> Option<Self> {
2277 let res = match syntax.kind() {
2278 REF_PAT => Pat::RefPat(RefPat { syntax }),
2279 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2280 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2281 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2282 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
2283 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2284 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2285 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2286 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2287 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2288 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2289 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2294 fn syntax(&self) -> &SyntaxNode {
2296 Pat::RefPat(it) => &it.syntax,
2297 Pat::BoxPat(it) => &it.syntax,
2298 Pat::BindPat(it) => &it.syntax,
2299 Pat::PlaceholderPat(it) => &it.syntax,
2300 Pat::DotDotPat(it) => &it.syntax,
2301 Pat::PathPat(it) => &it.syntax,
2302 Pat::RecordPat(it) => &it.syntax,
2303 Pat::TupleStructPat(it) => &it.syntax,
2304 Pat::TuplePat(it) => &it.syntax,
2305 Pat::SlicePat(it) => &it.syntax,
2306 Pat::RangePat(it) => &it.syntax,
2307 Pat::LiteralPat(it) => &it.syntax,
2312 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2314 pub(crate) syntax: SyntaxNode,
2316 impl AstNode for Path {
2317 fn can_cast(kind: SyntaxKind) -> bool {
2323 fn cast(syntax: SyntaxNode) -> Option<Self> {
2324 if Self::can_cast(syntax.kind()) {
2325 Some(Self { syntax })
2330 fn syntax(&self) -> &SyntaxNode {
2335 pub fn segment(&self) -> Option<PathSegment> {
2336 AstChildren::new(&self.syntax).next()
2338 pub fn qualifier(&self) -> Option<Path> {
2339 AstChildren::new(&self.syntax).next()
2342 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2343 pub struct PathExpr {
2344 pub(crate) syntax: SyntaxNode,
2346 impl AstNode for PathExpr {
2347 fn can_cast(kind: SyntaxKind) -> bool {
2353 fn cast(syntax: SyntaxNode) -> Option<Self> {
2354 if Self::can_cast(syntax.kind()) {
2355 Some(Self { syntax })
2360 fn syntax(&self) -> &SyntaxNode {
2365 pub fn path(&self) -> Option<Path> {
2366 AstChildren::new(&self.syntax).next()
2369 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2370 pub struct PathPat {
2371 pub(crate) syntax: SyntaxNode,
2373 impl AstNode for PathPat {
2374 fn can_cast(kind: SyntaxKind) -> bool {
2380 fn cast(syntax: SyntaxNode) -> Option<Self> {
2381 if Self::can_cast(syntax.kind()) {
2382 Some(Self { syntax })
2387 fn syntax(&self) -> &SyntaxNode {
2392 pub fn path(&self) -> Option<Path> {
2393 AstChildren::new(&self.syntax).next()
2396 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2397 pub struct PathSegment {
2398 pub(crate) syntax: SyntaxNode,
2400 impl AstNode for PathSegment {
2401 fn can_cast(kind: SyntaxKind) -> bool {
2403 PATH_SEGMENT => true,
2407 fn cast(syntax: SyntaxNode) -> Option<Self> {
2408 if Self::can_cast(syntax.kind()) {
2409 Some(Self { syntax })
2414 fn syntax(&self) -> &SyntaxNode {
2419 pub fn name_ref(&self) -> Option<NameRef> {
2420 AstChildren::new(&self.syntax).next()
2422 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2423 AstChildren::new(&self.syntax).next()
2425 pub fn param_list(&self) -> Option<ParamList> {
2426 AstChildren::new(&self.syntax).next()
2428 pub fn ret_type(&self) -> Option<RetType> {
2429 AstChildren::new(&self.syntax).next()
2431 pub fn path_type(&self) -> Option<PathType> {
2432 AstChildren::new(&self.syntax).next()
2435 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2436 pub struct PathType {
2437 pub(crate) syntax: SyntaxNode,
2439 impl AstNode for PathType {
2440 fn can_cast(kind: SyntaxKind) -> bool {
2446 fn cast(syntax: SyntaxNode) -> Option<Self> {
2447 if Self::can_cast(syntax.kind()) {
2448 Some(Self { syntax })
2453 fn syntax(&self) -> &SyntaxNode {
2458 pub fn path(&self) -> Option<Path> {
2459 AstChildren::new(&self.syntax).next()
2462 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2463 pub struct PlaceholderPat {
2464 pub(crate) syntax: SyntaxNode,
2466 impl AstNode for PlaceholderPat {
2467 fn can_cast(kind: SyntaxKind) -> bool {
2469 PLACEHOLDER_PAT => true,
2473 fn cast(syntax: SyntaxNode) -> Option<Self> {
2474 if Self::can_cast(syntax.kind()) {
2475 Some(Self { syntax })
2480 fn syntax(&self) -> &SyntaxNode {
2484 impl PlaceholderPat {}
2485 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2486 pub struct PlaceholderType {
2487 pub(crate) syntax: SyntaxNode,
2489 impl AstNode for PlaceholderType {
2490 fn can_cast(kind: SyntaxKind) -> bool {
2492 PLACEHOLDER_TYPE => true,
2496 fn cast(syntax: SyntaxNode) -> Option<Self> {
2497 if Self::can_cast(syntax.kind()) {
2498 Some(Self { syntax })
2503 fn syntax(&self) -> &SyntaxNode {
2507 impl PlaceholderType {}
2508 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2509 pub struct PointerType {
2510 pub(crate) syntax: SyntaxNode,
2512 impl AstNode for PointerType {
2513 fn can_cast(kind: SyntaxKind) -> bool {
2515 POINTER_TYPE => true,
2519 fn cast(syntax: SyntaxNode) -> Option<Self> {
2520 if Self::can_cast(syntax.kind()) {
2521 Some(Self { syntax })
2526 fn syntax(&self) -> &SyntaxNode {
2531 pub fn type_ref(&self) -> Option<TypeRef> {
2532 AstChildren::new(&self.syntax).next()
2535 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2536 pub struct PrefixExpr {
2537 pub(crate) syntax: SyntaxNode,
2539 impl AstNode for PrefixExpr {
2540 fn can_cast(kind: SyntaxKind) -> bool {
2542 PREFIX_EXPR => true,
2546 fn cast(syntax: SyntaxNode) -> Option<Self> {
2547 if Self::can_cast(syntax.kind()) {
2548 Some(Self { syntax })
2553 fn syntax(&self) -> &SyntaxNode {
2558 pub fn expr(&self) -> Option<Expr> {
2559 AstChildren::new(&self.syntax).next()
2562 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2563 pub struct RangeExpr {
2564 pub(crate) syntax: SyntaxNode,
2566 impl AstNode for RangeExpr {
2567 fn can_cast(kind: SyntaxKind) -> bool {
2573 fn cast(syntax: SyntaxNode) -> Option<Self> {
2574 if Self::can_cast(syntax.kind()) {
2575 Some(Self { syntax })
2580 fn syntax(&self) -> &SyntaxNode {
2585 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2586 pub struct RangePat {
2587 pub(crate) syntax: SyntaxNode,
2589 impl AstNode for RangePat {
2590 fn can_cast(kind: SyntaxKind) -> bool {
2596 fn cast(syntax: SyntaxNode) -> Option<Self> {
2597 if Self::can_cast(syntax.kind()) {
2598 Some(Self { syntax })
2603 fn syntax(&self) -> &SyntaxNode {
2608 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2609 pub struct RecordField {
2610 pub(crate) syntax: SyntaxNode,
2612 impl AstNode for RecordField {
2613 fn can_cast(kind: SyntaxKind) -> bool {
2615 RECORD_FIELD => true,
2619 fn cast(syntax: SyntaxNode) -> Option<Self> {
2620 if Self::can_cast(syntax.kind()) {
2621 Some(Self { syntax })
2626 fn syntax(&self) -> &SyntaxNode {
2631 pub fn name_ref(&self) -> Option<NameRef> {
2632 AstChildren::new(&self.syntax).next()
2634 pub fn expr(&self) -> Option<Expr> {
2635 AstChildren::new(&self.syntax).next()
2638 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2639 pub struct RecordFieldDef {
2640 pub(crate) syntax: SyntaxNode,
2642 impl AstNode for RecordFieldDef {
2643 fn can_cast(kind: SyntaxKind) -> bool {
2645 RECORD_FIELD_DEF => true,
2649 fn cast(syntax: SyntaxNode) -> Option<Self> {
2650 if Self::can_cast(syntax.kind()) {
2651 Some(Self { syntax })
2656 fn syntax(&self) -> &SyntaxNode {
2660 impl ast::VisibilityOwner for RecordFieldDef {}
2661 impl ast::NameOwner for RecordFieldDef {}
2662 impl ast::AttrsOwner for RecordFieldDef {}
2663 impl ast::DocCommentsOwner for RecordFieldDef {}
2664 impl ast::TypeAscriptionOwner for RecordFieldDef {}
2665 impl RecordFieldDef {}
2666 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2667 pub struct RecordFieldDefList {
2668 pub(crate) syntax: SyntaxNode,
2670 impl AstNode for RecordFieldDefList {
2671 fn can_cast(kind: SyntaxKind) -> bool {
2673 RECORD_FIELD_DEF_LIST => true,
2677 fn cast(syntax: SyntaxNode) -> Option<Self> {
2678 if Self::can_cast(syntax.kind()) {
2679 Some(Self { syntax })
2684 fn syntax(&self) -> &SyntaxNode {
2688 impl RecordFieldDefList {
2689 pub fn fields(&self) -> AstChildren<RecordFieldDef> {
2690 AstChildren::new(&self.syntax)
2693 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2694 pub struct RecordFieldList {
2695 pub(crate) syntax: SyntaxNode,
2697 impl AstNode for RecordFieldList {
2698 fn can_cast(kind: SyntaxKind) -> bool {
2700 RECORD_FIELD_LIST => true,
2704 fn cast(syntax: SyntaxNode) -> Option<Self> {
2705 if Self::can_cast(syntax.kind()) {
2706 Some(Self { syntax })
2711 fn syntax(&self) -> &SyntaxNode {
2715 impl RecordFieldList {
2716 pub fn fields(&self) -> AstChildren<RecordField> {
2717 AstChildren::new(&self.syntax)
2719 pub fn spread(&self) -> Option<Expr> {
2720 AstChildren::new(&self.syntax).next()
2723 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2724 pub struct RecordFieldPat {
2725 pub(crate) syntax: SyntaxNode,
2727 impl AstNode for RecordFieldPat {
2728 fn can_cast(kind: SyntaxKind) -> bool {
2730 RECORD_FIELD_PAT => true,
2734 fn cast(syntax: SyntaxNode) -> Option<Self> {
2735 if Self::can_cast(syntax.kind()) {
2736 Some(Self { syntax })
2741 fn syntax(&self) -> &SyntaxNode {
2745 impl ast::NameOwner for RecordFieldPat {}
2746 impl RecordFieldPat {
2747 pub fn pat(&self) -> Option<Pat> {
2748 AstChildren::new(&self.syntax).next()
2751 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2752 pub struct RecordFieldPatList {
2753 pub(crate) syntax: SyntaxNode,
2755 impl AstNode for RecordFieldPatList {
2756 fn can_cast(kind: SyntaxKind) -> bool {
2758 RECORD_FIELD_PAT_LIST => true,
2762 fn cast(syntax: SyntaxNode) -> Option<Self> {
2763 if Self::can_cast(syntax.kind()) {
2764 Some(Self { syntax })
2769 fn syntax(&self) -> &SyntaxNode {
2773 impl RecordFieldPatList {
2774 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
2775 AstChildren::new(&self.syntax)
2777 pub fn bind_pats(&self) -> AstChildren<BindPat> {
2778 AstChildren::new(&self.syntax)
2781 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2782 pub struct RecordLit {
2783 pub(crate) syntax: SyntaxNode,
2785 impl AstNode for RecordLit {
2786 fn can_cast(kind: SyntaxKind) -> bool {
2792 fn cast(syntax: SyntaxNode) -> Option<Self> {
2793 if Self::can_cast(syntax.kind()) {
2794 Some(Self { syntax })
2799 fn syntax(&self) -> &SyntaxNode {
2804 pub fn path(&self) -> Option<Path> {
2805 AstChildren::new(&self.syntax).next()
2807 pub fn record_field_list(&self) -> Option<RecordFieldList> {
2808 AstChildren::new(&self.syntax).next()
2811 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2812 pub struct RecordPat {
2813 pub(crate) syntax: SyntaxNode,
2815 impl AstNode for RecordPat {
2816 fn can_cast(kind: SyntaxKind) -> bool {
2822 fn cast(syntax: SyntaxNode) -> Option<Self> {
2823 if Self::can_cast(syntax.kind()) {
2824 Some(Self { syntax })
2829 fn syntax(&self) -> &SyntaxNode {
2834 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
2835 AstChildren::new(&self.syntax).next()
2837 pub fn path(&self) -> Option<Path> {
2838 AstChildren::new(&self.syntax).next()
2841 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2842 pub struct RefExpr {
2843 pub(crate) syntax: SyntaxNode,
2845 impl AstNode for RefExpr {
2846 fn can_cast(kind: SyntaxKind) -> bool {
2852 fn cast(syntax: SyntaxNode) -> Option<Self> {
2853 if Self::can_cast(syntax.kind()) {
2854 Some(Self { syntax })
2859 fn syntax(&self) -> &SyntaxNode {
2864 pub fn expr(&self) -> Option<Expr> {
2865 AstChildren::new(&self.syntax).next()
2868 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2870 pub(crate) syntax: SyntaxNode,
2872 impl AstNode for RefPat {
2873 fn can_cast(kind: SyntaxKind) -> bool {
2879 fn cast(syntax: SyntaxNode) -> Option<Self> {
2880 if Self::can_cast(syntax.kind()) {
2881 Some(Self { syntax })
2886 fn syntax(&self) -> &SyntaxNode {
2891 pub fn pat(&self) -> Option<Pat> {
2892 AstChildren::new(&self.syntax).next()
2895 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2896 pub struct ReferenceType {
2897 pub(crate) syntax: SyntaxNode,
2899 impl AstNode for ReferenceType {
2900 fn can_cast(kind: SyntaxKind) -> bool {
2902 REFERENCE_TYPE => true,
2906 fn cast(syntax: SyntaxNode) -> Option<Self> {
2907 if Self::can_cast(syntax.kind()) {
2908 Some(Self { syntax })
2913 fn syntax(&self) -> &SyntaxNode {
2917 impl ReferenceType {
2918 pub fn type_ref(&self) -> Option<TypeRef> {
2919 AstChildren::new(&self.syntax).next()
2922 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2923 pub struct RetType {
2924 pub(crate) syntax: SyntaxNode,
2926 impl AstNode for RetType {
2927 fn can_cast(kind: SyntaxKind) -> bool {
2933 fn cast(syntax: SyntaxNode) -> Option<Self> {
2934 if Self::can_cast(syntax.kind()) {
2935 Some(Self { syntax })
2940 fn syntax(&self) -> &SyntaxNode {
2945 pub fn type_ref(&self) -> Option<TypeRef> {
2946 AstChildren::new(&self.syntax).next()
2949 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2950 pub struct ReturnExpr {
2951 pub(crate) syntax: SyntaxNode,
2953 impl AstNode for ReturnExpr {
2954 fn can_cast(kind: SyntaxKind) -> bool {
2956 RETURN_EXPR => true,
2960 fn cast(syntax: SyntaxNode) -> Option<Self> {
2961 if Self::can_cast(syntax.kind()) {
2962 Some(Self { syntax })
2967 fn syntax(&self) -> &SyntaxNode {
2972 pub fn expr(&self) -> Option<Expr> {
2973 AstChildren::new(&self.syntax).next()
2976 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2977 pub struct SelfParam {
2978 pub(crate) syntax: SyntaxNode,
2980 impl AstNode for SelfParam {
2981 fn can_cast(kind: SyntaxKind) -> bool {
2987 fn cast(syntax: SyntaxNode) -> Option<Self> {
2988 if Self::can_cast(syntax.kind()) {
2989 Some(Self { syntax })
2994 fn syntax(&self) -> &SyntaxNode {
2998 impl ast::TypeAscriptionOwner for SelfParam {}
2999 impl ast::AttrsOwner for SelfParam {}
3001 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3002 pub struct SlicePat {
3003 pub(crate) syntax: SyntaxNode,
3005 impl AstNode for SlicePat {
3006 fn can_cast(kind: SyntaxKind) -> bool {
3012 fn cast(syntax: SyntaxNode) -> Option<Self> {
3013 if Self::can_cast(syntax.kind()) {
3014 Some(Self { syntax })
3019 fn syntax(&self) -> &SyntaxNode {
3024 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3025 pub struct SliceType {
3026 pub(crate) syntax: SyntaxNode,
3028 impl AstNode for SliceType {
3029 fn can_cast(kind: SyntaxKind) -> bool {
3035 fn cast(syntax: SyntaxNode) -> Option<Self> {
3036 if Self::can_cast(syntax.kind()) {
3037 Some(Self { syntax })
3042 fn syntax(&self) -> &SyntaxNode {
3047 pub fn type_ref(&self) -> Option<TypeRef> {
3048 AstChildren::new(&self.syntax).next()
3051 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3052 pub struct SourceFile {
3053 pub(crate) syntax: SyntaxNode,
3055 impl AstNode for SourceFile {
3056 fn can_cast(kind: SyntaxKind) -> bool {
3058 SOURCE_FILE => true,
3062 fn cast(syntax: SyntaxNode) -> Option<Self> {
3063 if Self::can_cast(syntax.kind()) {
3064 Some(Self { syntax })
3069 fn syntax(&self) -> &SyntaxNode {
3073 impl ast::ModuleItemOwner for SourceFile {}
3074 impl ast::FnDefOwner for SourceFile {}
3076 pub fn modules(&self) -> AstChildren<Module> {
3077 AstChildren::new(&self.syntax)
3080 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3081 pub struct StaticDef {
3082 pub(crate) syntax: SyntaxNode,
3084 impl AstNode for StaticDef {
3085 fn can_cast(kind: SyntaxKind) -> bool {
3091 fn cast(syntax: SyntaxNode) -> Option<Self> {
3092 if Self::can_cast(syntax.kind()) {
3093 Some(Self { syntax })
3098 fn syntax(&self) -> &SyntaxNode {
3102 impl ast::VisibilityOwner for StaticDef {}
3103 impl ast::NameOwner for StaticDef {}
3104 impl ast::TypeParamsOwner for StaticDef {}
3105 impl ast::AttrsOwner for StaticDef {}
3106 impl ast::DocCommentsOwner for StaticDef {}
3107 impl ast::TypeAscriptionOwner for StaticDef {}
3109 pub fn body(&self) -> Option<Expr> {
3110 AstChildren::new(&self.syntax).next()
3113 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3118 impl From<ExprStmt> for Stmt {
3119 fn from(node: ExprStmt) -> Stmt {
3120 Stmt::ExprStmt(node)
3123 impl From<LetStmt> for Stmt {
3124 fn from(node: LetStmt) -> Stmt {
3128 impl AstNode for Stmt {
3129 fn can_cast(kind: SyntaxKind) -> bool {
3131 EXPR_STMT | LET_STMT => true,
3135 fn cast(syntax: SyntaxNode) -> Option<Self> {
3136 let res = match syntax.kind() {
3137 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
3138 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
3143 fn syntax(&self) -> &SyntaxNode {
3145 Stmt::ExprStmt(it) => &it.syntax,
3146 Stmt::LetStmt(it) => &it.syntax,
3151 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3152 pub struct StructDef {
3153 pub(crate) syntax: SyntaxNode,
3155 impl AstNode for StructDef {
3156 fn can_cast(kind: SyntaxKind) -> bool {
3162 fn cast(syntax: SyntaxNode) -> Option<Self> {
3163 if Self::can_cast(syntax.kind()) {
3164 Some(Self { syntax })
3169 fn syntax(&self) -> &SyntaxNode {
3173 impl ast::VisibilityOwner for StructDef {}
3174 impl ast::NameOwner for StructDef {}
3175 impl ast::TypeParamsOwner for StructDef {}
3176 impl ast::AttrsOwner for StructDef {}
3177 impl ast::DocCommentsOwner for StructDef {}
3179 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3180 pub struct TokenTree {
3181 pub(crate) syntax: SyntaxNode,
3183 impl AstNode for TokenTree {
3184 fn can_cast(kind: SyntaxKind) -> bool {
3190 fn cast(syntax: SyntaxNode) -> Option<Self> {
3191 if Self::can_cast(syntax.kind()) {
3192 Some(Self { syntax })
3197 fn syntax(&self) -> &SyntaxNode {
3202 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3203 pub struct TraitDef {
3204 pub(crate) syntax: SyntaxNode,
3206 impl AstNode for TraitDef {
3207 fn can_cast(kind: SyntaxKind) -> bool {
3213 fn cast(syntax: SyntaxNode) -> Option<Self> {
3214 if Self::can_cast(syntax.kind()) {
3215 Some(Self { syntax })
3220 fn syntax(&self) -> &SyntaxNode {
3224 impl ast::VisibilityOwner for TraitDef {}
3225 impl ast::NameOwner for TraitDef {}
3226 impl ast::AttrsOwner for TraitDef {}
3227 impl ast::DocCommentsOwner for TraitDef {}
3228 impl ast::TypeParamsOwner for TraitDef {}
3229 impl ast::TypeBoundsOwner for TraitDef {}
3231 pub fn item_list(&self) -> Option<ItemList> {
3232 AstChildren::new(&self.syntax).next()
3235 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3236 pub struct TryBlockExpr {
3237 pub(crate) syntax: SyntaxNode,
3239 impl AstNode for TryBlockExpr {
3240 fn can_cast(kind: SyntaxKind) -> bool {
3242 TRY_BLOCK_EXPR => true,
3246 fn cast(syntax: SyntaxNode) -> Option<Self> {
3247 if Self::can_cast(syntax.kind()) {
3248 Some(Self { syntax })
3253 fn syntax(&self) -> &SyntaxNode {
3258 pub fn body(&self) -> Option<BlockExpr> {
3259 AstChildren::new(&self.syntax).next()
3262 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3263 pub struct TryExpr {
3264 pub(crate) syntax: SyntaxNode,
3266 impl AstNode for TryExpr {
3267 fn can_cast(kind: SyntaxKind) -> bool {
3273 fn cast(syntax: SyntaxNode) -> Option<Self> {
3274 if Self::can_cast(syntax.kind()) {
3275 Some(Self { syntax })
3280 fn syntax(&self) -> &SyntaxNode {
3285 pub fn expr(&self) -> Option<Expr> {
3286 AstChildren::new(&self.syntax).next()
3289 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3290 pub struct TupleExpr {
3291 pub(crate) syntax: SyntaxNode,
3293 impl AstNode for TupleExpr {
3294 fn can_cast(kind: SyntaxKind) -> bool {
3300 fn cast(syntax: SyntaxNode) -> Option<Self> {
3301 if Self::can_cast(syntax.kind()) {
3302 Some(Self { syntax })
3307 fn syntax(&self) -> &SyntaxNode {
3312 pub fn exprs(&self) -> AstChildren<Expr> {
3313 AstChildren::new(&self.syntax)
3316 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3317 pub struct TupleFieldDef {
3318 pub(crate) syntax: SyntaxNode,
3320 impl AstNode for TupleFieldDef {
3321 fn can_cast(kind: SyntaxKind) -> bool {
3323 TUPLE_FIELD_DEF => true,
3327 fn cast(syntax: SyntaxNode) -> Option<Self> {
3328 if Self::can_cast(syntax.kind()) {
3329 Some(Self { syntax })
3334 fn syntax(&self) -> &SyntaxNode {
3338 impl ast::VisibilityOwner for TupleFieldDef {}
3339 impl ast::AttrsOwner for TupleFieldDef {}
3340 impl TupleFieldDef {
3341 pub fn type_ref(&self) -> Option<TypeRef> {
3342 AstChildren::new(&self.syntax).next()
3345 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3346 pub struct TupleFieldDefList {
3347 pub(crate) syntax: SyntaxNode,
3349 impl AstNode for TupleFieldDefList {
3350 fn can_cast(kind: SyntaxKind) -> bool {
3352 TUPLE_FIELD_DEF_LIST => true,
3356 fn cast(syntax: SyntaxNode) -> Option<Self> {
3357 if Self::can_cast(syntax.kind()) {
3358 Some(Self { syntax })
3363 fn syntax(&self) -> &SyntaxNode {
3367 impl TupleFieldDefList {
3368 pub fn fields(&self) -> AstChildren<TupleFieldDef> {
3369 AstChildren::new(&self.syntax)
3372 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3373 pub struct TuplePat {
3374 pub(crate) syntax: SyntaxNode,
3376 impl AstNode for TuplePat {
3377 fn can_cast(kind: SyntaxKind) -> bool {
3383 fn cast(syntax: SyntaxNode) -> Option<Self> {
3384 if Self::can_cast(syntax.kind()) {
3385 Some(Self { syntax })
3390 fn syntax(&self) -> &SyntaxNode {
3395 pub fn args(&self) -> AstChildren<Pat> {
3396 AstChildren::new(&self.syntax)
3399 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3400 pub struct TupleStructPat {
3401 pub(crate) syntax: SyntaxNode,
3403 impl AstNode for TupleStructPat {
3404 fn can_cast(kind: SyntaxKind) -> bool {
3406 TUPLE_STRUCT_PAT => true,
3410 fn cast(syntax: SyntaxNode) -> Option<Self> {
3411 if Self::can_cast(syntax.kind()) {
3412 Some(Self { syntax })
3417 fn syntax(&self) -> &SyntaxNode {
3421 impl TupleStructPat {
3422 pub fn args(&self) -> AstChildren<Pat> {
3423 AstChildren::new(&self.syntax)
3425 pub fn path(&self) -> Option<Path> {
3426 AstChildren::new(&self.syntax).next()
3429 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3430 pub struct TupleType {
3431 pub(crate) syntax: SyntaxNode,
3433 impl AstNode for TupleType {
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 fields(&self) -> AstChildren<TypeRef> {
3453 AstChildren::new(&self.syntax)
3456 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3457 pub struct TypeAliasDef {
3458 pub(crate) syntax: SyntaxNode,
3460 impl AstNode for TypeAliasDef {
3461 fn can_cast(kind: SyntaxKind) -> bool {
3463 TYPE_ALIAS_DEF => 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 ast::VisibilityOwner for TypeAliasDef {}
3479 impl ast::NameOwner for TypeAliasDef {}
3480 impl ast::TypeParamsOwner for TypeAliasDef {}
3481 impl ast::AttrsOwner for TypeAliasDef {}
3482 impl ast::DocCommentsOwner for TypeAliasDef {}
3483 impl ast::TypeBoundsOwner for TypeAliasDef {}
3485 pub fn type_ref(&self) -> Option<TypeRef> {
3486 AstChildren::new(&self.syntax).next()
3489 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3490 pub struct TypeArg {
3491 pub(crate) syntax: SyntaxNode,
3493 impl AstNode for TypeArg {
3494 fn can_cast(kind: SyntaxKind) -> bool {
3500 fn cast(syntax: SyntaxNode) -> Option<Self> {
3501 if Self::can_cast(syntax.kind()) {
3502 Some(Self { syntax })
3507 fn syntax(&self) -> &SyntaxNode {
3512 pub fn type_ref(&self) -> Option<TypeRef> {
3513 AstChildren::new(&self.syntax).next()
3516 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3517 pub struct TypeArgList {
3518 pub(crate) syntax: SyntaxNode,
3520 impl AstNode for TypeArgList {
3521 fn can_cast(kind: SyntaxKind) -> bool {
3523 TYPE_ARG_LIST => true,
3527 fn cast(syntax: SyntaxNode) -> Option<Self> {
3528 if Self::can_cast(syntax.kind()) {
3529 Some(Self { syntax })
3534 fn syntax(&self) -> &SyntaxNode {
3539 pub fn type_args(&self) -> AstChildren<TypeArg> {
3540 AstChildren::new(&self.syntax)
3542 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3543 AstChildren::new(&self.syntax)
3545 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3546 AstChildren::new(&self.syntax)
3549 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3550 pub struct TypeBound {
3551 pub(crate) syntax: SyntaxNode,
3553 impl AstNode for TypeBound {
3554 fn can_cast(kind: SyntaxKind) -> bool {
3560 fn cast(syntax: SyntaxNode) -> Option<Self> {
3561 if Self::can_cast(syntax.kind()) {
3562 Some(Self { syntax })
3567 fn syntax(&self) -> &SyntaxNode {
3572 pub fn type_ref(&self) -> Option<TypeRef> {
3573 AstChildren::new(&self.syntax).next()
3576 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3577 pub struct TypeBoundList {
3578 pub(crate) syntax: SyntaxNode,
3580 impl AstNode for TypeBoundList {
3581 fn can_cast(kind: SyntaxKind) -> bool {
3583 TYPE_BOUND_LIST => true,
3587 fn cast(syntax: SyntaxNode) -> Option<Self> {
3588 if Self::can_cast(syntax.kind()) {
3589 Some(Self { syntax })
3594 fn syntax(&self) -> &SyntaxNode {
3598 impl TypeBoundList {
3599 pub fn bounds(&self) -> AstChildren<TypeBound> {
3600 AstChildren::new(&self.syntax)
3603 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3604 pub struct TypeParam {
3605 pub(crate) syntax: SyntaxNode,
3607 impl AstNode for TypeParam {
3608 fn can_cast(kind: SyntaxKind) -> bool {
3614 fn cast(syntax: SyntaxNode) -> Option<Self> {
3615 if Self::can_cast(syntax.kind()) {
3616 Some(Self { syntax })
3621 fn syntax(&self) -> &SyntaxNode {
3625 impl ast::NameOwner for TypeParam {}
3626 impl ast::AttrsOwner for TypeParam {}
3627 impl ast::TypeBoundsOwner for TypeParam {}
3629 pub fn default_type(&self) -> Option<TypeRef> {
3630 AstChildren::new(&self.syntax).next()
3633 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3634 pub struct TypeParamList {
3635 pub(crate) syntax: SyntaxNode,
3637 impl AstNode for TypeParamList {
3638 fn can_cast(kind: SyntaxKind) -> bool {
3640 TYPE_PARAM_LIST => true,
3644 fn cast(syntax: SyntaxNode) -> Option<Self> {
3645 if Self::can_cast(syntax.kind()) {
3646 Some(Self { syntax })
3651 fn syntax(&self) -> &SyntaxNode {
3655 impl TypeParamList {
3656 pub fn type_params(&self) -> AstChildren<TypeParam> {
3657 AstChildren::new(&self.syntax)
3659 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3660 AstChildren::new(&self.syntax)
3663 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3665 ParenType(ParenType),
3666 TupleType(TupleType),
3667 NeverType(NeverType),
3669 PointerType(PointerType),
3670 ArrayType(ArrayType),
3671 SliceType(SliceType),
3672 ReferenceType(ReferenceType),
3673 PlaceholderType(PlaceholderType),
3674 FnPointerType(FnPointerType),
3676 ImplTraitType(ImplTraitType),
3677 DynTraitType(DynTraitType),
3679 impl From<ParenType> for TypeRef {
3680 fn from(node: ParenType) -> TypeRef {
3681 TypeRef::ParenType(node)
3684 impl From<TupleType> for TypeRef {
3685 fn from(node: TupleType) -> TypeRef {
3686 TypeRef::TupleType(node)
3689 impl From<NeverType> for TypeRef {
3690 fn from(node: NeverType) -> TypeRef {
3691 TypeRef::NeverType(node)
3694 impl From<PathType> for TypeRef {
3695 fn from(node: PathType) -> TypeRef {
3696 TypeRef::PathType(node)
3699 impl From<PointerType> for TypeRef {
3700 fn from(node: PointerType) -> TypeRef {
3701 TypeRef::PointerType(node)
3704 impl From<ArrayType> for TypeRef {
3705 fn from(node: ArrayType) -> TypeRef {
3706 TypeRef::ArrayType(node)
3709 impl From<SliceType> for TypeRef {
3710 fn from(node: SliceType) -> TypeRef {
3711 TypeRef::SliceType(node)
3714 impl From<ReferenceType> for TypeRef {
3715 fn from(node: ReferenceType) -> TypeRef {
3716 TypeRef::ReferenceType(node)
3719 impl From<PlaceholderType> for TypeRef {
3720 fn from(node: PlaceholderType) -> TypeRef {
3721 TypeRef::PlaceholderType(node)
3724 impl From<FnPointerType> for TypeRef {
3725 fn from(node: FnPointerType) -> TypeRef {
3726 TypeRef::FnPointerType(node)
3729 impl From<ForType> for TypeRef {
3730 fn from(node: ForType) -> TypeRef {
3731 TypeRef::ForType(node)
3734 impl From<ImplTraitType> for TypeRef {
3735 fn from(node: ImplTraitType) -> TypeRef {
3736 TypeRef::ImplTraitType(node)
3739 impl From<DynTraitType> for TypeRef {
3740 fn from(node: DynTraitType) -> TypeRef {
3741 TypeRef::DynTraitType(node)
3744 impl AstNode for TypeRef {
3745 fn can_cast(kind: SyntaxKind) -> bool {
3747 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3748 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3749 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3753 fn cast(syntax: SyntaxNode) -> Option<Self> {
3754 let res = match syntax.kind() {
3755 PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
3756 TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
3757 NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
3758 PATH_TYPE => TypeRef::PathType(PathType { syntax }),
3759 POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
3760 ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
3761 SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
3762 REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
3763 PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
3764 FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
3765 FOR_TYPE => TypeRef::ForType(ForType { syntax }),
3766 IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
3767 DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
3772 fn syntax(&self) -> &SyntaxNode {
3774 TypeRef::ParenType(it) => &it.syntax,
3775 TypeRef::TupleType(it) => &it.syntax,
3776 TypeRef::NeverType(it) => &it.syntax,
3777 TypeRef::PathType(it) => &it.syntax,
3778 TypeRef::PointerType(it) => &it.syntax,
3779 TypeRef::ArrayType(it) => &it.syntax,
3780 TypeRef::SliceType(it) => &it.syntax,
3781 TypeRef::ReferenceType(it) => &it.syntax,
3782 TypeRef::PlaceholderType(it) => &it.syntax,
3783 TypeRef::FnPointerType(it) => &it.syntax,
3784 TypeRef::ForType(it) => &it.syntax,
3785 TypeRef::ImplTraitType(it) => &it.syntax,
3786 TypeRef::DynTraitType(it) => &it.syntax,
3791 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3792 pub struct UnionDef {
3793 pub(crate) syntax: SyntaxNode,
3795 impl AstNode for UnionDef {
3796 fn can_cast(kind: SyntaxKind) -> bool {
3802 fn cast(syntax: SyntaxNode) -> Option<Self> {
3803 if Self::can_cast(syntax.kind()) {
3804 Some(Self { syntax })
3809 fn syntax(&self) -> &SyntaxNode {
3813 impl ast::VisibilityOwner for UnionDef {}
3814 impl ast::NameOwner for UnionDef {}
3815 impl ast::TypeParamsOwner for UnionDef {}
3816 impl ast::AttrsOwner for UnionDef {}
3817 impl ast::DocCommentsOwner for UnionDef {}
3819 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3820 pub struct UseItem {
3821 pub(crate) syntax: SyntaxNode,
3823 impl AstNode for UseItem {
3824 fn can_cast(kind: SyntaxKind) -> bool {
3830 fn cast(syntax: SyntaxNode) -> Option<Self> {
3831 if Self::can_cast(syntax.kind()) {
3832 Some(Self { syntax })
3837 fn syntax(&self) -> &SyntaxNode {
3841 impl ast::AttrsOwner for UseItem {}
3843 pub fn use_tree(&self) -> Option<UseTree> {
3844 AstChildren::new(&self.syntax).next()
3847 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3848 pub struct UseTree {
3849 pub(crate) syntax: SyntaxNode,
3851 impl AstNode for UseTree {
3852 fn can_cast(kind: SyntaxKind) -> bool {
3858 fn cast(syntax: SyntaxNode) -> Option<Self> {
3859 if Self::can_cast(syntax.kind()) {
3860 Some(Self { syntax })
3865 fn syntax(&self) -> &SyntaxNode {
3870 pub fn path(&self) -> Option<Path> {
3871 AstChildren::new(&self.syntax).next()
3873 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3874 AstChildren::new(&self.syntax).next()
3876 pub fn alias(&self) -> Option<Alias> {
3877 AstChildren::new(&self.syntax).next()
3880 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3881 pub struct UseTreeList {
3882 pub(crate) syntax: SyntaxNode,
3884 impl AstNode for UseTreeList {
3885 fn can_cast(kind: SyntaxKind) -> bool {
3887 USE_TREE_LIST => true,
3891 fn cast(syntax: SyntaxNode) -> Option<Self> {
3892 if Self::can_cast(syntax.kind()) {
3893 Some(Self { syntax })
3898 fn syntax(&self) -> &SyntaxNode {
3903 pub fn use_trees(&self) -> AstChildren<UseTree> {
3904 AstChildren::new(&self.syntax)
3907 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3908 pub struct Visibility {
3909 pub(crate) syntax: SyntaxNode,
3911 impl AstNode for Visibility {
3912 fn can_cast(kind: SyntaxKind) -> bool {
3918 fn cast(syntax: SyntaxNode) -> Option<Self> {
3919 if Self::can_cast(syntax.kind()) {
3920 Some(Self { syntax })
3925 fn syntax(&self) -> &SyntaxNode {
3930 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3931 pub struct WhereClause {
3932 pub(crate) syntax: SyntaxNode,
3934 impl AstNode for WhereClause {
3935 fn can_cast(kind: SyntaxKind) -> bool {
3937 WHERE_CLAUSE => true,
3941 fn cast(syntax: SyntaxNode) -> Option<Self> {
3942 if Self::can_cast(syntax.kind()) {
3943 Some(Self { syntax })
3948 fn syntax(&self) -> &SyntaxNode {
3953 pub fn predicates(&self) -> AstChildren<WherePred> {
3954 AstChildren::new(&self.syntax)
3957 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3958 pub struct WherePred {
3959 pub(crate) syntax: SyntaxNode,
3961 impl AstNode for WherePred {
3962 fn can_cast(kind: SyntaxKind) -> bool {
3968 fn cast(syntax: SyntaxNode) -> Option<Self> {
3969 if Self::can_cast(syntax.kind()) {
3970 Some(Self { syntax })
3975 fn syntax(&self) -> &SyntaxNode {
3979 impl ast::TypeBoundsOwner for WherePred {}
3981 pub fn type_ref(&self) -> Option<TypeRef> {
3982 AstChildren::new(&self.syntax).next()
3985 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3986 pub struct WhileExpr {
3987 pub(crate) syntax: SyntaxNode,
3989 impl AstNode for WhileExpr {
3990 fn can_cast(kind: SyntaxKind) -> bool {
3996 fn cast(syntax: SyntaxNode) -> Option<Self> {
3997 if Self::can_cast(syntax.kind()) {
3998 Some(Self { syntax })
4003 fn syntax(&self) -> &SyntaxNode {
4007 impl ast::LoopBodyOwner for WhileExpr {}
4009 pub fn condition(&self) -> Option<Condition> {
4010 AstChildren::new(&self.syntax).next()