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,
1966 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1968 pub(crate) syntax: SyntaxNode,
1970 impl AstNode for Name {
1971 fn can_cast(kind: SyntaxKind) -> bool {
1977 fn cast(syntax: SyntaxNode) -> Option<Self> {
1978 if Self::can_cast(syntax.kind()) {
1979 Some(Self { syntax })
1984 fn syntax(&self) -> &SyntaxNode {
1989 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1990 pub struct NameRef {
1991 pub(crate) syntax: SyntaxNode,
1993 impl AstNode for NameRef {
1994 fn can_cast(kind: SyntaxKind) -> bool {
2000 fn cast(syntax: SyntaxNode) -> Option<Self> {
2001 if Self::can_cast(syntax.kind()) {
2002 Some(Self { syntax })
2007 fn syntax(&self) -> &SyntaxNode {
2012 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2013 pub struct NeverType {
2014 pub(crate) syntax: SyntaxNode,
2016 impl AstNode for NeverType {
2017 fn can_cast(kind: SyntaxKind) -> bool {
2023 fn cast(syntax: SyntaxNode) -> Option<Self> {
2024 if Self::can_cast(syntax.kind()) {
2025 Some(Self { syntax })
2030 fn syntax(&self) -> &SyntaxNode {
2035 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2036 pub enum NominalDef {
2037 StructDef(StructDef),
2040 impl From<StructDef> for NominalDef {
2041 fn from(node: StructDef) -> NominalDef {
2042 NominalDef::StructDef(node)
2045 impl From<EnumDef> for NominalDef {
2046 fn from(node: EnumDef) -> NominalDef {
2047 NominalDef::EnumDef(node)
2050 impl AstNode for NominalDef {
2051 fn can_cast(kind: SyntaxKind) -> bool {
2053 STRUCT_DEF | ENUM_DEF => true,
2057 fn cast(syntax: SyntaxNode) -> Option<Self> {
2058 let res = match syntax.kind() {
2059 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
2060 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
2065 fn syntax(&self) -> &SyntaxNode {
2067 NominalDef::StructDef(it) => &it.syntax,
2068 NominalDef::EnumDef(it) => &it.syntax,
2072 impl ast::NameOwner for NominalDef {}
2073 impl ast::TypeParamsOwner for NominalDef {}
2074 impl ast::AttrsOwner for NominalDef {}
2076 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2078 pub(crate) syntax: SyntaxNode,
2080 impl AstNode for Param {
2081 fn can_cast(kind: SyntaxKind) -> bool {
2087 fn cast(syntax: SyntaxNode) -> Option<Self> {
2088 if Self::can_cast(syntax.kind()) {
2089 Some(Self { syntax })
2094 fn syntax(&self) -> &SyntaxNode {
2098 impl ast::TypeAscriptionOwner for Param {}
2099 impl ast::AttrsOwner for Param {}
2101 pub fn pat(&self) -> Option<Pat> {
2102 AstChildren::new(&self.syntax).next()
2105 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2106 pub struct ParamList {
2107 pub(crate) syntax: SyntaxNode,
2109 impl AstNode for ParamList {
2110 fn can_cast(kind: SyntaxKind) -> bool {
2116 fn cast(syntax: SyntaxNode) -> Option<Self> {
2117 if Self::can_cast(syntax.kind()) {
2118 Some(Self { syntax })
2123 fn syntax(&self) -> &SyntaxNode {
2128 pub fn params(&self) -> AstChildren<Param> {
2129 AstChildren::new(&self.syntax)
2131 pub fn self_param(&self) -> Option<SelfParam> {
2132 AstChildren::new(&self.syntax).next()
2135 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2136 pub struct ParenExpr {
2137 pub(crate) syntax: SyntaxNode,
2139 impl AstNode for ParenExpr {
2140 fn can_cast(kind: SyntaxKind) -> bool {
2146 fn cast(syntax: SyntaxNode) -> Option<Self> {
2147 if Self::can_cast(syntax.kind()) {
2148 Some(Self { syntax })
2153 fn syntax(&self) -> &SyntaxNode {
2158 pub fn expr(&self) -> Option<Expr> {
2159 AstChildren::new(&self.syntax).next()
2162 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2163 pub struct ParenType {
2164 pub(crate) syntax: SyntaxNode,
2166 impl AstNode for ParenType {
2167 fn can_cast(kind: SyntaxKind) -> bool {
2173 fn cast(syntax: SyntaxNode) -> Option<Self> {
2174 if Self::can_cast(syntax.kind()) {
2175 Some(Self { syntax })
2180 fn syntax(&self) -> &SyntaxNode {
2185 pub fn type_ref(&self) -> Option<TypeRef> {
2186 AstChildren::new(&self.syntax).next()
2189 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2194 PlaceholderPat(PlaceholderPat),
2195 DotDotPat(DotDotPat),
2197 RecordPat(RecordPat),
2198 TupleStructPat(TupleStructPat),
2202 LiteralPat(LiteralPat),
2204 impl From<RefPat> for Pat {
2205 fn from(node: RefPat) -> Pat {
2209 impl From<BoxPat> for Pat {
2210 fn from(node: BoxPat) -> Pat {
2214 impl From<BindPat> for Pat {
2215 fn from(node: BindPat) -> Pat {
2219 impl From<PlaceholderPat> for Pat {
2220 fn from(node: PlaceholderPat) -> Pat {
2221 Pat::PlaceholderPat(node)
2224 impl From<DotDotPat> for Pat {
2225 fn from(node: DotDotPat) -> Pat {
2226 Pat::DotDotPat(node)
2229 impl From<PathPat> for Pat {
2230 fn from(node: PathPat) -> Pat {
2234 impl From<RecordPat> for Pat {
2235 fn from(node: RecordPat) -> Pat {
2236 Pat::RecordPat(node)
2239 impl From<TupleStructPat> for Pat {
2240 fn from(node: TupleStructPat) -> Pat {
2241 Pat::TupleStructPat(node)
2244 impl From<TuplePat> for Pat {
2245 fn from(node: TuplePat) -> Pat {
2249 impl From<SlicePat> for Pat {
2250 fn from(node: SlicePat) -> Pat {
2254 impl From<RangePat> for Pat {
2255 fn from(node: RangePat) -> Pat {
2259 impl From<LiteralPat> for Pat {
2260 fn from(node: LiteralPat) -> Pat {
2261 Pat::LiteralPat(node)
2264 impl AstNode for Pat {
2265 fn can_cast(kind: SyntaxKind) -> bool {
2267 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT
2268 | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => {
2274 fn cast(syntax: SyntaxNode) -> Option<Self> {
2275 let res = match syntax.kind() {
2276 REF_PAT => Pat::RefPat(RefPat { syntax }),
2277 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2278 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2279 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2280 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
2281 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2282 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2283 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2284 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2285 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2286 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2287 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2292 fn syntax(&self) -> &SyntaxNode {
2294 Pat::RefPat(it) => &it.syntax,
2295 Pat::BoxPat(it) => &it.syntax,
2296 Pat::BindPat(it) => &it.syntax,
2297 Pat::PlaceholderPat(it) => &it.syntax,
2298 Pat::DotDotPat(it) => &it.syntax,
2299 Pat::PathPat(it) => &it.syntax,
2300 Pat::RecordPat(it) => &it.syntax,
2301 Pat::TupleStructPat(it) => &it.syntax,
2302 Pat::TuplePat(it) => &it.syntax,
2303 Pat::SlicePat(it) => &it.syntax,
2304 Pat::RangePat(it) => &it.syntax,
2305 Pat::LiteralPat(it) => &it.syntax,
2310 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2312 pub(crate) syntax: SyntaxNode,
2314 impl AstNode for Path {
2315 fn can_cast(kind: SyntaxKind) -> bool {
2321 fn cast(syntax: SyntaxNode) -> Option<Self> {
2322 if Self::can_cast(syntax.kind()) {
2323 Some(Self { syntax })
2328 fn syntax(&self) -> &SyntaxNode {
2333 pub fn segment(&self) -> Option<PathSegment> {
2334 AstChildren::new(&self.syntax).next()
2336 pub fn qualifier(&self) -> Option<Path> {
2337 AstChildren::new(&self.syntax).next()
2340 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2341 pub struct PathExpr {
2342 pub(crate) syntax: SyntaxNode,
2344 impl AstNode for PathExpr {
2345 fn can_cast(kind: SyntaxKind) -> bool {
2351 fn cast(syntax: SyntaxNode) -> Option<Self> {
2352 if Self::can_cast(syntax.kind()) {
2353 Some(Self { syntax })
2358 fn syntax(&self) -> &SyntaxNode {
2363 pub fn path(&self) -> Option<Path> {
2364 AstChildren::new(&self.syntax).next()
2367 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2368 pub struct PathPat {
2369 pub(crate) syntax: SyntaxNode,
2371 impl AstNode for PathPat {
2372 fn can_cast(kind: SyntaxKind) -> bool {
2378 fn cast(syntax: SyntaxNode) -> Option<Self> {
2379 if Self::can_cast(syntax.kind()) {
2380 Some(Self { syntax })
2385 fn syntax(&self) -> &SyntaxNode {
2390 pub fn path(&self) -> Option<Path> {
2391 AstChildren::new(&self.syntax).next()
2394 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2395 pub struct PathSegment {
2396 pub(crate) syntax: SyntaxNode,
2398 impl AstNode for PathSegment {
2399 fn can_cast(kind: SyntaxKind) -> bool {
2401 PATH_SEGMENT => true,
2405 fn cast(syntax: SyntaxNode) -> Option<Self> {
2406 if Self::can_cast(syntax.kind()) {
2407 Some(Self { syntax })
2412 fn syntax(&self) -> &SyntaxNode {
2417 pub fn name_ref(&self) -> Option<NameRef> {
2418 AstChildren::new(&self.syntax).next()
2420 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2421 AstChildren::new(&self.syntax).next()
2423 pub fn param_list(&self) -> Option<ParamList> {
2424 AstChildren::new(&self.syntax).next()
2426 pub fn ret_type(&self) -> Option<RetType> {
2427 AstChildren::new(&self.syntax).next()
2429 pub fn path_type(&self) -> Option<PathType> {
2430 AstChildren::new(&self.syntax).next()
2433 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2434 pub struct PathType {
2435 pub(crate) syntax: SyntaxNode,
2437 impl AstNode for PathType {
2438 fn can_cast(kind: SyntaxKind) -> bool {
2444 fn cast(syntax: SyntaxNode) -> Option<Self> {
2445 if Self::can_cast(syntax.kind()) {
2446 Some(Self { syntax })
2451 fn syntax(&self) -> &SyntaxNode {
2456 pub fn path(&self) -> Option<Path> {
2457 AstChildren::new(&self.syntax).next()
2460 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2461 pub struct PlaceholderPat {
2462 pub(crate) syntax: SyntaxNode,
2464 impl AstNode for PlaceholderPat {
2465 fn can_cast(kind: SyntaxKind) -> bool {
2467 PLACEHOLDER_PAT => true,
2471 fn cast(syntax: SyntaxNode) -> Option<Self> {
2472 if Self::can_cast(syntax.kind()) {
2473 Some(Self { syntax })
2478 fn syntax(&self) -> &SyntaxNode {
2482 impl PlaceholderPat {}
2483 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2484 pub struct PlaceholderType {
2485 pub(crate) syntax: SyntaxNode,
2487 impl AstNode for PlaceholderType {
2488 fn can_cast(kind: SyntaxKind) -> bool {
2490 PLACEHOLDER_TYPE => true,
2494 fn cast(syntax: SyntaxNode) -> Option<Self> {
2495 if Self::can_cast(syntax.kind()) {
2496 Some(Self { syntax })
2501 fn syntax(&self) -> &SyntaxNode {
2505 impl PlaceholderType {}
2506 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2507 pub struct PointerType {
2508 pub(crate) syntax: SyntaxNode,
2510 impl AstNode for PointerType {
2511 fn can_cast(kind: SyntaxKind) -> bool {
2513 POINTER_TYPE => true,
2517 fn cast(syntax: SyntaxNode) -> Option<Self> {
2518 if Self::can_cast(syntax.kind()) {
2519 Some(Self { syntax })
2524 fn syntax(&self) -> &SyntaxNode {
2529 pub fn type_ref(&self) -> Option<TypeRef> {
2530 AstChildren::new(&self.syntax).next()
2533 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2534 pub struct PrefixExpr {
2535 pub(crate) syntax: SyntaxNode,
2537 impl AstNode for PrefixExpr {
2538 fn can_cast(kind: SyntaxKind) -> bool {
2540 PREFIX_EXPR => true,
2544 fn cast(syntax: SyntaxNode) -> Option<Self> {
2545 if Self::can_cast(syntax.kind()) {
2546 Some(Self { syntax })
2551 fn syntax(&self) -> &SyntaxNode {
2556 pub fn expr(&self) -> Option<Expr> {
2557 AstChildren::new(&self.syntax).next()
2560 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2561 pub struct RangeExpr {
2562 pub(crate) syntax: SyntaxNode,
2564 impl AstNode for RangeExpr {
2565 fn can_cast(kind: SyntaxKind) -> bool {
2571 fn cast(syntax: SyntaxNode) -> Option<Self> {
2572 if Self::can_cast(syntax.kind()) {
2573 Some(Self { syntax })
2578 fn syntax(&self) -> &SyntaxNode {
2583 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2584 pub struct RangePat {
2585 pub(crate) syntax: SyntaxNode,
2587 impl AstNode for RangePat {
2588 fn can_cast(kind: SyntaxKind) -> bool {
2594 fn cast(syntax: SyntaxNode) -> Option<Self> {
2595 if Self::can_cast(syntax.kind()) {
2596 Some(Self { syntax })
2601 fn syntax(&self) -> &SyntaxNode {
2606 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2607 pub struct RecordField {
2608 pub(crate) syntax: SyntaxNode,
2610 impl AstNode for RecordField {
2611 fn can_cast(kind: SyntaxKind) -> bool {
2613 RECORD_FIELD => true,
2617 fn cast(syntax: SyntaxNode) -> Option<Self> {
2618 if Self::can_cast(syntax.kind()) {
2619 Some(Self { syntax })
2624 fn syntax(&self) -> &SyntaxNode {
2629 pub fn name_ref(&self) -> Option<NameRef> {
2630 AstChildren::new(&self.syntax).next()
2632 pub fn expr(&self) -> Option<Expr> {
2633 AstChildren::new(&self.syntax).next()
2636 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2637 pub struct RecordFieldDef {
2638 pub(crate) syntax: SyntaxNode,
2640 impl AstNode for RecordFieldDef {
2641 fn can_cast(kind: SyntaxKind) -> bool {
2643 RECORD_FIELD_DEF => true,
2647 fn cast(syntax: SyntaxNode) -> Option<Self> {
2648 if Self::can_cast(syntax.kind()) {
2649 Some(Self { syntax })
2654 fn syntax(&self) -> &SyntaxNode {
2658 impl ast::VisibilityOwner for RecordFieldDef {}
2659 impl ast::NameOwner for RecordFieldDef {}
2660 impl ast::AttrsOwner for RecordFieldDef {}
2661 impl ast::DocCommentsOwner for RecordFieldDef {}
2662 impl ast::TypeAscriptionOwner for RecordFieldDef {}
2663 impl RecordFieldDef {}
2664 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2665 pub struct RecordFieldDefList {
2666 pub(crate) syntax: SyntaxNode,
2668 impl AstNode for RecordFieldDefList {
2669 fn can_cast(kind: SyntaxKind) -> bool {
2671 RECORD_FIELD_DEF_LIST => true,
2675 fn cast(syntax: SyntaxNode) -> Option<Self> {
2676 if Self::can_cast(syntax.kind()) {
2677 Some(Self { syntax })
2682 fn syntax(&self) -> &SyntaxNode {
2686 impl RecordFieldDefList {
2687 pub fn fields(&self) -> AstChildren<RecordFieldDef> {
2688 AstChildren::new(&self.syntax)
2691 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2692 pub struct RecordFieldList {
2693 pub(crate) syntax: SyntaxNode,
2695 impl AstNode for RecordFieldList {
2696 fn can_cast(kind: SyntaxKind) -> bool {
2698 RECORD_FIELD_LIST => true,
2702 fn cast(syntax: SyntaxNode) -> Option<Self> {
2703 if Self::can_cast(syntax.kind()) {
2704 Some(Self { syntax })
2709 fn syntax(&self) -> &SyntaxNode {
2713 impl RecordFieldList {
2714 pub fn fields(&self) -> AstChildren<RecordField> {
2715 AstChildren::new(&self.syntax)
2717 pub fn spread(&self) -> Option<Expr> {
2718 AstChildren::new(&self.syntax).next()
2721 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2722 pub struct RecordFieldPat {
2723 pub(crate) syntax: SyntaxNode,
2725 impl AstNode for RecordFieldPat {
2726 fn can_cast(kind: SyntaxKind) -> bool {
2728 RECORD_FIELD_PAT => true,
2732 fn cast(syntax: SyntaxNode) -> Option<Self> {
2733 if Self::can_cast(syntax.kind()) {
2734 Some(Self { syntax })
2739 fn syntax(&self) -> &SyntaxNode {
2743 impl ast::NameOwner for RecordFieldPat {}
2744 impl RecordFieldPat {
2745 pub fn pat(&self) -> Option<Pat> {
2746 AstChildren::new(&self.syntax).next()
2749 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2750 pub struct RecordFieldPatList {
2751 pub(crate) syntax: SyntaxNode,
2753 impl AstNode for RecordFieldPatList {
2754 fn can_cast(kind: SyntaxKind) -> bool {
2756 RECORD_FIELD_PAT_LIST => true,
2760 fn cast(syntax: SyntaxNode) -> Option<Self> {
2761 if Self::can_cast(syntax.kind()) {
2762 Some(Self { syntax })
2767 fn syntax(&self) -> &SyntaxNode {
2771 impl RecordFieldPatList {
2772 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
2773 AstChildren::new(&self.syntax)
2775 pub fn bind_pats(&self) -> AstChildren<BindPat> {
2776 AstChildren::new(&self.syntax)
2779 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2780 pub struct RecordLit {
2781 pub(crate) syntax: SyntaxNode,
2783 impl AstNode for RecordLit {
2784 fn can_cast(kind: SyntaxKind) -> bool {
2790 fn cast(syntax: SyntaxNode) -> Option<Self> {
2791 if Self::can_cast(syntax.kind()) {
2792 Some(Self { syntax })
2797 fn syntax(&self) -> &SyntaxNode {
2802 pub fn path(&self) -> Option<Path> {
2803 AstChildren::new(&self.syntax).next()
2805 pub fn record_field_list(&self) -> Option<RecordFieldList> {
2806 AstChildren::new(&self.syntax).next()
2809 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2810 pub struct RecordPat {
2811 pub(crate) syntax: SyntaxNode,
2813 impl AstNode for RecordPat {
2814 fn can_cast(kind: SyntaxKind) -> bool {
2820 fn cast(syntax: SyntaxNode) -> Option<Self> {
2821 if Self::can_cast(syntax.kind()) {
2822 Some(Self { syntax })
2827 fn syntax(&self) -> &SyntaxNode {
2832 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
2833 AstChildren::new(&self.syntax).next()
2835 pub fn path(&self) -> Option<Path> {
2836 AstChildren::new(&self.syntax).next()
2839 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2840 pub struct RefExpr {
2841 pub(crate) syntax: SyntaxNode,
2843 impl AstNode for RefExpr {
2844 fn can_cast(kind: SyntaxKind) -> bool {
2850 fn cast(syntax: SyntaxNode) -> Option<Self> {
2851 if Self::can_cast(syntax.kind()) {
2852 Some(Self { syntax })
2857 fn syntax(&self) -> &SyntaxNode {
2862 pub fn expr(&self) -> Option<Expr> {
2863 AstChildren::new(&self.syntax).next()
2866 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2868 pub(crate) syntax: SyntaxNode,
2870 impl AstNode for RefPat {
2871 fn can_cast(kind: SyntaxKind) -> bool {
2877 fn cast(syntax: SyntaxNode) -> Option<Self> {
2878 if Self::can_cast(syntax.kind()) {
2879 Some(Self { syntax })
2884 fn syntax(&self) -> &SyntaxNode {
2889 pub fn pat(&self) -> Option<Pat> {
2890 AstChildren::new(&self.syntax).next()
2893 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2894 pub struct ReferenceType {
2895 pub(crate) syntax: SyntaxNode,
2897 impl AstNode for ReferenceType {
2898 fn can_cast(kind: SyntaxKind) -> bool {
2900 REFERENCE_TYPE => true,
2904 fn cast(syntax: SyntaxNode) -> Option<Self> {
2905 if Self::can_cast(syntax.kind()) {
2906 Some(Self { syntax })
2911 fn syntax(&self) -> &SyntaxNode {
2915 impl ReferenceType {
2916 pub fn type_ref(&self) -> Option<TypeRef> {
2917 AstChildren::new(&self.syntax).next()
2920 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2921 pub struct RetType {
2922 pub(crate) syntax: SyntaxNode,
2924 impl AstNode for RetType {
2925 fn can_cast(kind: SyntaxKind) -> bool {
2931 fn cast(syntax: SyntaxNode) -> Option<Self> {
2932 if Self::can_cast(syntax.kind()) {
2933 Some(Self { syntax })
2938 fn syntax(&self) -> &SyntaxNode {
2943 pub fn type_ref(&self) -> Option<TypeRef> {
2944 AstChildren::new(&self.syntax).next()
2947 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2948 pub struct ReturnExpr {
2949 pub(crate) syntax: SyntaxNode,
2951 impl AstNode for ReturnExpr {
2952 fn can_cast(kind: SyntaxKind) -> bool {
2954 RETURN_EXPR => true,
2958 fn cast(syntax: SyntaxNode) -> Option<Self> {
2959 if Self::can_cast(syntax.kind()) {
2960 Some(Self { syntax })
2965 fn syntax(&self) -> &SyntaxNode {
2970 pub fn expr(&self) -> Option<Expr> {
2971 AstChildren::new(&self.syntax).next()
2974 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2975 pub struct SelfParam {
2976 pub(crate) syntax: SyntaxNode,
2978 impl AstNode for SelfParam {
2979 fn can_cast(kind: SyntaxKind) -> bool {
2985 fn cast(syntax: SyntaxNode) -> Option<Self> {
2986 if Self::can_cast(syntax.kind()) {
2987 Some(Self { syntax })
2992 fn syntax(&self) -> &SyntaxNode {
2996 impl ast::TypeAscriptionOwner for SelfParam {}
2997 impl ast::AttrsOwner for SelfParam {}
2999 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3000 pub struct SlicePat {
3001 pub(crate) syntax: SyntaxNode,
3003 impl AstNode for SlicePat {
3004 fn can_cast(kind: SyntaxKind) -> bool {
3010 fn cast(syntax: SyntaxNode) -> Option<Self> {
3011 if Self::can_cast(syntax.kind()) {
3012 Some(Self { syntax })
3017 fn syntax(&self) -> &SyntaxNode {
3022 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3023 pub struct SliceType {
3024 pub(crate) syntax: SyntaxNode,
3026 impl AstNode for SliceType {
3027 fn can_cast(kind: SyntaxKind) -> bool {
3033 fn cast(syntax: SyntaxNode) -> Option<Self> {
3034 if Self::can_cast(syntax.kind()) {
3035 Some(Self { syntax })
3040 fn syntax(&self) -> &SyntaxNode {
3045 pub fn type_ref(&self) -> Option<TypeRef> {
3046 AstChildren::new(&self.syntax).next()
3049 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3050 pub struct SourceFile {
3051 pub(crate) syntax: SyntaxNode,
3053 impl AstNode for SourceFile {
3054 fn can_cast(kind: SyntaxKind) -> bool {
3056 SOURCE_FILE => true,
3060 fn cast(syntax: SyntaxNode) -> Option<Self> {
3061 if Self::can_cast(syntax.kind()) {
3062 Some(Self { syntax })
3067 fn syntax(&self) -> &SyntaxNode {
3071 impl ast::ModuleItemOwner for SourceFile {}
3072 impl ast::FnDefOwner for SourceFile {}
3074 pub fn modules(&self) -> AstChildren<Module> {
3075 AstChildren::new(&self.syntax)
3078 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3079 pub struct StaticDef {
3080 pub(crate) syntax: SyntaxNode,
3082 impl AstNode for StaticDef {
3083 fn can_cast(kind: SyntaxKind) -> bool {
3089 fn cast(syntax: SyntaxNode) -> Option<Self> {
3090 if Self::can_cast(syntax.kind()) {
3091 Some(Self { syntax })
3096 fn syntax(&self) -> &SyntaxNode {
3100 impl ast::VisibilityOwner for StaticDef {}
3101 impl ast::NameOwner for StaticDef {}
3102 impl ast::TypeParamsOwner for StaticDef {}
3103 impl ast::AttrsOwner for StaticDef {}
3104 impl ast::DocCommentsOwner for StaticDef {}
3105 impl ast::TypeAscriptionOwner for StaticDef {}
3107 pub fn body(&self) -> Option<Expr> {
3108 AstChildren::new(&self.syntax).next()
3111 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3116 impl From<ExprStmt> for Stmt {
3117 fn from(node: ExprStmt) -> Stmt {
3118 Stmt::ExprStmt(node)
3121 impl From<LetStmt> for Stmt {
3122 fn from(node: LetStmt) -> Stmt {
3126 impl AstNode for Stmt {
3127 fn can_cast(kind: SyntaxKind) -> bool {
3129 EXPR_STMT | LET_STMT => true,
3133 fn cast(syntax: SyntaxNode) -> Option<Self> {
3134 let res = match syntax.kind() {
3135 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
3136 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
3141 fn syntax(&self) -> &SyntaxNode {
3143 Stmt::ExprStmt(it) => &it.syntax,
3144 Stmt::LetStmt(it) => &it.syntax,
3149 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3150 pub struct StructDef {
3151 pub(crate) syntax: SyntaxNode,
3153 impl AstNode for StructDef {
3154 fn can_cast(kind: SyntaxKind) -> bool {
3160 fn cast(syntax: SyntaxNode) -> Option<Self> {
3161 if Self::can_cast(syntax.kind()) {
3162 Some(Self { syntax })
3167 fn syntax(&self) -> &SyntaxNode {
3171 impl ast::VisibilityOwner for StructDef {}
3172 impl ast::NameOwner for StructDef {}
3173 impl ast::TypeParamsOwner for StructDef {}
3174 impl ast::AttrsOwner for StructDef {}
3175 impl ast::DocCommentsOwner for StructDef {}
3177 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3178 pub struct TokenTree {
3179 pub(crate) syntax: SyntaxNode,
3181 impl AstNode for TokenTree {
3182 fn can_cast(kind: SyntaxKind) -> bool {
3188 fn cast(syntax: SyntaxNode) -> Option<Self> {
3189 if Self::can_cast(syntax.kind()) {
3190 Some(Self { syntax })
3195 fn syntax(&self) -> &SyntaxNode {
3200 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3201 pub struct TraitDef {
3202 pub(crate) syntax: SyntaxNode,
3204 impl AstNode for TraitDef {
3205 fn can_cast(kind: SyntaxKind) -> bool {
3211 fn cast(syntax: SyntaxNode) -> Option<Self> {
3212 if Self::can_cast(syntax.kind()) {
3213 Some(Self { syntax })
3218 fn syntax(&self) -> &SyntaxNode {
3222 impl ast::VisibilityOwner for TraitDef {}
3223 impl ast::NameOwner for TraitDef {}
3224 impl ast::AttrsOwner for TraitDef {}
3225 impl ast::DocCommentsOwner for TraitDef {}
3226 impl ast::TypeParamsOwner for TraitDef {}
3227 impl ast::TypeBoundsOwner for TraitDef {}
3229 pub fn item_list(&self) -> Option<ItemList> {
3230 AstChildren::new(&self.syntax).next()
3233 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3234 pub struct TryBlockExpr {
3235 pub(crate) syntax: SyntaxNode,
3237 impl AstNode for TryBlockExpr {
3238 fn can_cast(kind: SyntaxKind) -> bool {
3240 TRY_BLOCK_EXPR => true,
3244 fn cast(syntax: SyntaxNode) -> Option<Self> {
3245 if Self::can_cast(syntax.kind()) {
3246 Some(Self { syntax })
3251 fn syntax(&self) -> &SyntaxNode {
3256 pub fn body(&self) -> Option<BlockExpr> {
3257 AstChildren::new(&self.syntax).next()
3260 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3261 pub struct TryExpr {
3262 pub(crate) syntax: SyntaxNode,
3264 impl AstNode for TryExpr {
3265 fn can_cast(kind: SyntaxKind) -> bool {
3271 fn cast(syntax: SyntaxNode) -> Option<Self> {
3272 if Self::can_cast(syntax.kind()) {
3273 Some(Self { syntax })
3278 fn syntax(&self) -> &SyntaxNode {
3283 pub fn expr(&self) -> Option<Expr> {
3284 AstChildren::new(&self.syntax).next()
3287 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3288 pub struct TupleExpr {
3289 pub(crate) syntax: SyntaxNode,
3291 impl AstNode for TupleExpr {
3292 fn can_cast(kind: SyntaxKind) -> bool {
3298 fn cast(syntax: SyntaxNode) -> Option<Self> {
3299 if Self::can_cast(syntax.kind()) {
3300 Some(Self { syntax })
3305 fn syntax(&self) -> &SyntaxNode {
3310 pub fn exprs(&self) -> AstChildren<Expr> {
3311 AstChildren::new(&self.syntax)
3314 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3315 pub struct TupleFieldDef {
3316 pub(crate) syntax: SyntaxNode,
3318 impl AstNode for TupleFieldDef {
3319 fn can_cast(kind: SyntaxKind) -> bool {
3321 TUPLE_FIELD_DEF => true,
3325 fn cast(syntax: SyntaxNode) -> Option<Self> {
3326 if Self::can_cast(syntax.kind()) {
3327 Some(Self { syntax })
3332 fn syntax(&self) -> &SyntaxNode {
3336 impl ast::VisibilityOwner for TupleFieldDef {}
3337 impl ast::AttrsOwner for TupleFieldDef {}
3338 impl TupleFieldDef {
3339 pub fn type_ref(&self) -> Option<TypeRef> {
3340 AstChildren::new(&self.syntax).next()
3343 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3344 pub struct TupleFieldDefList {
3345 pub(crate) syntax: SyntaxNode,
3347 impl AstNode for TupleFieldDefList {
3348 fn can_cast(kind: SyntaxKind) -> bool {
3350 TUPLE_FIELD_DEF_LIST => true,
3354 fn cast(syntax: SyntaxNode) -> Option<Self> {
3355 if Self::can_cast(syntax.kind()) {
3356 Some(Self { syntax })
3361 fn syntax(&self) -> &SyntaxNode {
3365 impl TupleFieldDefList {
3366 pub fn fields(&self) -> AstChildren<TupleFieldDef> {
3367 AstChildren::new(&self.syntax)
3370 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3371 pub struct TuplePat {
3372 pub(crate) syntax: SyntaxNode,
3374 impl AstNode for TuplePat {
3375 fn can_cast(kind: SyntaxKind) -> bool {
3381 fn cast(syntax: SyntaxNode) -> Option<Self> {
3382 if Self::can_cast(syntax.kind()) {
3383 Some(Self { syntax })
3388 fn syntax(&self) -> &SyntaxNode {
3393 pub fn args(&self) -> AstChildren<Pat> {
3394 AstChildren::new(&self.syntax)
3397 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3398 pub struct TupleStructPat {
3399 pub(crate) syntax: SyntaxNode,
3401 impl AstNode for TupleStructPat {
3402 fn can_cast(kind: SyntaxKind) -> bool {
3404 TUPLE_STRUCT_PAT => true,
3408 fn cast(syntax: SyntaxNode) -> Option<Self> {
3409 if Self::can_cast(syntax.kind()) {
3410 Some(Self { syntax })
3415 fn syntax(&self) -> &SyntaxNode {
3419 impl TupleStructPat {
3420 pub fn args(&self) -> AstChildren<Pat> {
3421 AstChildren::new(&self.syntax)
3423 pub fn path(&self) -> Option<Path> {
3424 AstChildren::new(&self.syntax).next()
3427 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3428 pub struct TupleType {
3429 pub(crate) syntax: SyntaxNode,
3431 impl AstNode for TupleType {
3432 fn can_cast(kind: SyntaxKind) -> bool {
3438 fn cast(syntax: SyntaxNode) -> Option<Self> {
3439 if Self::can_cast(syntax.kind()) {
3440 Some(Self { syntax })
3445 fn syntax(&self) -> &SyntaxNode {
3450 pub fn fields(&self) -> AstChildren<TypeRef> {
3451 AstChildren::new(&self.syntax)
3454 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3455 pub struct TypeAliasDef {
3456 pub(crate) syntax: SyntaxNode,
3458 impl AstNode for TypeAliasDef {
3459 fn can_cast(kind: SyntaxKind) -> bool {
3461 TYPE_ALIAS_DEF => true,
3465 fn cast(syntax: SyntaxNode) -> Option<Self> {
3466 if Self::can_cast(syntax.kind()) {
3467 Some(Self { syntax })
3472 fn syntax(&self) -> &SyntaxNode {
3476 impl ast::VisibilityOwner for TypeAliasDef {}
3477 impl ast::NameOwner for TypeAliasDef {}
3478 impl ast::TypeParamsOwner for TypeAliasDef {}
3479 impl ast::AttrsOwner for TypeAliasDef {}
3480 impl ast::DocCommentsOwner for TypeAliasDef {}
3481 impl ast::TypeBoundsOwner for TypeAliasDef {}
3483 pub fn type_ref(&self) -> Option<TypeRef> {
3484 AstChildren::new(&self.syntax).next()
3487 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3488 pub struct TypeArg {
3489 pub(crate) syntax: SyntaxNode,
3491 impl AstNode for TypeArg {
3492 fn can_cast(kind: SyntaxKind) -> bool {
3498 fn cast(syntax: SyntaxNode) -> Option<Self> {
3499 if Self::can_cast(syntax.kind()) {
3500 Some(Self { syntax })
3505 fn syntax(&self) -> &SyntaxNode {
3510 pub fn type_ref(&self) -> Option<TypeRef> {
3511 AstChildren::new(&self.syntax).next()
3514 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3515 pub struct TypeArgList {
3516 pub(crate) syntax: SyntaxNode,
3518 impl AstNode for TypeArgList {
3519 fn can_cast(kind: SyntaxKind) -> bool {
3521 TYPE_ARG_LIST => true,
3525 fn cast(syntax: SyntaxNode) -> Option<Self> {
3526 if Self::can_cast(syntax.kind()) {
3527 Some(Self { syntax })
3532 fn syntax(&self) -> &SyntaxNode {
3537 pub fn type_args(&self) -> AstChildren<TypeArg> {
3538 AstChildren::new(&self.syntax)
3540 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3541 AstChildren::new(&self.syntax)
3543 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3544 AstChildren::new(&self.syntax)
3547 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3548 pub struct TypeBound {
3549 pub(crate) syntax: SyntaxNode,
3551 impl AstNode for TypeBound {
3552 fn can_cast(kind: SyntaxKind) -> bool {
3558 fn cast(syntax: SyntaxNode) -> Option<Self> {
3559 if Self::can_cast(syntax.kind()) {
3560 Some(Self { syntax })
3565 fn syntax(&self) -> &SyntaxNode {
3570 pub fn type_ref(&self) -> Option<TypeRef> {
3571 AstChildren::new(&self.syntax).next()
3574 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3575 pub struct TypeBoundList {
3576 pub(crate) syntax: SyntaxNode,
3578 impl AstNode for TypeBoundList {
3579 fn can_cast(kind: SyntaxKind) -> bool {
3581 TYPE_BOUND_LIST => true,
3585 fn cast(syntax: SyntaxNode) -> Option<Self> {
3586 if Self::can_cast(syntax.kind()) {
3587 Some(Self { syntax })
3592 fn syntax(&self) -> &SyntaxNode {
3596 impl TypeBoundList {
3597 pub fn bounds(&self) -> AstChildren<TypeBound> {
3598 AstChildren::new(&self.syntax)
3601 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3602 pub struct TypeParam {
3603 pub(crate) syntax: SyntaxNode,
3605 impl AstNode for TypeParam {
3606 fn can_cast(kind: SyntaxKind) -> bool {
3612 fn cast(syntax: SyntaxNode) -> Option<Self> {
3613 if Self::can_cast(syntax.kind()) {
3614 Some(Self { syntax })
3619 fn syntax(&self) -> &SyntaxNode {
3623 impl ast::NameOwner for TypeParam {}
3624 impl ast::AttrsOwner for TypeParam {}
3625 impl ast::TypeBoundsOwner for TypeParam {}
3626 impl ast::DefaultTypeParamOwner for TypeParam {}
3628 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3629 pub struct TypeParamList {
3630 pub(crate) syntax: SyntaxNode,
3632 impl AstNode for TypeParamList {
3633 fn can_cast(kind: SyntaxKind) -> bool {
3635 TYPE_PARAM_LIST => true,
3639 fn cast(syntax: SyntaxNode) -> Option<Self> {
3640 if Self::can_cast(syntax.kind()) {
3641 Some(Self { syntax })
3646 fn syntax(&self) -> &SyntaxNode {
3650 impl TypeParamList {
3651 pub fn type_params(&self) -> AstChildren<TypeParam> {
3652 AstChildren::new(&self.syntax)
3654 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3655 AstChildren::new(&self.syntax)
3658 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3660 ParenType(ParenType),
3661 TupleType(TupleType),
3662 NeverType(NeverType),
3664 PointerType(PointerType),
3665 ArrayType(ArrayType),
3666 SliceType(SliceType),
3667 ReferenceType(ReferenceType),
3668 PlaceholderType(PlaceholderType),
3669 FnPointerType(FnPointerType),
3671 ImplTraitType(ImplTraitType),
3672 DynTraitType(DynTraitType),
3674 impl From<ParenType> for TypeRef {
3675 fn from(node: ParenType) -> TypeRef {
3676 TypeRef::ParenType(node)
3679 impl From<TupleType> for TypeRef {
3680 fn from(node: TupleType) -> TypeRef {
3681 TypeRef::TupleType(node)
3684 impl From<NeverType> for TypeRef {
3685 fn from(node: NeverType) -> TypeRef {
3686 TypeRef::NeverType(node)
3689 impl From<PathType> for TypeRef {
3690 fn from(node: PathType) -> TypeRef {
3691 TypeRef::PathType(node)
3694 impl From<PointerType> for TypeRef {
3695 fn from(node: PointerType) -> TypeRef {
3696 TypeRef::PointerType(node)
3699 impl From<ArrayType> for TypeRef {
3700 fn from(node: ArrayType) -> TypeRef {
3701 TypeRef::ArrayType(node)
3704 impl From<SliceType> for TypeRef {
3705 fn from(node: SliceType) -> TypeRef {
3706 TypeRef::SliceType(node)
3709 impl From<ReferenceType> for TypeRef {
3710 fn from(node: ReferenceType) -> TypeRef {
3711 TypeRef::ReferenceType(node)
3714 impl From<PlaceholderType> for TypeRef {
3715 fn from(node: PlaceholderType) -> TypeRef {
3716 TypeRef::PlaceholderType(node)
3719 impl From<FnPointerType> for TypeRef {
3720 fn from(node: FnPointerType) -> TypeRef {
3721 TypeRef::FnPointerType(node)
3724 impl From<ForType> for TypeRef {
3725 fn from(node: ForType) -> TypeRef {
3726 TypeRef::ForType(node)
3729 impl From<ImplTraitType> for TypeRef {
3730 fn from(node: ImplTraitType) -> TypeRef {
3731 TypeRef::ImplTraitType(node)
3734 impl From<DynTraitType> for TypeRef {
3735 fn from(node: DynTraitType) -> TypeRef {
3736 TypeRef::DynTraitType(node)
3739 impl AstNode for TypeRef {
3740 fn can_cast(kind: SyntaxKind) -> bool {
3742 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3743 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3744 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3748 fn cast(syntax: SyntaxNode) -> Option<Self> {
3749 let res = match syntax.kind() {
3750 PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
3751 TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
3752 NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
3753 PATH_TYPE => TypeRef::PathType(PathType { syntax }),
3754 POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
3755 ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
3756 SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
3757 REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
3758 PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
3759 FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
3760 FOR_TYPE => TypeRef::ForType(ForType { syntax }),
3761 IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
3762 DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
3767 fn syntax(&self) -> &SyntaxNode {
3769 TypeRef::ParenType(it) => &it.syntax,
3770 TypeRef::TupleType(it) => &it.syntax,
3771 TypeRef::NeverType(it) => &it.syntax,
3772 TypeRef::PathType(it) => &it.syntax,
3773 TypeRef::PointerType(it) => &it.syntax,
3774 TypeRef::ArrayType(it) => &it.syntax,
3775 TypeRef::SliceType(it) => &it.syntax,
3776 TypeRef::ReferenceType(it) => &it.syntax,
3777 TypeRef::PlaceholderType(it) => &it.syntax,
3778 TypeRef::FnPointerType(it) => &it.syntax,
3779 TypeRef::ForType(it) => &it.syntax,
3780 TypeRef::ImplTraitType(it) => &it.syntax,
3781 TypeRef::DynTraitType(it) => &it.syntax,
3786 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3787 pub struct UseItem {
3788 pub(crate) syntax: SyntaxNode,
3790 impl AstNode for UseItem {
3791 fn can_cast(kind: SyntaxKind) -> bool {
3797 fn cast(syntax: SyntaxNode) -> Option<Self> {
3798 if Self::can_cast(syntax.kind()) {
3799 Some(Self { syntax })
3804 fn syntax(&self) -> &SyntaxNode {
3808 impl ast::AttrsOwner for UseItem {}
3810 pub fn use_tree(&self) -> Option<UseTree> {
3811 AstChildren::new(&self.syntax).next()
3814 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3815 pub struct UseTree {
3816 pub(crate) syntax: SyntaxNode,
3818 impl AstNode for UseTree {
3819 fn can_cast(kind: SyntaxKind) -> bool {
3825 fn cast(syntax: SyntaxNode) -> Option<Self> {
3826 if Self::can_cast(syntax.kind()) {
3827 Some(Self { syntax })
3832 fn syntax(&self) -> &SyntaxNode {
3837 pub fn path(&self) -> Option<Path> {
3838 AstChildren::new(&self.syntax).next()
3840 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3841 AstChildren::new(&self.syntax).next()
3843 pub fn alias(&self) -> Option<Alias> {
3844 AstChildren::new(&self.syntax).next()
3847 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3848 pub struct UseTreeList {
3849 pub(crate) syntax: SyntaxNode,
3851 impl AstNode for UseTreeList {
3852 fn can_cast(kind: SyntaxKind) -> bool {
3854 USE_TREE_LIST => true,
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 use_trees(&self) -> AstChildren<UseTree> {
3871 AstChildren::new(&self.syntax)
3874 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3875 pub struct Visibility {
3876 pub(crate) syntax: SyntaxNode,
3878 impl AstNode for Visibility {
3879 fn can_cast(kind: SyntaxKind) -> bool {
3885 fn cast(syntax: SyntaxNode) -> Option<Self> {
3886 if Self::can_cast(syntax.kind()) {
3887 Some(Self { syntax })
3892 fn syntax(&self) -> &SyntaxNode {
3897 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3898 pub struct WhereClause {
3899 pub(crate) syntax: SyntaxNode,
3901 impl AstNode for WhereClause {
3902 fn can_cast(kind: SyntaxKind) -> bool {
3904 WHERE_CLAUSE => true,
3908 fn cast(syntax: SyntaxNode) -> Option<Self> {
3909 if Self::can_cast(syntax.kind()) {
3910 Some(Self { syntax })
3915 fn syntax(&self) -> &SyntaxNode {
3920 pub fn predicates(&self) -> AstChildren<WherePred> {
3921 AstChildren::new(&self.syntax)
3924 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3925 pub struct WherePred {
3926 pub(crate) syntax: SyntaxNode,
3928 impl AstNode for WherePred {
3929 fn can_cast(kind: SyntaxKind) -> bool {
3935 fn cast(syntax: SyntaxNode) -> Option<Self> {
3936 if Self::can_cast(syntax.kind()) {
3937 Some(Self { syntax })
3942 fn syntax(&self) -> &SyntaxNode {
3946 impl ast::TypeBoundsOwner for WherePred {}
3948 pub fn type_ref(&self) -> Option<TypeRef> {
3949 AstChildren::new(&self.syntax).next()
3952 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3953 pub struct WhileExpr {
3954 pub(crate) syntax: SyntaxNode,
3956 impl AstNode for WhileExpr {
3957 fn can_cast(kind: SyntaxKind) -> bool {
3963 fn cast(syntax: SyntaxNode) -> Option<Self> {
3964 if Self::can_cast(syntax.kind()) {
3965 Some(Self { syntax })
3970 fn syntax(&self) -> &SyntaxNode {
3974 impl ast::LoopBodyOwner for WhileExpr {}
3976 pub fn condition(&self) -> Option<Condition> {
3977 AstChildren::new(&self.syntax).next()