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,
1302 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1303 pub struct ImplTraitType {
1304 pub(crate) syntax: SyntaxNode,
1306 impl AstNode for ImplTraitType {
1307 fn can_cast(kind: SyntaxKind) -> bool {
1309 IMPL_TRAIT_TYPE => true,
1313 fn cast(syntax: SyntaxNode) -> Option<Self> {
1314 if Self::can_cast(syntax.kind()) {
1315 Some(Self { syntax })
1320 fn syntax(&self) -> &SyntaxNode {
1324 impl ast::TypeBoundsOwner for ImplTraitType {}
1325 impl ImplTraitType {}
1326 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1327 pub struct IndexExpr {
1328 pub(crate) syntax: SyntaxNode,
1330 impl AstNode for IndexExpr {
1331 fn can_cast(kind: SyntaxKind) -> bool {
1337 fn cast(syntax: SyntaxNode) -> Option<Self> {
1338 if Self::can_cast(syntax.kind()) {
1339 Some(Self { syntax })
1344 fn syntax(&self) -> &SyntaxNode {
1349 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1350 pub struct ItemList {
1351 pub(crate) syntax: SyntaxNode,
1353 impl AstNode for ItemList {
1354 fn can_cast(kind: SyntaxKind) -> bool {
1360 fn cast(syntax: SyntaxNode) -> Option<Self> {
1361 if Self::can_cast(syntax.kind()) {
1362 Some(Self { syntax })
1367 fn syntax(&self) -> &SyntaxNode {
1371 impl ast::FnDefOwner for ItemList {}
1372 impl ast::ModuleItemOwner for ItemList {}
1374 pub fn impl_items(&self) -> AstChildren<ImplItem> {
1375 AstChildren::new(&self.syntax)
1378 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1380 pub(crate) syntax: SyntaxNode,
1382 impl AstNode for Label {
1383 fn can_cast(kind: SyntaxKind) -> bool {
1389 fn cast(syntax: SyntaxNode) -> Option<Self> {
1390 if Self::can_cast(syntax.kind()) {
1391 Some(Self { syntax })
1396 fn syntax(&self) -> &SyntaxNode {
1401 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1402 pub struct LambdaExpr {
1403 pub(crate) syntax: SyntaxNode,
1405 impl AstNode for LambdaExpr {
1406 fn can_cast(kind: SyntaxKind) -> bool {
1408 LAMBDA_EXPR => true,
1412 fn cast(syntax: SyntaxNode) -> Option<Self> {
1413 if Self::can_cast(syntax.kind()) {
1414 Some(Self { syntax })
1419 fn syntax(&self) -> &SyntaxNode {
1424 pub fn param_list(&self) -> Option<ParamList> {
1425 AstChildren::new(&self.syntax).next()
1427 pub fn body(&self) -> Option<Expr> {
1428 AstChildren::new(&self.syntax).next()
1431 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1432 pub struct LetStmt {
1433 pub(crate) syntax: SyntaxNode,
1435 impl AstNode for LetStmt {
1436 fn can_cast(kind: SyntaxKind) -> bool {
1442 fn cast(syntax: SyntaxNode) -> Option<Self> {
1443 if Self::can_cast(syntax.kind()) {
1444 Some(Self { syntax })
1449 fn syntax(&self) -> &SyntaxNode {
1453 impl ast::TypeAscriptionOwner for LetStmt {}
1455 pub fn pat(&self) -> Option<Pat> {
1456 AstChildren::new(&self.syntax).next()
1458 pub fn initializer(&self) -> Option<Expr> {
1459 AstChildren::new(&self.syntax).next()
1462 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1463 pub struct LifetimeArg {
1464 pub(crate) syntax: SyntaxNode,
1466 impl AstNode for LifetimeArg {
1467 fn can_cast(kind: SyntaxKind) -> bool {
1469 LIFETIME_ARG => true,
1473 fn cast(syntax: SyntaxNode) -> Option<Self> {
1474 if Self::can_cast(syntax.kind()) {
1475 Some(Self { syntax })
1480 fn syntax(&self) -> &SyntaxNode {
1485 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1486 pub struct LifetimeParam {
1487 pub(crate) syntax: SyntaxNode,
1489 impl AstNode for LifetimeParam {
1490 fn can_cast(kind: SyntaxKind) -> bool {
1492 LIFETIME_PARAM => true,
1496 fn cast(syntax: SyntaxNode) -> Option<Self> {
1497 if Self::can_cast(syntax.kind()) {
1498 Some(Self { syntax })
1503 fn syntax(&self) -> &SyntaxNode {
1507 impl ast::AttrsOwner for LifetimeParam {}
1508 impl LifetimeParam {}
1509 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1510 pub struct Literal {
1511 pub(crate) syntax: SyntaxNode,
1513 impl AstNode for Literal {
1514 fn can_cast(kind: SyntaxKind) -> bool {
1520 fn cast(syntax: SyntaxNode) -> Option<Self> {
1521 if Self::can_cast(syntax.kind()) {
1522 Some(Self { syntax })
1527 fn syntax(&self) -> &SyntaxNode {
1532 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1533 pub struct LiteralPat {
1534 pub(crate) syntax: SyntaxNode,
1536 impl AstNode for LiteralPat {
1537 fn can_cast(kind: SyntaxKind) -> bool {
1539 LITERAL_PAT => true,
1543 fn cast(syntax: SyntaxNode) -> Option<Self> {
1544 if Self::can_cast(syntax.kind()) {
1545 Some(Self { syntax })
1550 fn syntax(&self) -> &SyntaxNode {
1555 pub fn literal(&self) -> Option<Literal> {
1556 AstChildren::new(&self.syntax).next()
1559 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1560 pub struct LoopExpr {
1561 pub(crate) syntax: SyntaxNode,
1563 impl AstNode for LoopExpr {
1564 fn can_cast(kind: SyntaxKind) -> bool {
1570 fn cast(syntax: SyntaxNode) -> Option<Self> {
1571 if Self::can_cast(syntax.kind()) {
1572 Some(Self { syntax })
1577 fn syntax(&self) -> &SyntaxNode {
1581 impl ast::LoopBodyOwner for LoopExpr {}
1583 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1584 pub struct MacroCall {
1585 pub(crate) syntax: SyntaxNode,
1587 impl AstNode for MacroCall {
1588 fn can_cast(kind: SyntaxKind) -> bool {
1594 fn cast(syntax: SyntaxNode) -> Option<Self> {
1595 if Self::can_cast(syntax.kind()) {
1596 Some(Self { syntax })
1601 fn syntax(&self) -> &SyntaxNode {
1605 impl ast::NameOwner for MacroCall {}
1606 impl ast::AttrsOwner for MacroCall {}
1607 impl ast::DocCommentsOwner for MacroCall {}
1609 pub fn token_tree(&self) -> Option<TokenTree> {
1610 AstChildren::new(&self.syntax).next()
1612 pub fn path(&self) -> Option<Path> {
1613 AstChildren::new(&self.syntax).next()
1616 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1617 pub struct MacroItems {
1618 pub(crate) syntax: SyntaxNode,
1620 impl AstNode for MacroItems {
1621 fn can_cast(kind: SyntaxKind) -> bool {
1623 MACRO_ITEMS => true,
1627 fn cast(syntax: SyntaxNode) -> Option<Self> {
1628 if Self::can_cast(syntax.kind()) {
1629 Some(Self { syntax })
1634 fn syntax(&self) -> &SyntaxNode {
1638 impl ast::ModuleItemOwner for MacroItems {}
1639 impl ast::FnDefOwner for MacroItems {}
1641 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1642 pub struct MacroStmts {
1643 pub(crate) syntax: SyntaxNode,
1645 impl AstNode for MacroStmts {
1646 fn can_cast(kind: SyntaxKind) -> bool {
1648 MACRO_STMTS => true,
1652 fn cast(syntax: SyntaxNode) -> Option<Self> {
1653 if Self::can_cast(syntax.kind()) {
1654 Some(Self { syntax })
1659 fn syntax(&self) -> &SyntaxNode {
1664 pub fn statements(&self) -> AstChildren<Stmt> {
1665 AstChildren::new(&self.syntax)
1667 pub fn expr(&self) -> Option<Expr> {
1668 AstChildren::new(&self.syntax).next()
1671 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1672 pub struct MatchArm {
1673 pub(crate) syntax: SyntaxNode,
1675 impl AstNode for MatchArm {
1676 fn can_cast(kind: SyntaxKind) -> bool {
1682 fn cast(syntax: SyntaxNode) -> Option<Self> {
1683 if Self::can_cast(syntax.kind()) {
1684 Some(Self { syntax })
1689 fn syntax(&self) -> &SyntaxNode {
1693 impl ast::AttrsOwner for MatchArm {}
1695 pub fn pats(&self) -> AstChildren<Pat> {
1696 AstChildren::new(&self.syntax)
1698 pub fn guard(&self) -> Option<MatchGuard> {
1699 AstChildren::new(&self.syntax).next()
1701 pub fn expr(&self) -> Option<Expr> {
1702 AstChildren::new(&self.syntax).next()
1705 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1706 pub struct MatchArmList {
1707 pub(crate) syntax: SyntaxNode,
1709 impl AstNode for MatchArmList {
1710 fn can_cast(kind: SyntaxKind) -> bool {
1712 MATCH_ARM_LIST => true,
1716 fn cast(syntax: SyntaxNode) -> Option<Self> {
1717 if Self::can_cast(syntax.kind()) {
1718 Some(Self { syntax })
1723 fn syntax(&self) -> &SyntaxNode {
1727 impl ast::AttrsOwner for MatchArmList {}
1729 pub fn arms(&self) -> AstChildren<MatchArm> {
1730 AstChildren::new(&self.syntax)
1733 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1734 pub struct MatchExpr {
1735 pub(crate) syntax: SyntaxNode,
1737 impl AstNode for MatchExpr {
1738 fn can_cast(kind: SyntaxKind) -> bool {
1744 fn cast(syntax: SyntaxNode) -> Option<Self> {
1745 if Self::can_cast(syntax.kind()) {
1746 Some(Self { syntax })
1751 fn syntax(&self) -> &SyntaxNode {
1756 pub fn expr(&self) -> Option<Expr> {
1757 AstChildren::new(&self.syntax).next()
1759 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1760 AstChildren::new(&self.syntax).next()
1763 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1764 pub struct MatchGuard {
1765 pub(crate) syntax: SyntaxNode,
1767 impl AstNode for MatchGuard {
1768 fn can_cast(kind: SyntaxKind) -> bool {
1770 MATCH_GUARD => true,
1774 fn cast(syntax: SyntaxNode) -> Option<Self> {
1775 if Self::can_cast(syntax.kind()) {
1776 Some(Self { syntax })
1781 fn syntax(&self) -> &SyntaxNode {
1786 pub fn expr(&self) -> Option<Expr> {
1787 AstChildren::new(&self.syntax).next()
1790 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1791 pub struct MethodCallExpr {
1792 pub(crate) syntax: SyntaxNode,
1794 impl AstNode for MethodCallExpr {
1795 fn can_cast(kind: SyntaxKind) -> bool {
1797 METHOD_CALL_EXPR => true,
1801 fn cast(syntax: SyntaxNode) -> Option<Self> {
1802 if Self::can_cast(syntax.kind()) {
1803 Some(Self { syntax })
1808 fn syntax(&self) -> &SyntaxNode {
1812 impl ast::ArgListOwner for MethodCallExpr {}
1813 impl MethodCallExpr {
1814 pub fn expr(&self) -> Option<Expr> {
1815 AstChildren::new(&self.syntax).next()
1817 pub fn name_ref(&self) -> Option<NameRef> {
1818 AstChildren::new(&self.syntax).next()
1820 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1821 AstChildren::new(&self.syntax).next()
1824 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1826 pub(crate) syntax: SyntaxNode,
1828 impl AstNode for Module {
1829 fn can_cast(kind: SyntaxKind) -> bool {
1835 fn cast(syntax: SyntaxNode) -> Option<Self> {
1836 if Self::can_cast(syntax.kind()) {
1837 Some(Self { syntax })
1842 fn syntax(&self) -> &SyntaxNode {
1846 impl ast::VisibilityOwner for Module {}
1847 impl ast::NameOwner for Module {}
1848 impl ast::AttrsOwner for Module {}
1849 impl ast::DocCommentsOwner for Module {}
1851 pub fn item_list(&self) -> Option<ItemList> {
1852 AstChildren::new(&self.syntax).next()
1855 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1856 pub enum ModuleItem {
1857 StructDef(StructDef),
1861 TypeAliasDef(TypeAliasDef),
1862 ImplBlock(ImplBlock),
1864 ExternCrateItem(ExternCrateItem),
1866 StaticDef(StaticDef),
1869 impl From<StructDef> for ModuleItem {
1870 fn from(node: StructDef) -> ModuleItem {
1871 ModuleItem::StructDef(node)
1874 impl From<EnumDef> for ModuleItem {
1875 fn from(node: EnumDef) -> ModuleItem {
1876 ModuleItem::EnumDef(node)
1879 impl From<FnDef> for ModuleItem {
1880 fn from(node: FnDef) -> ModuleItem {
1881 ModuleItem::FnDef(node)
1884 impl From<TraitDef> for ModuleItem {
1885 fn from(node: TraitDef) -> ModuleItem {
1886 ModuleItem::TraitDef(node)
1889 impl From<TypeAliasDef> for ModuleItem {
1890 fn from(node: TypeAliasDef) -> ModuleItem {
1891 ModuleItem::TypeAliasDef(node)
1894 impl From<ImplBlock> for ModuleItem {
1895 fn from(node: ImplBlock) -> ModuleItem {
1896 ModuleItem::ImplBlock(node)
1899 impl From<UseItem> for ModuleItem {
1900 fn from(node: UseItem) -> ModuleItem {
1901 ModuleItem::UseItem(node)
1904 impl From<ExternCrateItem> for ModuleItem {
1905 fn from(node: ExternCrateItem) -> ModuleItem {
1906 ModuleItem::ExternCrateItem(node)
1909 impl From<ConstDef> for ModuleItem {
1910 fn from(node: ConstDef) -> ModuleItem {
1911 ModuleItem::ConstDef(node)
1914 impl From<StaticDef> for ModuleItem {
1915 fn from(node: StaticDef) -> ModuleItem {
1916 ModuleItem::StaticDef(node)
1919 impl From<Module> for ModuleItem {
1920 fn from(node: Module) -> ModuleItem {
1921 ModuleItem::Module(node)
1924 impl AstNode for ModuleItem {
1925 fn can_cast(kind: SyntaxKind) -> bool {
1927 STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM
1928 | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1932 fn cast(syntax: SyntaxNode) -> Option<Self> {
1933 let res = match syntax.kind() {
1934 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
1935 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
1936 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
1937 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
1938 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
1939 IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
1940 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
1941 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
1942 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
1943 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
1944 MODULE => ModuleItem::Module(Module { syntax }),
1949 fn syntax(&self) -> &SyntaxNode {
1951 ModuleItem::StructDef(it) => &it.syntax,
1952 ModuleItem::EnumDef(it) => &it.syntax,
1953 ModuleItem::FnDef(it) => &it.syntax,
1954 ModuleItem::TraitDef(it) => &it.syntax,
1955 ModuleItem::TypeAliasDef(it) => &it.syntax,
1956 ModuleItem::ImplBlock(it) => &it.syntax,
1957 ModuleItem::UseItem(it) => &it.syntax,
1958 ModuleItem::ExternCrateItem(it) => &it.syntax,
1959 ModuleItem::ConstDef(it) => &it.syntax,
1960 ModuleItem::StaticDef(it) => &it.syntax,
1961 ModuleItem::Module(it) => &it.syntax,
1965 impl ast::AttrsOwner for ModuleItem {}
1967 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1969 pub(crate) syntax: SyntaxNode,
1971 impl AstNode for Name {
1972 fn can_cast(kind: SyntaxKind) -> bool {
1978 fn cast(syntax: SyntaxNode) -> Option<Self> {
1979 if Self::can_cast(syntax.kind()) {
1980 Some(Self { syntax })
1985 fn syntax(&self) -> &SyntaxNode {
1990 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1991 pub struct NameRef {
1992 pub(crate) syntax: SyntaxNode,
1994 impl AstNode for NameRef {
1995 fn can_cast(kind: SyntaxKind) -> bool {
2001 fn cast(syntax: SyntaxNode) -> Option<Self> {
2002 if Self::can_cast(syntax.kind()) {
2003 Some(Self { syntax })
2008 fn syntax(&self) -> &SyntaxNode {
2013 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2014 pub struct NeverType {
2015 pub(crate) syntax: SyntaxNode,
2017 impl AstNode for NeverType {
2018 fn can_cast(kind: SyntaxKind) -> bool {
2024 fn cast(syntax: SyntaxNode) -> Option<Self> {
2025 if Self::can_cast(syntax.kind()) {
2026 Some(Self { syntax })
2031 fn syntax(&self) -> &SyntaxNode {
2036 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2037 pub enum NominalDef {
2038 StructDef(StructDef),
2041 impl From<StructDef> for NominalDef {
2042 fn from(node: StructDef) -> NominalDef {
2043 NominalDef::StructDef(node)
2046 impl From<EnumDef> for NominalDef {
2047 fn from(node: EnumDef) -> NominalDef {
2048 NominalDef::EnumDef(node)
2051 impl AstNode for NominalDef {
2052 fn can_cast(kind: SyntaxKind) -> bool {
2054 STRUCT_DEF | ENUM_DEF => true,
2058 fn cast(syntax: SyntaxNode) -> Option<Self> {
2059 let res = match syntax.kind() {
2060 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
2061 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
2066 fn syntax(&self) -> &SyntaxNode {
2068 NominalDef::StructDef(it) => &it.syntax,
2069 NominalDef::EnumDef(it) => &it.syntax,
2073 impl ast::NameOwner for NominalDef {}
2074 impl ast::TypeParamsOwner for NominalDef {}
2075 impl ast::AttrsOwner for NominalDef {}
2077 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2079 pub(crate) syntax: SyntaxNode,
2081 impl AstNode for Param {
2082 fn can_cast(kind: SyntaxKind) -> bool {
2088 fn cast(syntax: SyntaxNode) -> Option<Self> {
2089 if Self::can_cast(syntax.kind()) {
2090 Some(Self { syntax })
2095 fn syntax(&self) -> &SyntaxNode {
2099 impl ast::TypeAscriptionOwner for Param {}
2100 impl ast::AttrsOwner for Param {}
2102 pub fn pat(&self) -> Option<Pat> {
2103 AstChildren::new(&self.syntax).next()
2106 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2107 pub struct ParamList {
2108 pub(crate) syntax: SyntaxNode,
2110 impl AstNode for ParamList {
2111 fn can_cast(kind: SyntaxKind) -> bool {
2117 fn cast(syntax: SyntaxNode) -> Option<Self> {
2118 if Self::can_cast(syntax.kind()) {
2119 Some(Self { syntax })
2124 fn syntax(&self) -> &SyntaxNode {
2129 pub fn params(&self) -> AstChildren<Param> {
2130 AstChildren::new(&self.syntax)
2132 pub fn self_param(&self) -> Option<SelfParam> {
2133 AstChildren::new(&self.syntax).next()
2136 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2137 pub struct ParenExpr {
2138 pub(crate) syntax: SyntaxNode,
2140 impl AstNode for ParenExpr {
2141 fn can_cast(kind: SyntaxKind) -> bool {
2147 fn cast(syntax: SyntaxNode) -> Option<Self> {
2148 if Self::can_cast(syntax.kind()) {
2149 Some(Self { syntax })
2154 fn syntax(&self) -> &SyntaxNode {
2159 pub fn expr(&self) -> Option<Expr> {
2160 AstChildren::new(&self.syntax).next()
2163 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2164 pub struct ParenType {
2165 pub(crate) syntax: SyntaxNode,
2167 impl AstNode for ParenType {
2168 fn can_cast(kind: SyntaxKind) -> bool {
2174 fn cast(syntax: SyntaxNode) -> Option<Self> {
2175 if Self::can_cast(syntax.kind()) {
2176 Some(Self { syntax })
2181 fn syntax(&self) -> &SyntaxNode {
2186 pub fn type_ref(&self) -> Option<TypeRef> {
2187 AstChildren::new(&self.syntax).next()
2190 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2195 PlaceholderPat(PlaceholderPat),
2196 DotDotPat(DotDotPat),
2198 RecordPat(RecordPat),
2199 TupleStructPat(TupleStructPat),
2203 LiteralPat(LiteralPat),
2205 impl From<RefPat> for Pat {
2206 fn from(node: RefPat) -> Pat {
2210 impl From<BoxPat> for Pat {
2211 fn from(node: BoxPat) -> Pat {
2215 impl From<BindPat> for Pat {
2216 fn from(node: BindPat) -> Pat {
2220 impl From<PlaceholderPat> for Pat {
2221 fn from(node: PlaceholderPat) -> Pat {
2222 Pat::PlaceholderPat(node)
2225 impl From<DotDotPat> for Pat {
2226 fn from(node: DotDotPat) -> Pat {
2227 Pat::DotDotPat(node)
2230 impl From<PathPat> for Pat {
2231 fn from(node: PathPat) -> Pat {
2235 impl From<RecordPat> for Pat {
2236 fn from(node: RecordPat) -> Pat {
2237 Pat::RecordPat(node)
2240 impl From<TupleStructPat> for Pat {
2241 fn from(node: TupleStructPat) -> Pat {
2242 Pat::TupleStructPat(node)
2245 impl From<TuplePat> for Pat {
2246 fn from(node: TuplePat) -> Pat {
2250 impl From<SlicePat> for Pat {
2251 fn from(node: SlicePat) -> Pat {
2255 impl From<RangePat> for Pat {
2256 fn from(node: RangePat) -> Pat {
2260 impl From<LiteralPat> for Pat {
2261 fn from(node: LiteralPat) -> Pat {
2262 Pat::LiteralPat(node)
2265 impl AstNode for Pat {
2266 fn can_cast(kind: SyntaxKind) -> bool {
2268 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT
2269 | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => {
2275 fn cast(syntax: SyntaxNode) -> Option<Self> {
2276 let res = match syntax.kind() {
2277 REF_PAT => Pat::RefPat(RefPat { syntax }),
2278 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2279 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2280 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2281 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
2282 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2283 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2284 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2285 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2286 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2287 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2288 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2293 fn syntax(&self) -> &SyntaxNode {
2295 Pat::RefPat(it) => &it.syntax,
2296 Pat::BoxPat(it) => &it.syntax,
2297 Pat::BindPat(it) => &it.syntax,
2298 Pat::PlaceholderPat(it) => &it.syntax,
2299 Pat::DotDotPat(it) => &it.syntax,
2300 Pat::PathPat(it) => &it.syntax,
2301 Pat::RecordPat(it) => &it.syntax,
2302 Pat::TupleStructPat(it) => &it.syntax,
2303 Pat::TuplePat(it) => &it.syntax,
2304 Pat::SlicePat(it) => &it.syntax,
2305 Pat::RangePat(it) => &it.syntax,
2306 Pat::LiteralPat(it) => &it.syntax,
2311 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2313 pub(crate) syntax: SyntaxNode,
2315 impl AstNode for Path {
2316 fn can_cast(kind: SyntaxKind) -> bool {
2322 fn cast(syntax: SyntaxNode) -> Option<Self> {
2323 if Self::can_cast(syntax.kind()) {
2324 Some(Self { syntax })
2329 fn syntax(&self) -> &SyntaxNode {
2334 pub fn segment(&self) -> Option<PathSegment> {
2335 AstChildren::new(&self.syntax).next()
2337 pub fn qualifier(&self) -> Option<Path> {
2338 AstChildren::new(&self.syntax).next()
2341 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2342 pub struct PathExpr {
2343 pub(crate) syntax: SyntaxNode,
2345 impl AstNode for PathExpr {
2346 fn can_cast(kind: SyntaxKind) -> bool {
2352 fn cast(syntax: SyntaxNode) -> Option<Self> {
2353 if Self::can_cast(syntax.kind()) {
2354 Some(Self { syntax })
2359 fn syntax(&self) -> &SyntaxNode {
2364 pub fn path(&self) -> Option<Path> {
2365 AstChildren::new(&self.syntax).next()
2368 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2369 pub struct PathPat {
2370 pub(crate) syntax: SyntaxNode,
2372 impl AstNode for PathPat {
2373 fn can_cast(kind: SyntaxKind) -> bool {
2379 fn cast(syntax: SyntaxNode) -> Option<Self> {
2380 if Self::can_cast(syntax.kind()) {
2381 Some(Self { syntax })
2386 fn syntax(&self) -> &SyntaxNode {
2391 pub fn path(&self) -> Option<Path> {
2392 AstChildren::new(&self.syntax).next()
2395 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2396 pub struct PathSegment {
2397 pub(crate) syntax: SyntaxNode,
2399 impl AstNode for PathSegment {
2400 fn can_cast(kind: SyntaxKind) -> bool {
2402 PATH_SEGMENT => true,
2406 fn cast(syntax: SyntaxNode) -> Option<Self> {
2407 if Self::can_cast(syntax.kind()) {
2408 Some(Self { syntax })
2413 fn syntax(&self) -> &SyntaxNode {
2418 pub fn name_ref(&self) -> Option<NameRef> {
2419 AstChildren::new(&self.syntax).next()
2421 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2422 AstChildren::new(&self.syntax).next()
2424 pub fn param_list(&self) -> Option<ParamList> {
2425 AstChildren::new(&self.syntax).next()
2427 pub fn ret_type(&self) -> Option<RetType> {
2428 AstChildren::new(&self.syntax).next()
2430 pub fn path_type(&self) -> Option<PathType> {
2431 AstChildren::new(&self.syntax).next()
2434 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2435 pub struct PathType {
2436 pub(crate) syntax: SyntaxNode,
2438 impl AstNode for PathType {
2439 fn can_cast(kind: SyntaxKind) -> bool {
2445 fn cast(syntax: SyntaxNode) -> Option<Self> {
2446 if Self::can_cast(syntax.kind()) {
2447 Some(Self { syntax })
2452 fn syntax(&self) -> &SyntaxNode {
2457 pub fn path(&self) -> Option<Path> {
2458 AstChildren::new(&self.syntax).next()
2461 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2462 pub struct PlaceholderPat {
2463 pub(crate) syntax: SyntaxNode,
2465 impl AstNode for PlaceholderPat {
2466 fn can_cast(kind: SyntaxKind) -> bool {
2468 PLACEHOLDER_PAT => true,
2472 fn cast(syntax: SyntaxNode) -> Option<Self> {
2473 if Self::can_cast(syntax.kind()) {
2474 Some(Self { syntax })
2479 fn syntax(&self) -> &SyntaxNode {
2483 impl PlaceholderPat {}
2484 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2485 pub struct PlaceholderType {
2486 pub(crate) syntax: SyntaxNode,
2488 impl AstNode for PlaceholderType {
2489 fn can_cast(kind: SyntaxKind) -> bool {
2491 PLACEHOLDER_TYPE => true,
2495 fn cast(syntax: SyntaxNode) -> Option<Self> {
2496 if Self::can_cast(syntax.kind()) {
2497 Some(Self { syntax })
2502 fn syntax(&self) -> &SyntaxNode {
2506 impl PlaceholderType {}
2507 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2508 pub struct PointerType {
2509 pub(crate) syntax: SyntaxNode,
2511 impl AstNode for PointerType {
2512 fn can_cast(kind: SyntaxKind) -> bool {
2514 POINTER_TYPE => true,
2518 fn cast(syntax: SyntaxNode) -> Option<Self> {
2519 if Self::can_cast(syntax.kind()) {
2520 Some(Self { syntax })
2525 fn syntax(&self) -> &SyntaxNode {
2530 pub fn type_ref(&self) -> Option<TypeRef> {
2531 AstChildren::new(&self.syntax).next()
2534 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2535 pub struct PrefixExpr {
2536 pub(crate) syntax: SyntaxNode,
2538 impl AstNode for PrefixExpr {
2539 fn can_cast(kind: SyntaxKind) -> bool {
2541 PREFIX_EXPR => true,
2545 fn cast(syntax: SyntaxNode) -> Option<Self> {
2546 if Self::can_cast(syntax.kind()) {
2547 Some(Self { syntax })
2552 fn syntax(&self) -> &SyntaxNode {
2557 pub fn expr(&self) -> Option<Expr> {
2558 AstChildren::new(&self.syntax).next()
2561 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2562 pub struct RangeExpr {
2563 pub(crate) syntax: SyntaxNode,
2565 impl AstNode for RangeExpr {
2566 fn can_cast(kind: SyntaxKind) -> bool {
2572 fn cast(syntax: SyntaxNode) -> Option<Self> {
2573 if Self::can_cast(syntax.kind()) {
2574 Some(Self { syntax })
2579 fn syntax(&self) -> &SyntaxNode {
2584 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2585 pub struct RangePat {
2586 pub(crate) syntax: SyntaxNode,
2588 impl AstNode for RangePat {
2589 fn can_cast(kind: SyntaxKind) -> bool {
2595 fn cast(syntax: SyntaxNode) -> Option<Self> {
2596 if Self::can_cast(syntax.kind()) {
2597 Some(Self { syntax })
2602 fn syntax(&self) -> &SyntaxNode {
2607 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2608 pub struct RecordField {
2609 pub(crate) syntax: SyntaxNode,
2611 impl AstNode for RecordField {
2612 fn can_cast(kind: SyntaxKind) -> bool {
2614 RECORD_FIELD => true,
2618 fn cast(syntax: SyntaxNode) -> Option<Self> {
2619 if Self::can_cast(syntax.kind()) {
2620 Some(Self { syntax })
2625 fn syntax(&self) -> &SyntaxNode {
2630 pub fn name_ref(&self) -> Option<NameRef> {
2631 AstChildren::new(&self.syntax).next()
2633 pub fn expr(&self) -> Option<Expr> {
2634 AstChildren::new(&self.syntax).next()
2637 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2638 pub struct RecordFieldDef {
2639 pub(crate) syntax: SyntaxNode,
2641 impl AstNode for RecordFieldDef {
2642 fn can_cast(kind: SyntaxKind) -> bool {
2644 RECORD_FIELD_DEF => true,
2648 fn cast(syntax: SyntaxNode) -> Option<Self> {
2649 if Self::can_cast(syntax.kind()) {
2650 Some(Self { syntax })
2655 fn syntax(&self) -> &SyntaxNode {
2659 impl ast::VisibilityOwner for RecordFieldDef {}
2660 impl ast::NameOwner for RecordFieldDef {}
2661 impl ast::AttrsOwner for RecordFieldDef {}
2662 impl ast::DocCommentsOwner for RecordFieldDef {}
2663 impl ast::TypeAscriptionOwner for RecordFieldDef {}
2664 impl RecordFieldDef {}
2665 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2666 pub struct RecordFieldDefList {
2667 pub(crate) syntax: SyntaxNode,
2669 impl AstNode for RecordFieldDefList {
2670 fn can_cast(kind: SyntaxKind) -> bool {
2672 RECORD_FIELD_DEF_LIST => true,
2676 fn cast(syntax: SyntaxNode) -> Option<Self> {
2677 if Self::can_cast(syntax.kind()) {
2678 Some(Self { syntax })
2683 fn syntax(&self) -> &SyntaxNode {
2687 impl RecordFieldDefList {
2688 pub fn fields(&self) -> AstChildren<RecordFieldDef> {
2689 AstChildren::new(&self.syntax)
2692 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2693 pub struct RecordFieldList {
2694 pub(crate) syntax: SyntaxNode,
2696 impl AstNode for RecordFieldList {
2697 fn can_cast(kind: SyntaxKind) -> bool {
2699 RECORD_FIELD_LIST => true,
2703 fn cast(syntax: SyntaxNode) -> Option<Self> {
2704 if Self::can_cast(syntax.kind()) {
2705 Some(Self { syntax })
2710 fn syntax(&self) -> &SyntaxNode {
2714 impl RecordFieldList {
2715 pub fn fields(&self) -> AstChildren<RecordField> {
2716 AstChildren::new(&self.syntax)
2718 pub fn spread(&self) -> Option<Expr> {
2719 AstChildren::new(&self.syntax).next()
2722 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2723 pub struct RecordFieldPat {
2724 pub(crate) syntax: SyntaxNode,
2726 impl AstNode for RecordFieldPat {
2727 fn can_cast(kind: SyntaxKind) -> bool {
2729 RECORD_FIELD_PAT => true,
2733 fn cast(syntax: SyntaxNode) -> Option<Self> {
2734 if Self::can_cast(syntax.kind()) {
2735 Some(Self { syntax })
2740 fn syntax(&self) -> &SyntaxNode {
2744 impl ast::NameOwner for RecordFieldPat {}
2745 impl RecordFieldPat {
2746 pub fn pat(&self) -> Option<Pat> {
2747 AstChildren::new(&self.syntax).next()
2750 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2751 pub struct RecordFieldPatList {
2752 pub(crate) syntax: SyntaxNode,
2754 impl AstNode for RecordFieldPatList {
2755 fn can_cast(kind: SyntaxKind) -> bool {
2757 RECORD_FIELD_PAT_LIST => true,
2761 fn cast(syntax: SyntaxNode) -> Option<Self> {
2762 if Self::can_cast(syntax.kind()) {
2763 Some(Self { syntax })
2768 fn syntax(&self) -> &SyntaxNode {
2772 impl RecordFieldPatList {
2773 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
2774 AstChildren::new(&self.syntax)
2776 pub fn bind_pats(&self) -> AstChildren<BindPat> {
2777 AstChildren::new(&self.syntax)
2780 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2781 pub struct RecordLit {
2782 pub(crate) syntax: SyntaxNode,
2784 impl AstNode for RecordLit {
2785 fn can_cast(kind: SyntaxKind) -> bool {
2791 fn cast(syntax: SyntaxNode) -> Option<Self> {
2792 if Self::can_cast(syntax.kind()) {
2793 Some(Self { syntax })
2798 fn syntax(&self) -> &SyntaxNode {
2803 pub fn path(&self) -> Option<Path> {
2804 AstChildren::new(&self.syntax).next()
2806 pub fn record_field_list(&self) -> Option<RecordFieldList> {
2807 AstChildren::new(&self.syntax).next()
2810 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2811 pub struct RecordPat {
2812 pub(crate) syntax: SyntaxNode,
2814 impl AstNode for RecordPat {
2815 fn can_cast(kind: SyntaxKind) -> bool {
2821 fn cast(syntax: SyntaxNode) -> Option<Self> {
2822 if Self::can_cast(syntax.kind()) {
2823 Some(Self { syntax })
2828 fn syntax(&self) -> &SyntaxNode {
2833 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
2834 AstChildren::new(&self.syntax).next()
2836 pub fn path(&self) -> Option<Path> {
2837 AstChildren::new(&self.syntax).next()
2840 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2841 pub struct RefExpr {
2842 pub(crate) syntax: SyntaxNode,
2844 impl AstNode for RefExpr {
2845 fn can_cast(kind: SyntaxKind) -> bool {
2851 fn cast(syntax: SyntaxNode) -> Option<Self> {
2852 if Self::can_cast(syntax.kind()) {
2853 Some(Self { syntax })
2858 fn syntax(&self) -> &SyntaxNode {
2863 pub fn expr(&self) -> Option<Expr> {
2864 AstChildren::new(&self.syntax).next()
2867 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2869 pub(crate) syntax: SyntaxNode,
2871 impl AstNode for RefPat {
2872 fn can_cast(kind: SyntaxKind) -> bool {
2878 fn cast(syntax: SyntaxNode) -> Option<Self> {
2879 if Self::can_cast(syntax.kind()) {
2880 Some(Self { syntax })
2885 fn syntax(&self) -> &SyntaxNode {
2890 pub fn pat(&self) -> Option<Pat> {
2891 AstChildren::new(&self.syntax).next()
2894 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2895 pub struct ReferenceType {
2896 pub(crate) syntax: SyntaxNode,
2898 impl AstNode for ReferenceType {
2899 fn can_cast(kind: SyntaxKind) -> bool {
2901 REFERENCE_TYPE => true,
2905 fn cast(syntax: SyntaxNode) -> Option<Self> {
2906 if Self::can_cast(syntax.kind()) {
2907 Some(Self { syntax })
2912 fn syntax(&self) -> &SyntaxNode {
2916 impl ReferenceType {
2917 pub fn type_ref(&self) -> Option<TypeRef> {
2918 AstChildren::new(&self.syntax).next()
2921 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2922 pub struct RetType {
2923 pub(crate) syntax: SyntaxNode,
2925 impl AstNode for RetType {
2926 fn can_cast(kind: SyntaxKind) -> bool {
2932 fn cast(syntax: SyntaxNode) -> Option<Self> {
2933 if Self::can_cast(syntax.kind()) {
2934 Some(Self { syntax })
2939 fn syntax(&self) -> &SyntaxNode {
2944 pub fn type_ref(&self) -> Option<TypeRef> {
2945 AstChildren::new(&self.syntax).next()
2948 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2949 pub struct ReturnExpr {
2950 pub(crate) syntax: SyntaxNode,
2952 impl AstNode for ReturnExpr {
2953 fn can_cast(kind: SyntaxKind) -> bool {
2955 RETURN_EXPR => true,
2959 fn cast(syntax: SyntaxNode) -> Option<Self> {
2960 if Self::can_cast(syntax.kind()) {
2961 Some(Self { syntax })
2966 fn syntax(&self) -> &SyntaxNode {
2971 pub fn expr(&self) -> Option<Expr> {
2972 AstChildren::new(&self.syntax).next()
2975 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2976 pub struct SelfParam {
2977 pub(crate) syntax: SyntaxNode,
2979 impl AstNode for SelfParam {
2980 fn can_cast(kind: SyntaxKind) -> bool {
2986 fn cast(syntax: SyntaxNode) -> Option<Self> {
2987 if Self::can_cast(syntax.kind()) {
2988 Some(Self { syntax })
2993 fn syntax(&self) -> &SyntaxNode {
2997 impl ast::TypeAscriptionOwner for SelfParam {}
2998 impl ast::AttrsOwner for SelfParam {}
3000 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3001 pub struct SlicePat {
3002 pub(crate) syntax: SyntaxNode,
3004 impl AstNode for SlicePat {
3005 fn can_cast(kind: SyntaxKind) -> bool {
3011 fn cast(syntax: SyntaxNode) -> Option<Self> {
3012 if Self::can_cast(syntax.kind()) {
3013 Some(Self { syntax })
3018 fn syntax(&self) -> &SyntaxNode {
3023 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3024 pub struct SliceType {
3025 pub(crate) syntax: SyntaxNode,
3027 impl AstNode for SliceType {
3028 fn can_cast(kind: SyntaxKind) -> bool {
3034 fn cast(syntax: SyntaxNode) -> Option<Self> {
3035 if Self::can_cast(syntax.kind()) {
3036 Some(Self { syntax })
3041 fn syntax(&self) -> &SyntaxNode {
3046 pub fn type_ref(&self) -> Option<TypeRef> {
3047 AstChildren::new(&self.syntax).next()
3050 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3051 pub struct SourceFile {
3052 pub(crate) syntax: SyntaxNode,
3054 impl AstNode for SourceFile {
3055 fn can_cast(kind: SyntaxKind) -> bool {
3057 SOURCE_FILE => true,
3061 fn cast(syntax: SyntaxNode) -> Option<Self> {
3062 if Self::can_cast(syntax.kind()) {
3063 Some(Self { syntax })
3068 fn syntax(&self) -> &SyntaxNode {
3072 impl ast::ModuleItemOwner for SourceFile {}
3073 impl ast::FnDefOwner for SourceFile {}
3075 pub fn modules(&self) -> AstChildren<Module> {
3076 AstChildren::new(&self.syntax)
3079 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3080 pub struct StaticDef {
3081 pub(crate) syntax: SyntaxNode,
3083 impl AstNode for StaticDef {
3084 fn can_cast(kind: SyntaxKind) -> bool {
3090 fn cast(syntax: SyntaxNode) -> Option<Self> {
3091 if Self::can_cast(syntax.kind()) {
3092 Some(Self { syntax })
3097 fn syntax(&self) -> &SyntaxNode {
3101 impl ast::VisibilityOwner for StaticDef {}
3102 impl ast::NameOwner for StaticDef {}
3103 impl ast::TypeParamsOwner for StaticDef {}
3104 impl ast::AttrsOwner for StaticDef {}
3105 impl ast::DocCommentsOwner for StaticDef {}
3106 impl ast::TypeAscriptionOwner for StaticDef {}
3108 pub fn body(&self) -> Option<Expr> {
3109 AstChildren::new(&self.syntax).next()
3112 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3117 impl From<ExprStmt> for Stmt {
3118 fn from(node: ExprStmt) -> Stmt {
3119 Stmt::ExprStmt(node)
3122 impl From<LetStmt> for Stmt {
3123 fn from(node: LetStmt) -> Stmt {
3127 impl AstNode for Stmt {
3128 fn can_cast(kind: SyntaxKind) -> bool {
3130 EXPR_STMT | LET_STMT => true,
3134 fn cast(syntax: SyntaxNode) -> Option<Self> {
3135 let res = match syntax.kind() {
3136 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
3137 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
3142 fn syntax(&self) -> &SyntaxNode {
3144 Stmt::ExprStmt(it) => &it.syntax,
3145 Stmt::LetStmt(it) => &it.syntax,
3150 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3151 pub struct StructDef {
3152 pub(crate) syntax: SyntaxNode,
3154 impl AstNode for StructDef {
3155 fn can_cast(kind: SyntaxKind) -> bool {
3161 fn cast(syntax: SyntaxNode) -> Option<Self> {
3162 if Self::can_cast(syntax.kind()) {
3163 Some(Self { syntax })
3168 fn syntax(&self) -> &SyntaxNode {
3172 impl ast::VisibilityOwner for StructDef {}
3173 impl ast::NameOwner for StructDef {}
3174 impl ast::TypeParamsOwner for StructDef {}
3175 impl ast::AttrsOwner for StructDef {}
3176 impl ast::DocCommentsOwner for StructDef {}
3178 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3179 pub struct TokenTree {
3180 pub(crate) syntax: SyntaxNode,
3182 impl AstNode for TokenTree {
3183 fn can_cast(kind: SyntaxKind) -> bool {
3189 fn cast(syntax: SyntaxNode) -> Option<Self> {
3190 if Self::can_cast(syntax.kind()) {
3191 Some(Self { syntax })
3196 fn syntax(&self) -> &SyntaxNode {
3201 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3202 pub struct TraitDef {
3203 pub(crate) syntax: SyntaxNode,
3205 impl AstNode for TraitDef {
3206 fn can_cast(kind: SyntaxKind) -> bool {
3212 fn cast(syntax: SyntaxNode) -> Option<Self> {
3213 if Self::can_cast(syntax.kind()) {
3214 Some(Self { syntax })
3219 fn syntax(&self) -> &SyntaxNode {
3223 impl ast::VisibilityOwner for TraitDef {}
3224 impl ast::NameOwner for TraitDef {}
3225 impl ast::AttrsOwner for TraitDef {}
3226 impl ast::DocCommentsOwner for TraitDef {}
3227 impl ast::TypeParamsOwner for TraitDef {}
3228 impl ast::TypeBoundsOwner for TraitDef {}
3230 pub fn item_list(&self) -> Option<ItemList> {
3231 AstChildren::new(&self.syntax).next()
3234 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3235 pub struct TryBlockExpr {
3236 pub(crate) syntax: SyntaxNode,
3238 impl AstNode for TryBlockExpr {
3239 fn can_cast(kind: SyntaxKind) -> bool {
3241 TRY_BLOCK_EXPR => true,
3245 fn cast(syntax: SyntaxNode) -> Option<Self> {
3246 if Self::can_cast(syntax.kind()) {
3247 Some(Self { syntax })
3252 fn syntax(&self) -> &SyntaxNode {
3257 pub fn body(&self) -> Option<BlockExpr> {
3258 AstChildren::new(&self.syntax).next()
3261 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3262 pub struct TryExpr {
3263 pub(crate) syntax: SyntaxNode,
3265 impl AstNode for TryExpr {
3266 fn can_cast(kind: SyntaxKind) -> bool {
3272 fn cast(syntax: SyntaxNode) -> Option<Self> {
3273 if Self::can_cast(syntax.kind()) {
3274 Some(Self { syntax })
3279 fn syntax(&self) -> &SyntaxNode {
3284 pub fn expr(&self) -> Option<Expr> {
3285 AstChildren::new(&self.syntax).next()
3288 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3289 pub struct TupleExpr {
3290 pub(crate) syntax: SyntaxNode,
3292 impl AstNode for TupleExpr {
3293 fn can_cast(kind: SyntaxKind) -> bool {
3299 fn cast(syntax: SyntaxNode) -> Option<Self> {
3300 if Self::can_cast(syntax.kind()) {
3301 Some(Self { syntax })
3306 fn syntax(&self) -> &SyntaxNode {
3311 pub fn exprs(&self) -> AstChildren<Expr> {
3312 AstChildren::new(&self.syntax)
3315 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3316 pub struct TupleFieldDef {
3317 pub(crate) syntax: SyntaxNode,
3319 impl AstNode for TupleFieldDef {
3320 fn can_cast(kind: SyntaxKind) -> bool {
3322 TUPLE_FIELD_DEF => true,
3326 fn cast(syntax: SyntaxNode) -> Option<Self> {
3327 if Self::can_cast(syntax.kind()) {
3328 Some(Self { syntax })
3333 fn syntax(&self) -> &SyntaxNode {
3337 impl ast::VisibilityOwner for TupleFieldDef {}
3338 impl ast::AttrsOwner for TupleFieldDef {}
3339 impl TupleFieldDef {
3340 pub fn type_ref(&self) -> Option<TypeRef> {
3341 AstChildren::new(&self.syntax).next()
3344 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3345 pub struct TupleFieldDefList {
3346 pub(crate) syntax: SyntaxNode,
3348 impl AstNode for TupleFieldDefList {
3349 fn can_cast(kind: SyntaxKind) -> bool {
3351 TUPLE_FIELD_DEF_LIST => true,
3355 fn cast(syntax: SyntaxNode) -> Option<Self> {
3356 if Self::can_cast(syntax.kind()) {
3357 Some(Self { syntax })
3362 fn syntax(&self) -> &SyntaxNode {
3366 impl TupleFieldDefList {
3367 pub fn fields(&self) -> AstChildren<TupleFieldDef> {
3368 AstChildren::new(&self.syntax)
3371 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3372 pub struct TuplePat {
3373 pub(crate) syntax: SyntaxNode,
3375 impl AstNode for TuplePat {
3376 fn can_cast(kind: SyntaxKind) -> bool {
3382 fn cast(syntax: SyntaxNode) -> Option<Self> {
3383 if Self::can_cast(syntax.kind()) {
3384 Some(Self { syntax })
3389 fn syntax(&self) -> &SyntaxNode {
3394 pub fn args(&self) -> AstChildren<Pat> {
3395 AstChildren::new(&self.syntax)
3398 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3399 pub struct TupleStructPat {
3400 pub(crate) syntax: SyntaxNode,
3402 impl AstNode for TupleStructPat {
3403 fn can_cast(kind: SyntaxKind) -> bool {
3405 TUPLE_STRUCT_PAT => true,
3409 fn cast(syntax: SyntaxNode) -> Option<Self> {
3410 if Self::can_cast(syntax.kind()) {
3411 Some(Self { syntax })
3416 fn syntax(&self) -> &SyntaxNode {
3420 impl TupleStructPat {
3421 pub fn args(&self) -> AstChildren<Pat> {
3422 AstChildren::new(&self.syntax)
3424 pub fn path(&self) -> Option<Path> {
3425 AstChildren::new(&self.syntax).next()
3428 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3429 pub struct TupleType {
3430 pub(crate) syntax: SyntaxNode,
3432 impl AstNode for TupleType {
3433 fn can_cast(kind: SyntaxKind) -> bool {
3439 fn cast(syntax: SyntaxNode) -> Option<Self> {
3440 if Self::can_cast(syntax.kind()) {
3441 Some(Self { syntax })
3446 fn syntax(&self) -> &SyntaxNode {
3451 pub fn fields(&self) -> AstChildren<TypeRef> {
3452 AstChildren::new(&self.syntax)
3455 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3456 pub struct TypeAliasDef {
3457 pub(crate) syntax: SyntaxNode,
3459 impl AstNode for TypeAliasDef {
3460 fn can_cast(kind: SyntaxKind) -> bool {
3462 TYPE_ALIAS_DEF => true,
3466 fn cast(syntax: SyntaxNode) -> Option<Self> {
3467 if Self::can_cast(syntax.kind()) {
3468 Some(Self { syntax })
3473 fn syntax(&self) -> &SyntaxNode {
3477 impl ast::VisibilityOwner for TypeAliasDef {}
3478 impl ast::NameOwner for TypeAliasDef {}
3479 impl ast::TypeParamsOwner for TypeAliasDef {}
3480 impl ast::AttrsOwner for TypeAliasDef {}
3481 impl ast::DocCommentsOwner for TypeAliasDef {}
3482 impl ast::TypeBoundsOwner for TypeAliasDef {}
3484 pub fn type_ref(&self) -> Option<TypeRef> {
3485 AstChildren::new(&self.syntax).next()
3488 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3489 pub struct TypeArg {
3490 pub(crate) syntax: SyntaxNode,
3492 impl AstNode for TypeArg {
3493 fn can_cast(kind: SyntaxKind) -> bool {
3499 fn cast(syntax: SyntaxNode) -> Option<Self> {
3500 if Self::can_cast(syntax.kind()) {
3501 Some(Self { syntax })
3506 fn syntax(&self) -> &SyntaxNode {
3511 pub fn type_ref(&self) -> Option<TypeRef> {
3512 AstChildren::new(&self.syntax).next()
3515 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3516 pub struct TypeArgList {
3517 pub(crate) syntax: SyntaxNode,
3519 impl AstNode for TypeArgList {
3520 fn can_cast(kind: SyntaxKind) -> bool {
3522 TYPE_ARG_LIST => true,
3526 fn cast(syntax: SyntaxNode) -> Option<Self> {
3527 if Self::can_cast(syntax.kind()) {
3528 Some(Self { syntax })
3533 fn syntax(&self) -> &SyntaxNode {
3538 pub fn type_args(&self) -> AstChildren<TypeArg> {
3539 AstChildren::new(&self.syntax)
3541 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3542 AstChildren::new(&self.syntax)
3544 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3545 AstChildren::new(&self.syntax)
3548 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3549 pub struct TypeBound {
3550 pub(crate) syntax: SyntaxNode,
3552 impl AstNode for TypeBound {
3553 fn can_cast(kind: SyntaxKind) -> bool {
3559 fn cast(syntax: SyntaxNode) -> Option<Self> {
3560 if Self::can_cast(syntax.kind()) {
3561 Some(Self { syntax })
3566 fn syntax(&self) -> &SyntaxNode {
3571 pub fn type_ref(&self) -> Option<TypeRef> {
3572 AstChildren::new(&self.syntax).next()
3575 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3576 pub struct TypeBoundList {
3577 pub(crate) syntax: SyntaxNode,
3579 impl AstNode for TypeBoundList {
3580 fn can_cast(kind: SyntaxKind) -> bool {
3582 TYPE_BOUND_LIST => true,
3586 fn cast(syntax: SyntaxNode) -> Option<Self> {
3587 if Self::can_cast(syntax.kind()) {
3588 Some(Self { syntax })
3593 fn syntax(&self) -> &SyntaxNode {
3597 impl TypeBoundList {
3598 pub fn bounds(&self) -> AstChildren<TypeBound> {
3599 AstChildren::new(&self.syntax)
3602 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3603 pub struct TypeParam {
3604 pub(crate) syntax: SyntaxNode,
3606 impl AstNode for TypeParam {
3607 fn can_cast(kind: SyntaxKind) -> bool {
3613 fn cast(syntax: SyntaxNode) -> Option<Self> {
3614 if Self::can_cast(syntax.kind()) {
3615 Some(Self { syntax })
3620 fn syntax(&self) -> &SyntaxNode {
3624 impl ast::NameOwner for TypeParam {}
3625 impl ast::AttrsOwner for TypeParam {}
3626 impl ast::TypeBoundsOwner for TypeParam {}
3627 impl ast::DefaultTypeParamOwner for TypeParam {}
3629 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3630 pub struct TypeParamList {
3631 pub(crate) syntax: SyntaxNode,
3633 impl AstNode for TypeParamList {
3634 fn can_cast(kind: SyntaxKind) -> bool {
3636 TYPE_PARAM_LIST => true,
3640 fn cast(syntax: SyntaxNode) -> Option<Self> {
3641 if Self::can_cast(syntax.kind()) {
3642 Some(Self { syntax })
3647 fn syntax(&self) -> &SyntaxNode {
3651 impl TypeParamList {
3652 pub fn type_params(&self) -> AstChildren<TypeParam> {
3653 AstChildren::new(&self.syntax)
3655 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3656 AstChildren::new(&self.syntax)
3659 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3661 ParenType(ParenType),
3662 TupleType(TupleType),
3663 NeverType(NeverType),
3665 PointerType(PointerType),
3666 ArrayType(ArrayType),
3667 SliceType(SliceType),
3668 ReferenceType(ReferenceType),
3669 PlaceholderType(PlaceholderType),
3670 FnPointerType(FnPointerType),
3672 ImplTraitType(ImplTraitType),
3673 DynTraitType(DynTraitType),
3675 impl From<ParenType> for TypeRef {
3676 fn from(node: ParenType) -> TypeRef {
3677 TypeRef::ParenType(node)
3680 impl From<TupleType> for TypeRef {
3681 fn from(node: TupleType) -> TypeRef {
3682 TypeRef::TupleType(node)
3685 impl From<NeverType> for TypeRef {
3686 fn from(node: NeverType) -> TypeRef {
3687 TypeRef::NeverType(node)
3690 impl From<PathType> for TypeRef {
3691 fn from(node: PathType) -> TypeRef {
3692 TypeRef::PathType(node)
3695 impl From<PointerType> for TypeRef {
3696 fn from(node: PointerType) -> TypeRef {
3697 TypeRef::PointerType(node)
3700 impl From<ArrayType> for TypeRef {
3701 fn from(node: ArrayType) -> TypeRef {
3702 TypeRef::ArrayType(node)
3705 impl From<SliceType> for TypeRef {
3706 fn from(node: SliceType) -> TypeRef {
3707 TypeRef::SliceType(node)
3710 impl From<ReferenceType> for TypeRef {
3711 fn from(node: ReferenceType) -> TypeRef {
3712 TypeRef::ReferenceType(node)
3715 impl From<PlaceholderType> for TypeRef {
3716 fn from(node: PlaceholderType) -> TypeRef {
3717 TypeRef::PlaceholderType(node)
3720 impl From<FnPointerType> for TypeRef {
3721 fn from(node: FnPointerType) -> TypeRef {
3722 TypeRef::FnPointerType(node)
3725 impl From<ForType> for TypeRef {
3726 fn from(node: ForType) -> TypeRef {
3727 TypeRef::ForType(node)
3730 impl From<ImplTraitType> for TypeRef {
3731 fn from(node: ImplTraitType) -> TypeRef {
3732 TypeRef::ImplTraitType(node)
3735 impl From<DynTraitType> for TypeRef {
3736 fn from(node: DynTraitType) -> TypeRef {
3737 TypeRef::DynTraitType(node)
3740 impl AstNode for TypeRef {
3741 fn can_cast(kind: SyntaxKind) -> bool {
3743 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3744 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3745 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3749 fn cast(syntax: SyntaxNode) -> Option<Self> {
3750 let res = match syntax.kind() {
3751 PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
3752 TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
3753 NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
3754 PATH_TYPE => TypeRef::PathType(PathType { syntax }),
3755 POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
3756 ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
3757 SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
3758 REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
3759 PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
3760 FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
3761 FOR_TYPE => TypeRef::ForType(ForType { syntax }),
3762 IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
3763 DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
3768 fn syntax(&self) -> &SyntaxNode {
3770 TypeRef::ParenType(it) => &it.syntax,
3771 TypeRef::TupleType(it) => &it.syntax,
3772 TypeRef::NeverType(it) => &it.syntax,
3773 TypeRef::PathType(it) => &it.syntax,
3774 TypeRef::PointerType(it) => &it.syntax,
3775 TypeRef::ArrayType(it) => &it.syntax,
3776 TypeRef::SliceType(it) => &it.syntax,
3777 TypeRef::ReferenceType(it) => &it.syntax,
3778 TypeRef::PlaceholderType(it) => &it.syntax,
3779 TypeRef::FnPointerType(it) => &it.syntax,
3780 TypeRef::ForType(it) => &it.syntax,
3781 TypeRef::ImplTraitType(it) => &it.syntax,
3782 TypeRef::DynTraitType(it) => &it.syntax,
3787 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3788 pub struct UseItem {
3789 pub(crate) syntax: SyntaxNode,
3791 impl AstNode for UseItem {
3792 fn can_cast(kind: SyntaxKind) -> bool {
3798 fn cast(syntax: SyntaxNode) -> Option<Self> {
3799 if Self::can_cast(syntax.kind()) {
3800 Some(Self { syntax })
3805 fn syntax(&self) -> &SyntaxNode {
3809 impl ast::AttrsOwner for UseItem {}
3811 pub fn use_tree(&self) -> Option<UseTree> {
3812 AstChildren::new(&self.syntax).next()
3815 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3816 pub struct UseTree {
3817 pub(crate) syntax: SyntaxNode,
3819 impl AstNode for UseTree {
3820 fn can_cast(kind: SyntaxKind) -> bool {
3826 fn cast(syntax: SyntaxNode) -> Option<Self> {
3827 if Self::can_cast(syntax.kind()) {
3828 Some(Self { syntax })
3833 fn syntax(&self) -> &SyntaxNode {
3838 pub fn path(&self) -> Option<Path> {
3839 AstChildren::new(&self.syntax).next()
3841 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3842 AstChildren::new(&self.syntax).next()
3844 pub fn alias(&self) -> Option<Alias> {
3845 AstChildren::new(&self.syntax).next()
3848 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3849 pub struct UseTreeList {
3850 pub(crate) syntax: SyntaxNode,
3852 impl AstNode for UseTreeList {
3853 fn can_cast(kind: SyntaxKind) -> bool {
3855 USE_TREE_LIST => true,
3859 fn cast(syntax: SyntaxNode) -> Option<Self> {
3860 if Self::can_cast(syntax.kind()) {
3861 Some(Self { syntax })
3866 fn syntax(&self) -> &SyntaxNode {
3871 pub fn use_trees(&self) -> AstChildren<UseTree> {
3872 AstChildren::new(&self.syntax)
3875 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3876 pub struct Visibility {
3877 pub(crate) syntax: SyntaxNode,
3879 impl AstNode for Visibility {
3880 fn can_cast(kind: SyntaxKind) -> bool {
3886 fn cast(syntax: SyntaxNode) -> Option<Self> {
3887 if Self::can_cast(syntax.kind()) {
3888 Some(Self { syntax })
3893 fn syntax(&self) -> &SyntaxNode {
3898 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3899 pub struct WhereClause {
3900 pub(crate) syntax: SyntaxNode,
3902 impl AstNode for WhereClause {
3903 fn can_cast(kind: SyntaxKind) -> bool {
3905 WHERE_CLAUSE => true,
3909 fn cast(syntax: SyntaxNode) -> Option<Self> {
3910 if Self::can_cast(syntax.kind()) {
3911 Some(Self { syntax })
3916 fn syntax(&self) -> &SyntaxNode {
3921 pub fn predicates(&self) -> AstChildren<WherePred> {
3922 AstChildren::new(&self.syntax)
3925 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3926 pub struct WherePred {
3927 pub(crate) syntax: SyntaxNode,
3929 impl AstNode for WherePred {
3930 fn can_cast(kind: SyntaxKind) -> bool {
3936 fn cast(syntax: SyntaxNode) -> Option<Self> {
3937 if Self::can_cast(syntax.kind()) {
3938 Some(Self { syntax })
3943 fn syntax(&self) -> &SyntaxNode {
3947 impl ast::TypeBoundsOwner for WherePred {}
3949 pub fn type_ref(&self) -> Option<TypeRef> {
3950 AstChildren::new(&self.syntax).next()
3953 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3954 pub struct WhileExpr {
3955 pub(crate) syntax: SyntaxNode,
3957 impl AstNode for WhileExpr {
3958 fn can_cast(kind: SyntaxKind) -> bool {
3964 fn cast(syntax: SyntaxNode) -> Option<Self> {
3965 if Self::can_cast(syntax.kind()) {
3966 Some(Self { syntax })
3971 fn syntax(&self) -> &SyntaxNode {
3975 impl ast::LoopBodyOwner for WhileExpr {}
3977 pub fn condition(&self) -> Option<Condition> {
3978 AstChildren::new(&self.syntax).next()