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()
175 pub fn value(&self) -> Option<TokenTree> {
176 AstChildren::new(&self.syntax).next()
179 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
182 TokenTree(TokenTree),
184 impl From<Literal> for AttrInput {
185 fn from(node: Literal) -> AttrInput {
186 AttrInput::Literal(node)
189 impl From<TokenTree> for AttrInput {
190 fn from(node: TokenTree) -> AttrInput {
191 AttrInput::TokenTree(node)
194 impl AstNode for AttrInput {
195 fn can_cast(kind: SyntaxKind) -> bool {
197 LITERAL | TOKEN_TREE => true,
201 fn cast(syntax: SyntaxNode) -> Option<Self> {
202 let res = match syntax.kind() {
203 LITERAL => AttrInput::Literal(Literal { syntax }),
204 TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }),
209 fn syntax(&self) -> &SyntaxNode {
211 AttrInput::Literal(it) => &it.syntax,
212 AttrInput::TokenTree(it) => &it.syntax,
217 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
218 pub struct AwaitExpr {
219 pub(crate) syntax: SyntaxNode,
221 impl AstNode for AwaitExpr {
222 fn can_cast(kind: SyntaxKind) -> bool {
228 fn cast(syntax: SyntaxNode) -> Option<Self> {
229 if Self::can_cast(syntax.kind()) {
230 Some(Self { syntax })
235 fn syntax(&self) -> &SyntaxNode {
240 pub fn expr(&self) -> Option<Expr> {
241 AstChildren::new(&self.syntax).next()
244 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
246 pub(crate) syntax: SyntaxNode,
248 impl AstNode for BinExpr {
249 fn can_cast(kind: SyntaxKind) -> bool {
255 fn cast(syntax: SyntaxNode) -> Option<Self> {
256 if Self::can_cast(syntax.kind()) {
257 Some(Self { syntax })
262 fn syntax(&self) -> &SyntaxNode {
267 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
269 pub(crate) syntax: SyntaxNode,
271 impl AstNode for BindPat {
272 fn can_cast(kind: SyntaxKind) -> bool {
278 fn cast(syntax: SyntaxNode) -> Option<Self> {
279 if Self::can_cast(syntax.kind()) {
280 Some(Self { syntax })
285 fn syntax(&self) -> &SyntaxNode {
289 impl ast::NameOwner for BindPat {}
291 pub fn pat(&self) -> Option<Pat> {
292 AstChildren::new(&self.syntax).next()
295 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
297 pub(crate) syntax: SyntaxNode,
299 impl AstNode for Block {
300 fn can_cast(kind: SyntaxKind) -> bool {
306 fn cast(syntax: SyntaxNode) -> Option<Self> {
307 if Self::can_cast(syntax.kind()) {
308 Some(Self { syntax })
313 fn syntax(&self) -> &SyntaxNode {
317 impl ast::AttrsOwner for Block {}
319 pub fn statements(&self) -> AstChildren<Stmt> {
320 AstChildren::new(&self.syntax)
322 pub fn expr(&self) -> Option<Expr> {
323 AstChildren::new(&self.syntax).next()
326 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
327 pub struct BlockExpr {
328 pub(crate) syntax: SyntaxNode,
330 impl AstNode for BlockExpr {
331 fn can_cast(kind: SyntaxKind) -> bool {
337 fn cast(syntax: SyntaxNode) -> Option<Self> {
338 if Self::can_cast(syntax.kind()) {
339 Some(Self { syntax })
344 fn syntax(&self) -> &SyntaxNode {
349 pub fn block(&self) -> Option<Block> {
350 AstChildren::new(&self.syntax).next()
353 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
355 pub(crate) syntax: SyntaxNode,
357 impl AstNode for BoxExpr {
358 fn can_cast(kind: SyntaxKind) -> bool {
364 fn cast(syntax: SyntaxNode) -> Option<Self> {
365 if Self::can_cast(syntax.kind()) {
366 Some(Self { syntax })
371 fn syntax(&self) -> &SyntaxNode {
376 pub fn expr(&self) -> Option<Expr> {
377 AstChildren::new(&self.syntax).next()
380 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
382 pub(crate) syntax: SyntaxNode,
384 impl AstNode for BoxPat {
385 fn can_cast(kind: SyntaxKind) -> bool {
391 fn cast(syntax: SyntaxNode) -> Option<Self> {
392 if Self::can_cast(syntax.kind()) {
393 Some(Self { syntax })
398 fn syntax(&self) -> &SyntaxNode {
403 pub fn pat(&self) -> Option<Pat> {
404 AstChildren::new(&self.syntax).next()
407 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
408 pub struct BreakExpr {
409 pub(crate) syntax: SyntaxNode,
411 impl AstNode for BreakExpr {
412 fn can_cast(kind: SyntaxKind) -> bool {
418 fn cast(syntax: SyntaxNode) -> Option<Self> {
419 if Self::can_cast(syntax.kind()) {
420 Some(Self { syntax })
425 fn syntax(&self) -> &SyntaxNode {
430 pub fn expr(&self) -> Option<Expr> {
431 AstChildren::new(&self.syntax).next()
434 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
435 pub struct CallExpr {
436 pub(crate) syntax: SyntaxNode,
438 impl AstNode for CallExpr {
439 fn can_cast(kind: SyntaxKind) -> bool {
445 fn cast(syntax: SyntaxNode) -> Option<Self> {
446 if Self::can_cast(syntax.kind()) {
447 Some(Self { syntax })
452 fn syntax(&self) -> &SyntaxNode {
456 impl ast::ArgListOwner for CallExpr {}
458 pub fn expr(&self) -> Option<Expr> {
459 AstChildren::new(&self.syntax).next()
462 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
463 pub struct CastExpr {
464 pub(crate) syntax: SyntaxNode,
466 impl AstNode for CastExpr {
467 fn can_cast(kind: SyntaxKind) -> bool {
473 fn cast(syntax: SyntaxNode) -> Option<Self> {
474 if Self::can_cast(syntax.kind()) {
475 Some(Self { syntax })
480 fn syntax(&self) -> &SyntaxNode {
485 pub fn expr(&self) -> Option<Expr> {
486 AstChildren::new(&self.syntax).next()
488 pub fn type_ref(&self) -> Option<TypeRef> {
489 AstChildren::new(&self.syntax).next()
492 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
493 pub struct Condition {
494 pub(crate) syntax: SyntaxNode,
496 impl AstNode for Condition {
497 fn can_cast(kind: SyntaxKind) -> bool {
503 fn cast(syntax: SyntaxNode) -> Option<Self> {
504 if Self::can_cast(syntax.kind()) {
505 Some(Self { syntax })
510 fn syntax(&self) -> &SyntaxNode {
515 pub fn pat(&self) -> Option<Pat> {
516 AstChildren::new(&self.syntax).next()
518 pub fn expr(&self) -> Option<Expr> {
519 AstChildren::new(&self.syntax).next()
522 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
523 pub struct ConstDef {
524 pub(crate) syntax: SyntaxNode,
526 impl AstNode for ConstDef {
527 fn can_cast(kind: SyntaxKind) -> bool {
533 fn cast(syntax: SyntaxNode) -> Option<Self> {
534 if Self::can_cast(syntax.kind()) {
535 Some(Self { syntax })
540 fn syntax(&self) -> &SyntaxNode {
544 impl ast::VisibilityOwner for ConstDef {}
545 impl ast::NameOwner for ConstDef {}
546 impl ast::TypeParamsOwner for ConstDef {}
547 impl ast::AttrsOwner for ConstDef {}
548 impl ast::DocCommentsOwner for ConstDef {}
549 impl ast::TypeAscriptionOwner for ConstDef {}
551 pub fn body(&self) -> Option<Expr> {
552 AstChildren::new(&self.syntax).next()
555 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
556 pub struct ContinueExpr {
557 pub(crate) syntax: SyntaxNode,
559 impl AstNode for ContinueExpr {
560 fn can_cast(kind: SyntaxKind) -> bool {
562 CONTINUE_EXPR => true,
566 fn cast(syntax: SyntaxNode) -> Option<Self> {
567 if Self::can_cast(syntax.kind()) {
568 Some(Self { syntax })
573 fn syntax(&self) -> &SyntaxNode {
578 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
579 pub struct DotDotPat {
580 pub(crate) syntax: SyntaxNode,
582 impl AstNode for DotDotPat {
583 fn can_cast(kind: SyntaxKind) -> bool {
589 fn cast(syntax: SyntaxNode) -> Option<Self> {
590 if Self::can_cast(syntax.kind()) {
591 Some(Self { syntax })
596 fn syntax(&self) -> &SyntaxNode {
601 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
602 pub struct DynTraitType {
603 pub(crate) syntax: SyntaxNode,
605 impl AstNode for DynTraitType {
606 fn can_cast(kind: SyntaxKind) -> bool {
608 DYN_TRAIT_TYPE => true,
612 fn cast(syntax: SyntaxNode) -> Option<Self> {
613 if Self::can_cast(syntax.kind()) {
614 Some(Self { syntax })
619 fn syntax(&self) -> &SyntaxNode {
623 impl ast::TypeBoundsOwner for DynTraitType {}
625 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
627 pub(crate) syntax: SyntaxNode,
629 impl AstNode for EnumDef {
630 fn can_cast(kind: SyntaxKind) -> bool {
636 fn cast(syntax: SyntaxNode) -> Option<Self> {
637 if Self::can_cast(syntax.kind()) {
638 Some(Self { syntax })
643 fn syntax(&self) -> &SyntaxNode {
647 impl ast::VisibilityOwner for EnumDef {}
648 impl ast::NameOwner for EnumDef {}
649 impl ast::TypeParamsOwner for EnumDef {}
650 impl ast::AttrsOwner for EnumDef {}
651 impl ast::DocCommentsOwner for EnumDef {}
653 pub fn variant_list(&self) -> Option<EnumVariantList> {
654 AstChildren::new(&self.syntax).next()
657 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
658 pub struct EnumVariant {
659 pub(crate) syntax: SyntaxNode,
661 impl AstNode for EnumVariant {
662 fn can_cast(kind: SyntaxKind) -> bool {
664 ENUM_VARIANT => true,
668 fn cast(syntax: SyntaxNode) -> Option<Self> {
669 if Self::can_cast(syntax.kind()) {
670 Some(Self { syntax })
675 fn syntax(&self) -> &SyntaxNode {
679 impl ast::NameOwner for EnumVariant {}
680 impl ast::DocCommentsOwner for EnumVariant {}
681 impl ast::AttrsOwner for EnumVariant {}
683 pub fn expr(&self) -> Option<Expr> {
684 AstChildren::new(&self.syntax).next()
687 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
688 pub struct EnumVariantList {
689 pub(crate) syntax: SyntaxNode,
691 impl AstNode for EnumVariantList {
692 fn can_cast(kind: SyntaxKind) -> bool {
694 ENUM_VARIANT_LIST => true,
698 fn cast(syntax: SyntaxNode) -> Option<Self> {
699 if Self::can_cast(syntax.kind()) {
700 Some(Self { syntax })
705 fn syntax(&self) -> &SyntaxNode {
709 impl EnumVariantList {
710 pub fn variants(&self) -> AstChildren<EnumVariant> {
711 AstChildren::new(&self.syntax)
714 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
716 TupleExpr(TupleExpr),
717 ArrayExpr(ArrayExpr),
718 ParenExpr(ParenExpr),
720 LambdaExpr(LambdaExpr),
724 WhileExpr(WhileExpr),
725 ContinueExpr(ContinueExpr),
726 BreakExpr(BreakExpr),
728 BlockExpr(BlockExpr),
729 ReturnExpr(ReturnExpr),
730 MatchExpr(MatchExpr),
731 RecordLit(RecordLit),
733 IndexExpr(IndexExpr),
734 MethodCallExpr(MethodCallExpr),
735 FieldExpr(FieldExpr),
736 AwaitExpr(AwaitExpr),
738 TryBlockExpr(TryBlockExpr),
741 PrefixExpr(PrefixExpr),
742 RangeExpr(RangeExpr),
745 MacroCall(MacroCall),
748 impl From<TupleExpr> for Expr {
749 fn from(node: TupleExpr) -> Expr {
750 Expr::TupleExpr(node)
753 impl From<ArrayExpr> for Expr {
754 fn from(node: ArrayExpr) -> Expr {
755 Expr::ArrayExpr(node)
758 impl From<ParenExpr> for Expr {
759 fn from(node: ParenExpr) -> Expr {
760 Expr::ParenExpr(node)
763 impl From<PathExpr> for Expr {
764 fn from(node: PathExpr) -> Expr {
768 impl From<LambdaExpr> for Expr {
769 fn from(node: LambdaExpr) -> Expr {
770 Expr::LambdaExpr(node)
773 impl From<IfExpr> for Expr {
774 fn from(node: IfExpr) -> Expr {
778 impl From<LoopExpr> for Expr {
779 fn from(node: LoopExpr) -> Expr {
783 impl From<ForExpr> for Expr {
784 fn from(node: ForExpr) -> Expr {
788 impl From<WhileExpr> for Expr {
789 fn from(node: WhileExpr) -> Expr {
790 Expr::WhileExpr(node)
793 impl From<ContinueExpr> for Expr {
794 fn from(node: ContinueExpr) -> Expr {
795 Expr::ContinueExpr(node)
798 impl From<BreakExpr> for Expr {
799 fn from(node: BreakExpr) -> Expr {
800 Expr::BreakExpr(node)
803 impl From<Label> for Expr {
804 fn from(node: Label) -> Expr {
808 impl From<BlockExpr> for Expr {
809 fn from(node: BlockExpr) -> Expr {
810 Expr::BlockExpr(node)
813 impl From<ReturnExpr> for Expr {
814 fn from(node: ReturnExpr) -> Expr {
815 Expr::ReturnExpr(node)
818 impl From<MatchExpr> for Expr {
819 fn from(node: MatchExpr) -> Expr {
820 Expr::MatchExpr(node)
823 impl From<RecordLit> for Expr {
824 fn from(node: RecordLit) -> Expr {
825 Expr::RecordLit(node)
828 impl From<CallExpr> for Expr {
829 fn from(node: CallExpr) -> Expr {
833 impl From<IndexExpr> for Expr {
834 fn from(node: IndexExpr) -> Expr {
835 Expr::IndexExpr(node)
838 impl From<MethodCallExpr> for Expr {
839 fn from(node: MethodCallExpr) -> Expr {
840 Expr::MethodCallExpr(node)
843 impl From<FieldExpr> for Expr {
844 fn from(node: FieldExpr) -> Expr {
845 Expr::FieldExpr(node)
848 impl From<AwaitExpr> for Expr {
849 fn from(node: AwaitExpr) -> Expr {
850 Expr::AwaitExpr(node)
853 impl From<TryExpr> for Expr {
854 fn from(node: TryExpr) -> Expr {
858 impl From<TryBlockExpr> for Expr {
859 fn from(node: TryBlockExpr) -> Expr {
860 Expr::TryBlockExpr(node)
863 impl From<CastExpr> for Expr {
864 fn from(node: CastExpr) -> Expr {
868 impl From<RefExpr> for Expr {
869 fn from(node: RefExpr) -> Expr {
873 impl From<PrefixExpr> for Expr {
874 fn from(node: PrefixExpr) -> Expr {
875 Expr::PrefixExpr(node)
878 impl From<RangeExpr> for Expr {
879 fn from(node: RangeExpr) -> Expr {
880 Expr::RangeExpr(node)
883 impl From<BinExpr> for Expr {
884 fn from(node: BinExpr) -> Expr {
888 impl From<Literal> for Expr {
889 fn from(node: Literal) -> Expr {
893 impl From<MacroCall> for Expr {
894 fn from(node: MacroCall) -> Expr {
895 Expr::MacroCall(node)
898 impl From<BoxExpr> for Expr {
899 fn from(node: BoxExpr) -> Expr {
903 impl AstNode for Expr {
904 fn can_cast(kind: SyntaxKind) -> bool {
906 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
907 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
908 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
909 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
910 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL
915 fn cast(syntax: SyntaxNode) -> Option<Self> {
916 let res = match syntax.kind() {
917 TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
918 ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }),
919 PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }),
920 PATH_EXPR => Expr::PathExpr(PathExpr { syntax }),
921 LAMBDA_EXPR => Expr::LambdaExpr(LambdaExpr { syntax }),
922 IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
923 LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
924 FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
925 WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
926 CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
927 BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
928 LABEL => Expr::Label(Label { syntax }),
929 BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
930 RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
931 MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
932 RECORD_LIT => Expr::RecordLit(RecordLit { syntax }),
933 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
934 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
935 METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
936 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
937 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
938 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
939 TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
940 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
941 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
942 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
943 RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }),
944 BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
945 LITERAL => Expr::Literal(Literal { syntax }),
946 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
947 BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }),
952 fn syntax(&self) -> &SyntaxNode {
954 Expr::TupleExpr(it) => &it.syntax,
955 Expr::ArrayExpr(it) => &it.syntax,
956 Expr::ParenExpr(it) => &it.syntax,
957 Expr::PathExpr(it) => &it.syntax,
958 Expr::LambdaExpr(it) => &it.syntax,
959 Expr::IfExpr(it) => &it.syntax,
960 Expr::LoopExpr(it) => &it.syntax,
961 Expr::ForExpr(it) => &it.syntax,
962 Expr::WhileExpr(it) => &it.syntax,
963 Expr::ContinueExpr(it) => &it.syntax,
964 Expr::BreakExpr(it) => &it.syntax,
965 Expr::Label(it) => &it.syntax,
966 Expr::BlockExpr(it) => &it.syntax,
967 Expr::ReturnExpr(it) => &it.syntax,
968 Expr::MatchExpr(it) => &it.syntax,
969 Expr::RecordLit(it) => &it.syntax,
970 Expr::CallExpr(it) => &it.syntax,
971 Expr::IndexExpr(it) => &it.syntax,
972 Expr::MethodCallExpr(it) => &it.syntax,
973 Expr::FieldExpr(it) => &it.syntax,
974 Expr::AwaitExpr(it) => &it.syntax,
975 Expr::TryExpr(it) => &it.syntax,
976 Expr::TryBlockExpr(it) => &it.syntax,
977 Expr::CastExpr(it) => &it.syntax,
978 Expr::RefExpr(it) => &it.syntax,
979 Expr::PrefixExpr(it) => &it.syntax,
980 Expr::RangeExpr(it) => &it.syntax,
981 Expr::BinExpr(it) => &it.syntax,
982 Expr::Literal(it) => &it.syntax,
983 Expr::MacroCall(it) => &it.syntax,
984 Expr::BoxExpr(it) => &it.syntax,
989 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
990 pub struct ExprStmt {
991 pub(crate) syntax: SyntaxNode,
993 impl AstNode for ExprStmt {
994 fn can_cast(kind: SyntaxKind) -> bool {
1000 fn cast(syntax: SyntaxNode) -> Option<Self> {
1001 if Self::can_cast(syntax.kind()) {
1002 Some(Self { syntax })
1007 fn syntax(&self) -> &SyntaxNode {
1012 pub fn expr(&self) -> Option<Expr> {
1013 AstChildren::new(&self.syntax).next()
1016 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1017 pub struct ExternCrateItem {
1018 pub(crate) syntax: SyntaxNode,
1020 impl AstNode for ExternCrateItem {
1021 fn can_cast(kind: SyntaxKind) -> bool {
1023 EXTERN_CRATE_ITEM => true,
1027 fn cast(syntax: SyntaxNode) -> Option<Self> {
1028 if Self::can_cast(syntax.kind()) {
1029 Some(Self { syntax })
1034 fn syntax(&self) -> &SyntaxNode {
1038 impl ast::AttrsOwner for ExternCrateItem {}
1039 impl ExternCrateItem {
1040 pub fn name_ref(&self) -> Option<NameRef> {
1041 AstChildren::new(&self.syntax).next()
1043 pub fn alias(&self) -> Option<Alias> {
1044 AstChildren::new(&self.syntax).next()
1047 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1048 pub struct FieldExpr {
1049 pub(crate) syntax: SyntaxNode,
1051 impl AstNode for FieldExpr {
1052 fn can_cast(kind: SyntaxKind) -> bool {
1058 fn cast(syntax: SyntaxNode) -> Option<Self> {
1059 if Self::can_cast(syntax.kind()) {
1060 Some(Self { syntax })
1065 fn syntax(&self) -> &SyntaxNode {
1070 pub fn expr(&self) -> Option<Expr> {
1071 AstChildren::new(&self.syntax).next()
1073 pub fn name_ref(&self) -> Option<NameRef> {
1074 AstChildren::new(&self.syntax).next()
1077 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1079 pub(crate) syntax: SyntaxNode,
1081 impl AstNode for FnDef {
1082 fn can_cast(kind: SyntaxKind) -> bool {
1088 fn cast(syntax: SyntaxNode) -> Option<Self> {
1089 if Self::can_cast(syntax.kind()) {
1090 Some(Self { syntax })
1095 fn syntax(&self) -> &SyntaxNode {
1099 impl ast::VisibilityOwner for FnDef {}
1100 impl ast::NameOwner for FnDef {}
1101 impl ast::TypeParamsOwner for FnDef {}
1102 impl ast::AttrsOwner for FnDef {}
1103 impl ast::DocCommentsOwner for FnDef {}
1105 pub fn param_list(&self) -> Option<ParamList> {
1106 AstChildren::new(&self.syntax).next()
1108 pub fn body(&self) -> Option<BlockExpr> {
1109 AstChildren::new(&self.syntax).next()
1111 pub fn ret_type(&self) -> Option<RetType> {
1112 AstChildren::new(&self.syntax).next()
1115 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1116 pub struct FnPointerType {
1117 pub(crate) syntax: SyntaxNode,
1119 impl AstNode for FnPointerType {
1120 fn can_cast(kind: SyntaxKind) -> bool {
1122 FN_POINTER_TYPE => true,
1126 fn cast(syntax: SyntaxNode) -> Option<Self> {
1127 if Self::can_cast(syntax.kind()) {
1128 Some(Self { syntax })
1133 fn syntax(&self) -> &SyntaxNode {
1137 impl FnPointerType {
1138 pub fn param_list(&self) -> Option<ParamList> {
1139 AstChildren::new(&self.syntax).next()
1141 pub fn ret_type(&self) -> Option<RetType> {
1142 AstChildren::new(&self.syntax).next()
1145 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1146 pub struct ForExpr {
1147 pub(crate) syntax: SyntaxNode,
1149 impl AstNode for ForExpr {
1150 fn can_cast(kind: SyntaxKind) -> bool {
1156 fn cast(syntax: SyntaxNode) -> Option<Self> {
1157 if Self::can_cast(syntax.kind()) {
1158 Some(Self { syntax })
1163 fn syntax(&self) -> &SyntaxNode {
1167 impl ast::LoopBodyOwner for ForExpr {}
1169 pub fn pat(&self) -> Option<Pat> {
1170 AstChildren::new(&self.syntax).next()
1172 pub fn iterable(&self) -> Option<Expr> {
1173 AstChildren::new(&self.syntax).next()
1176 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1177 pub struct ForType {
1178 pub(crate) syntax: SyntaxNode,
1180 impl AstNode for ForType {
1181 fn can_cast(kind: SyntaxKind) -> bool {
1187 fn cast(syntax: SyntaxNode) -> Option<Self> {
1188 if Self::can_cast(syntax.kind()) {
1189 Some(Self { syntax })
1194 fn syntax(&self) -> &SyntaxNode {
1199 pub fn type_ref(&self) -> Option<TypeRef> {
1200 AstChildren::new(&self.syntax).next()
1203 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1205 pub(crate) syntax: SyntaxNode,
1207 impl AstNode for IfExpr {
1208 fn can_cast(kind: SyntaxKind) -> bool {
1214 fn cast(syntax: SyntaxNode) -> Option<Self> {
1215 if Self::can_cast(syntax.kind()) {
1216 Some(Self { syntax })
1221 fn syntax(&self) -> &SyntaxNode {
1226 pub fn condition(&self) -> Option<Condition> {
1227 AstChildren::new(&self.syntax).next()
1230 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1231 pub struct ImplBlock {
1232 pub(crate) syntax: SyntaxNode,
1234 impl AstNode for ImplBlock {
1235 fn can_cast(kind: SyntaxKind) -> bool {
1241 fn cast(syntax: SyntaxNode) -> Option<Self> {
1242 if Self::can_cast(syntax.kind()) {
1243 Some(Self { syntax })
1248 fn syntax(&self) -> &SyntaxNode {
1252 impl ast::TypeParamsOwner for ImplBlock {}
1253 impl ast::AttrsOwner for ImplBlock {}
1255 pub fn item_list(&self) -> Option<ItemList> {
1256 AstChildren::new(&self.syntax).next()
1259 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1262 TypeAliasDef(TypeAliasDef),
1265 impl From<FnDef> for ImplItem {
1266 fn from(node: FnDef) -> ImplItem {
1267 ImplItem::FnDef(node)
1270 impl From<TypeAliasDef> for ImplItem {
1271 fn from(node: TypeAliasDef) -> ImplItem {
1272 ImplItem::TypeAliasDef(node)
1275 impl From<ConstDef> for ImplItem {
1276 fn from(node: ConstDef) -> ImplItem {
1277 ImplItem::ConstDef(node)
1280 impl AstNode for ImplItem {
1281 fn can_cast(kind: SyntaxKind) -> bool {
1283 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1287 fn cast(syntax: SyntaxNode) -> Option<Self> {
1288 let res = match syntax.kind() {
1289 FN_DEF => ImplItem::FnDef(FnDef { syntax }),
1290 TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }),
1291 CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }),
1296 fn syntax(&self) -> &SyntaxNode {
1298 ImplItem::FnDef(it) => &it.syntax,
1299 ImplItem::TypeAliasDef(it) => &it.syntax,
1300 ImplItem::ConstDef(it) => &it.syntax,
1305 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1306 pub struct ImplTraitType {
1307 pub(crate) syntax: SyntaxNode,
1309 impl AstNode for ImplTraitType {
1310 fn can_cast(kind: SyntaxKind) -> bool {
1312 IMPL_TRAIT_TYPE => true,
1316 fn cast(syntax: SyntaxNode) -> Option<Self> {
1317 if Self::can_cast(syntax.kind()) {
1318 Some(Self { syntax })
1323 fn syntax(&self) -> &SyntaxNode {
1327 impl ast::TypeBoundsOwner for ImplTraitType {}
1328 impl ImplTraitType {}
1329 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1330 pub struct IndexExpr {
1331 pub(crate) syntax: SyntaxNode,
1333 impl AstNode for IndexExpr {
1334 fn can_cast(kind: SyntaxKind) -> bool {
1340 fn cast(syntax: SyntaxNode) -> Option<Self> {
1341 if Self::can_cast(syntax.kind()) {
1342 Some(Self { syntax })
1347 fn syntax(&self) -> &SyntaxNode {
1352 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1353 pub struct ItemList {
1354 pub(crate) syntax: SyntaxNode,
1356 impl AstNode for ItemList {
1357 fn can_cast(kind: SyntaxKind) -> bool {
1363 fn cast(syntax: SyntaxNode) -> Option<Self> {
1364 if Self::can_cast(syntax.kind()) {
1365 Some(Self { syntax })
1370 fn syntax(&self) -> &SyntaxNode {
1374 impl ast::FnDefOwner for ItemList {}
1375 impl ast::ModuleItemOwner for ItemList {}
1377 pub fn impl_items(&self) -> AstChildren<ImplItem> {
1378 AstChildren::new(&self.syntax)
1381 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1383 pub(crate) syntax: SyntaxNode,
1385 impl AstNode for Label {
1386 fn can_cast(kind: SyntaxKind) -> bool {
1392 fn cast(syntax: SyntaxNode) -> Option<Self> {
1393 if Self::can_cast(syntax.kind()) {
1394 Some(Self { syntax })
1399 fn syntax(&self) -> &SyntaxNode {
1404 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1405 pub struct LambdaExpr {
1406 pub(crate) syntax: SyntaxNode,
1408 impl AstNode for LambdaExpr {
1409 fn can_cast(kind: SyntaxKind) -> bool {
1411 LAMBDA_EXPR => true,
1415 fn cast(syntax: SyntaxNode) -> Option<Self> {
1416 if Self::can_cast(syntax.kind()) {
1417 Some(Self { syntax })
1422 fn syntax(&self) -> &SyntaxNode {
1427 pub fn param_list(&self) -> Option<ParamList> {
1428 AstChildren::new(&self.syntax).next()
1430 pub fn body(&self) -> Option<Expr> {
1431 AstChildren::new(&self.syntax).next()
1434 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1435 pub struct LetStmt {
1436 pub(crate) syntax: SyntaxNode,
1438 impl AstNode for LetStmt {
1439 fn can_cast(kind: SyntaxKind) -> bool {
1445 fn cast(syntax: SyntaxNode) -> Option<Self> {
1446 if Self::can_cast(syntax.kind()) {
1447 Some(Self { syntax })
1452 fn syntax(&self) -> &SyntaxNode {
1456 impl ast::TypeAscriptionOwner for LetStmt {}
1458 pub fn pat(&self) -> Option<Pat> {
1459 AstChildren::new(&self.syntax).next()
1461 pub fn initializer(&self) -> Option<Expr> {
1462 AstChildren::new(&self.syntax).next()
1465 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1466 pub struct LifetimeArg {
1467 pub(crate) syntax: SyntaxNode,
1469 impl AstNode for LifetimeArg {
1470 fn can_cast(kind: SyntaxKind) -> bool {
1472 LIFETIME_ARG => true,
1476 fn cast(syntax: SyntaxNode) -> Option<Self> {
1477 if Self::can_cast(syntax.kind()) {
1478 Some(Self { syntax })
1483 fn syntax(&self) -> &SyntaxNode {
1488 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1489 pub struct LifetimeParam {
1490 pub(crate) syntax: SyntaxNode,
1492 impl AstNode for LifetimeParam {
1493 fn can_cast(kind: SyntaxKind) -> bool {
1495 LIFETIME_PARAM => true,
1499 fn cast(syntax: SyntaxNode) -> Option<Self> {
1500 if Self::can_cast(syntax.kind()) {
1501 Some(Self { syntax })
1506 fn syntax(&self) -> &SyntaxNode {
1510 impl ast::AttrsOwner for LifetimeParam {}
1511 impl LifetimeParam {}
1512 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1513 pub struct Literal {
1514 pub(crate) syntax: SyntaxNode,
1516 impl AstNode for Literal {
1517 fn can_cast(kind: SyntaxKind) -> bool {
1523 fn cast(syntax: SyntaxNode) -> Option<Self> {
1524 if Self::can_cast(syntax.kind()) {
1525 Some(Self { syntax })
1530 fn syntax(&self) -> &SyntaxNode {
1535 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1536 pub struct LiteralPat {
1537 pub(crate) syntax: SyntaxNode,
1539 impl AstNode for LiteralPat {
1540 fn can_cast(kind: SyntaxKind) -> bool {
1542 LITERAL_PAT => true,
1546 fn cast(syntax: SyntaxNode) -> Option<Self> {
1547 if Self::can_cast(syntax.kind()) {
1548 Some(Self { syntax })
1553 fn syntax(&self) -> &SyntaxNode {
1558 pub fn literal(&self) -> Option<Literal> {
1559 AstChildren::new(&self.syntax).next()
1562 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1563 pub struct LoopExpr {
1564 pub(crate) syntax: SyntaxNode,
1566 impl AstNode for LoopExpr {
1567 fn can_cast(kind: SyntaxKind) -> bool {
1573 fn cast(syntax: SyntaxNode) -> Option<Self> {
1574 if Self::can_cast(syntax.kind()) {
1575 Some(Self { syntax })
1580 fn syntax(&self) -> &SyntaxNode {
1584 impl ast::LoopBodyOwner for LoopExpr {}
1586 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1587 pub struct MacroCall {
1588 pub(crate) syntax: SyntaxNode,
1590 impl AstNode for MacroCall {
1591 fn can_cast(kind: SyntaxKind) -> bool {
1597 fn cast(syntax: SyntaxNode) -> Option<Self> {
1598 if Self::can_cast(syntax.kind()) {
1599 Some(Self { syntax })
1604 fn syntax(&self) -> &SyntaxNode {
1608 impl ast::NameOwner for MacroCall {}
1609 impl ast::AttrsOwner for MacroCall {}
1610 impl ast::DocCommentsOwner for MacroCall {}
1612 pub fn token_tree(&self) -> Option<TokenTree> {
1613 AstChildren::new(&self.syntax).next()
1615 pub fn path(&self) -> Option<Path> {
1616 AstChildren::new(&self.syntax).next()
1619 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1620 pub struct MacroItems {
1621 pub(crate) syntax: SyntaxNode,
1623 impl AstNode for MacroItems {
1624 fn can_cast(kind: SyntaxKind) -> bool {
1626 MACRO_ITEMS => true,
1630 fn cast(syntax: SyntaxNode) -> Option<Self> {
1631 if Self::can_cast(syntax.kind()) {
1632 Some(Self { syntax })
1637 fn syntax(&self) -> &SyntaxNode {
1641 impl ast::ModuleItemOwner for MacroItems {}
1642 impl ast::FnDefOwner for MacroItems {}
1644 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1645 pub struct MacroStmts {
1646 pub(crate) syntax: SyntaxNode,
1648 impl AstNode for MacroStmts {
1649 fn can_cast(kind: SyntaxKind) -> bool {
1651 MACRO_STMTS => true,
1655 fn cast(syntax: SyntaxNode) -> Option<Self> {
1656 if Self::can_cast(syntax.kind()) {
1657 Some(Self { syntax })
1662 fn syntax(&self) -> &SyntaxNode {
1667 pub fn statements(&self) -> AstChildren<Stmt> {
1668 AstChildren::new(&self.syntax)
1670 pub fn expr(&self) -> Option<Expr> {
1671 AstChildren::new(&self.syntax).next()
1674 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1675 pub struct MatchArm {
1676 pub(crate) syntax: SyntaxNode,
1678 impl AstNode for MatchArm {
1679 fn can_cast(kind: SyntaxKind) -> bool {
1685 fn cast(syntax: SyntaxNode) -> Option<Self> {
1686 if Self::can_cast(syntax.kind()) {
1687 Some(Self { syntax })
1692 fn syntax(&self) -> &SyntaxNode {
1696 impl ast::AttrsOwner for MatchArm {}
1698 pub fn pats(&self) -> AstChildren<Pat> {
1699 AstChildren::new(&self.syntax)
1701 pub fn guard(&self) -> Option<MatchGuard> {
1702 AstChildren::new(&self.syntax).next()
1704 pub fn expr(&self) -> Option<Expr> {
1705 AstChildren::new(&self.syntax).next()
1708 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1709 pub struct MatchArmList {
1710 pub(crate) syntax: SyntaxNode,
1712 impl AstNode for MatchArmList {
1713 fn can_cast(kind: SyntaxKind) -> bool {
1715 MATCH_ARM_LIST => true,
1719 fn cast(syntax: SyntaxNode) -> Option<Self> {
1720 if Self::can_cast(syntax.kind()) {
1721 Some(Self { syntax })
1726 fn syntax(&self) -> &SyntaxNode {
1730 impl ast::AttrsOwner for MatchArmList {}
1732 pub fn arms(&self) -> AstChildren<MatchArm> {
1733 AstChildren::new(&self.syntax)
1736 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1737 pub struct MatchExpr {
1738 pub(crate) syntax: SyntaxNode,
1740 impl AstNode for MatchExpr {
1741 fn can_cast(kind: SyntaxKind) -> bool {
1747 fn cast(syntax: SyntaxNode) -> Option<Self> {
1748 if Self::can_cast(syntax.kind()) {
1749 Some(Self { syntax })
1754 fn syntax(&self) -> &SyntaxNode {
1759 pub fn expr(&self) -> Option<Expr> {
1760 AstChildren::new(&self.syntax).next()
1762 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1763 AstChildren::new(&self.syntax).next()
1766 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1767 pub struct MatchGuard {
1768 pub(crate) syntax: SyntaxNode,
1770 impl AstNode for MatchGuard {
1771 fn can_cast(kind: SyntaxKind) -> bool {
1773 MATCH_GUARD => true,
1777 fn cast(syntax: SyntaxNode) -> Option<Self> {
1778 if Self::can_cast(syntax.kind()) {
1779 Some(Self { syntax })
1784 fn syntax(&self) -> &SyntaxNode {
1789 pub fn expr(&self) -> Option<Expr> {
1790 AstChildren::new(&self.syntax).next()
1793 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1794 pub struct MethodCallExpr {
1795 pub(crate) syntax: SyntaxNode,
1797 impl AstNode for MethodCallExpr {
1798 fn can_cast(kind: SyntaxKind) -> bool {
1800 METHOD_CALL_EXPR => true,
1804 fn cast(syntax: SyntaxNode) -> Option<Self> {
1805 if Self::can_cast(syntax.kind()) {
1806 Some(Self { syntax })
1811 fn syntax(&self) -> &SyntaxNode {
1815 impl ast::ArgListOwner for MethodCallExpr {}
1816 impl MethodCallExpr {
1817 pub fn expr(&self) -> Option<Expr> {
1818 AstChildren::new(&self.syntax).next()
1820 pub fn name_ref(&self) -> Option<NameRef> {
1821 AstChildren::new(&self.syntax).next()
1823 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1824 AstChildren::new(&self.syntax).next()
1827 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1829 pub(crate) syntax: SyntaxNode,
1831 impl AstNode for Module {
1832 fn can_cast(kind: SyntaxKind) -> bool {
1838 fn cast(syntax: SyntaxNode) -> Option<Self> {
1839 if Self::can_cast(syntax.kind()) {
1840 Some(Self { syntax })
1845 fn syntax(&self) -> &SyntaxNode {
1849 impl ast::VisibilityOwner for Module {}
1850 impl ast::NameOwner for Module {}
1851 impl ast::AttrsOwner for Module {}
1852 impl ast::DocCommentsOwner for Module {}
1854 pub fn item_list(&self) -> Option<ItemList> {
1855 AstChildren::new(&self.syntax).next()
1858 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1859 pub enum ModuleItem {
1860 StructDef(StructDef),
1864 TypeAliasDef(TypeAliasDef),
1865 ImplBlock(ImplBlock),
1867 ExternCrateItem(ExternCrateItem),
1869 StaticDef(StaticDef),
1872 impl From<StructDef> for ModuleItem {
1873 fn from(node: StructDef) -> ModuleItem {
1874 ModuleItem::StructDef(node)
1877 impl From<EnumDef> for ModuleItem {
1878 fn from(node: EnumDef) -> ModuleItem {
1879 ModuleItem::EnumDef(node)
1882 impl From<FnDef> for ModuleItem {
1883 fn from(node: FnDef) -> ModuleItem {
1884 ModuleItem::FnDef(node)
1887 impl From<TraitDef> for ModuleItem {
1888 fn from(node: TraitDef) -> ModuleItem {
1889 ModuleItem::TraitDef(node)
1892 impl From<TypeAliasDef> for ModuleItem {
1893 fn from(node: TypeAliasDef) -> ModuleItem {
1894 ModuleItem::TypeAliasDef(node)
1897 impl From<ImplBlock> for ModuleItem {
1898 fn from(node: ImplBlock) -> ModuleItem {
1899 ModuleItem::ImplBlock(node)
1902 impl From<UseItem> for ModuleItem {
1903 fn from(node: UseItem) -> ModuleItem {
1904 ModuleItem::UseItem(node)
1907 impl From<ExternCrateItem> for ModuleItem {
1908 fn from(node: ExternCrateItem) -> ModuleItem {
1909 ModuleItem::ExternCrateItem(node)
1912 impl From<ConstDef> for ModuleItem {
1913 fn from(node: ConstDef) -> ModuleItem {
1914 ModuleItem::ConstDef(node)
1917 impl From<StaticDef> for ModuleItem {
1918 fn from(node: StaticDef) -> ModuleItem {
1919 ModuleItem::StaticDef(node)
1922 impl From<Module> for ModuleItem {
1923 fn from(node: Module) -> ModuleItem {
1924 ModuleItem::Module(node)
1927 impl AstNode for ModuleItem {
1928 fn can_cast(kind: SyntaxKind) -> bool {
1930 STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM
1931 | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1935 fn cast(syntax: SyntaxNode) -> Option<Self> {
1936 let res = match syntax.kind() {
1937 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
1938 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
1939 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
1940 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
1941 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
1942 IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
1943 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
1944 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
1945 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
1946 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
1947 MODULE => ModuleItem::Module(Module { syntax }),
1952 fn syntax(&self) -> &SyntaxNode {
1954 ModuleItem::StructDef(it) => &it.syntax,
1955 ModuleItem::EnumDef(it) => &it.syntax,
1956 ModuleItem::FnDef(it) => &it.syntax,
1957 ModuleItem::TraitDef(it) => &it.syntax,
1958 ModuleItem::TypeAliasDef(it) => &it.syntax,
1959 ModuleItem::ImplBlock(it) => &it.syntax,
1960 ModuleItem::UseItem(it) => &it.syntax,
1961 ModuleItem::ExternCrateItem(it) => &it.syntax,
1962 ModuleItem::ConstDef(it) => &it.syntax,
1963 ModuleItem::StaticDef(it) => &it.syntax,
1964 ModuleItem::Module(it) => &it.syntax,
1969 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1971 pub(crate) syntax: SyntaxNode,
1973 impl AstNode for Name {
1974 fn can_cast(kind: SyntaxKind) -> bool {
1980 fn cast(syntax: SyntaxNode) -> Option<Self> {
1981 if Self::can_cast(syntax.kind()) {
1982 Some(Self { syntax })
1987 fn syntax(&self) -> &SyntaxNode {
1992 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1993 pub struct NameRef {
1994 pub(crate) syntax: SyntaxNode,
1996 impl AstNode for NameRef {
1997 fn can_cast(kind: SyntaxKind) -> bool {
2003 fn cast(syntax: SyntaxNode) -> Option<Self> {
2004 if Self::can_cast(syntax.kind()) {
2005 Some(Self { syntax })
2010 fn syntax(&self) -> &SyntaxNode {
2015 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2016 pub struct NeverType {
2017 pub(crate) syntax: SyntaxNode,
2019 impl AstNode for NeverType {
2020 fn can_cast(kind: SyntaxKind) -> bool {
2026 fn cast(syntax: SyntaxNode) -> Option<Self> {
2027 if Self::can_cast(syntax.kind()) {
2028 Some(Self { syntax })
2033 fn syntax(&self) -> &SyntaxNode {
2038 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2039 pub enum NominalDef {
2040 StructDef(StructDef),
2043 impl From<StructDef> for NominalDef {
2044 fn from(node: StructDef) -> NominalDef {
2045 NominalDef::StructDef(node)
2048 impl From<EnumDef> for NominalDef {
2049 fn from(node: EnumDef) -> NominalDef {
2050 NominalDef::EnumDef(node)
2053 impl AstNode for NominalDef {
2054 fn can_cast(kind: SyntaxKind) -> bool {
2056 STRUCT_DEF | ENUM_DEF => true,
2060 fn cast(syntax: SyntaxNode) -> Option<Self> {
2061 let res = match syntax.kind() {
2062 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
2063 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
2068 fn syntax(&self) -> &SyntaxNode {
2070 NominalDef::StructDef(it) => &it.syntax,
2071 NominalDef::EnumDef(it) => &it.syntax,
2075 impl ast::NameOwner for NominalDef {}
2076 impl ast::TypeParamsOwner for NominalDef {}
2077 impl ast::AttrsOwner for NominalDef {}
2079 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2081 pub(crate) syntax: SyntaxNode,
2083 impl AstNode for Param {
2084 fn can_cast(kind: SyntaxKind) -> bool {
2090 fn cast(syntax: SyntaxNode) -> Option<Self> {
2091 if Self::can_cast(syntax.kind()) {
2092 Some(Self { syntax })
2097 fn syntax(&self) -> &SyntaxNode {
2101 impl ast::TypeAscriptionOwner for Param {}
2102 impl ast::AttrsOwner for Param {}
2104 pub fn pat(&self) -> Option<Pat> {
2105 AstChildren::new(&self.syntax).next()
2108 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2109 pub struct ParamList {
2110 pub(crate) syntax: SyntaxNode,
2112 impl AstNode for ParamList {
2113 fn can_cast(kind: SyntaxKind) -> bool {
2119 fn cast(syntax: SyntaxNode) -> Option<Self> {
2120 if Self::can_cast(syntax.kind()) {
2121 Some(Self { syntax })
2126 fn syntax(&self) -> &SyntaxNode {
2131 pub fn params(&self) -> AstChildren<Param> {
2132 AstChildren::new(&self.syntax)
2134 pub fn self_param(&self) -> Option<SelfParam> {
2135 AstChildren::new(&self.syntax).next()
2138 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2139 pub struct ParenExpr {
2140 pub(crate) syntax: SyntaxNode,
2142 impl AstNode for ParenExpr {
2143 fn can_cast(kind: SyntaxKind) -> bool {
2149 fn cast(syntax: SyntaxNode) -> Option<Self> {
2150 if Self::can_cast(syntax.kind()) {
2151 Some(Self { syntax })
2156 fn syntax(&self) -> &SyntaxNode {
2161 pub fn expr(&self) -> Option<Expr> {
2162 AstChildren::new(&self.syntax).next()
2165 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2166 pub struct ParenType {
2167 pub(crate) syntax: SyntaxNode,
2169 impl AstNode for ParenType {
2170 fn can_cast(kind: SyntaxKind) -> bool {
2176 fn cast(syntax: SyntaxNode) -> Option<Self> {
2177 if Self::can_cast(syntax.kind()) {
2178 Some(Self { syntax })
2183 fn syntax(&self) -> &SyntaxNode {
2188 pub fn type_ref(&self) -> Option<TypeRef> {
2189 AstChildren::new(&self.syntax).next()
2192 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2197 PlaceholderPat(PlaceholderPat),
2198 DotDotPat(DotDotPat),
2200 RecordPat(RecordPat),
2201 TupleStructPat(TupleStructPat),
2205 LiteralPat(LiteralPat),
2207 impl From<RefPat> for Pat {
2208 fn from(node: RefPat) -> Pat {
2212 impl From<BoxPat> for Pat {
2213 fn from(node: BoxPat) -> Pat {
2217 impl From<BindPat> for Pat {
2218 fn from(node: BindPat) -> Pat {
2222 impl From<PlaceholderPat> for Pat {
2223 fn from(node: PlaceholderPat) -> Pat {
2224 Pat::PlaceholderPat(node)
2227 impl From<DotDotPat> for Pat {
2228 fn from(node: DotDotPat) -> Pat {
2229 Pat::DotDotPat(node)
2232 impl From<PathPat> for Pat {
2233 fn from(node: PathPat) -> Pat {
2237 impl From<RecordPat> for Pat {
2238 fn from(node: RecordPat) -> Pat {
2239 Pat::RecordPat(node)
2242 impl From<TupleStructPat> for Pat {
2243 fn from(node: TupleStructPat) -> Pat {
2244 Pat::TupleStructPat(node)
2247 impl From<TuplePat> for Pat {
2248 fn from(node: TuplePat) -> Pat {
2252 impl From<SlicePat> for Pat {
2253 fn from(node: SlicePat) -> Pat {
2257 impl From<RangePat> for Pat {
2258 fn from(node: RangePat) -> Pat {
2262 impl From<LiteralPat> for Pat {
2263 fn from(node: LiteralPat) -> Pat {
2264 Pat::LiteralPat(node)
2267 impl AstNode for Pat {
2268 fn can_cast(kind: SyntaxKind) -> bool {
2270 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT
2271 | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => {
2277 fn cast(syntax: SyntaxNode) -> Option<Self> {
2278 let res = match syntax.kind() {
2279 REF_PAT => Pat::RefPat(RefPat { syntax }),
2280 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2281 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2282 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2283 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
2284 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2285 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2286 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2287 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2288 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2289 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2290 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2295 fn syntax(&self) -> &SyntaxNode {
2297 Pat::RefPat(it) => &it.syntax,
2298 Pat::BoxPat(it) => &it.syntax,
2299 Pat::BindPat(it) => &it.syntax,
2300 Pat::PlaceholderPat(it) => &it.syntax,
2301 Pat::DotDotPat(it) => &it.syntax,
2302 Pat::PathPat(it) => &it.syntax,
2303 Pat::RecordPat(it) => &it.syntax,
2304 Pat::TupleStructPat(it) => &it.syntax,
2305 Pat::TuplePat(it) => &it.syntax,
2306 Pat::SlicePat(it) => &it.syntax,
2307 Pat::RangePat(it) => &it.syntax,
2308 Pat::LiteralPat(it) => &it.syntax,
2313 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2315 pub(crate) syntax: SyntaxNode,
2317 impl AstNode for Path {
2318 fn can_cast(kind: SyntaxKind) -> bool {
2324 fn cast(syntax: SyntaxNode) -> Option<Self> {
2325 if Self::can_cast(syntax.kind()) {
2326 Some(Self { syntax })
2331 fn syntax(&self) -> &SyntaxNode {
2336 pub fn segment(&self) -> Option<PathSegment> {
2337 AstChildren::new(&self.syntax).next()
2339 pub fn qualifier(&self) -> Option<Path> {
2340 AstChildren::new(&self.syntax).next()
2343 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2344 pub struct PathExpr {
2345 pub(crate) syntax: SyntaxNode,
2347 impl AstNode for PathExpr {
2348 fn can_cast(kind: SyntaxKind) -> bool {
2354 fn cast(syntax: SyntaxNode) -> Option<Self> {
2355 if Self::can_cast(syntax.kind()) {
2356 Some(Self { syntax })
2361 fn syntax(&self) -> &SyntaxNode {
2366 pub fn path(&self) -> Option<Path> {
2367 AstChildren::new(&self.syntax).next()
2370 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2371 pub struct PathPat {
2372 pub(crate) syntax: SyntaxNode,
2374 impl AstNode for PathPat {
2375 fn can_cast(kind: SyntaxKind) -> bool {
2381 fn cast(syntax: SyntaxNode) -> Option<Self> {
2382 if Self::can_cast(syntax.kind()) {
2383 Some(Self { syntax })
2388 fn syntax(&self) -> &SyntaxNode {
2393 pub fn path(&self) -> Option<Path> {
2394 AstChildren::new(&self.syntax).next()
2397 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2398 pub struct PathSegment {
2399 pub(crate) syntax: SyntaxNode,
2401 impl AstNode for PathSegment {
2402 fn can_cast(kind: SyntaxKind) -> bool {
2404 PATH_SEGMENT => true,
2408 fn cast(syntax: SyntaxNode) -> Option<Self> {
2409 if Self::can_cast(syntax.kind()) {
2410 Some(Self { syntax })
2415 fn syntax(&self) -> &SyntaxNode {
2420 pub fn name_ref(&self) -> Option<NameRef> {
2421 AstChildren::new(&self.syntax).next()
2423 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2424 AstChildren::new(&self.syntax).next()
2426 pub fn param_list(&self) -> Option<ParamList> {
2427 AstChildren::new(&self.syntax).next()
2429 pub fn ret_type(&self) -> Option<RetType> {
2430 AstChildren::new(&self.syntax).next()
2432 pub fn path_type(&self) -> Option<PathType> {
2433 AstChildren::new(&self.syntax).next()
2436 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2437 pub struct PathType {
2438 pub(crate) syntax: SyntaxNode,
2440 impl AstNode for PathType {
2441 fn can_cast(kind: SyntaxKind) -> bool {
2447 fn cast(syntax: SyntaxNode) -> Option<Self> {
2448 if Self::can_cast(syntax.kind()) {
2449 Some(Self { syntax })
2454 fn syntax(&self) -> &SyntaxNode {
2459 pub fn path(&self) -> Option<Path> {
2460 AstChildren::new(&self.syntax).next()
2463 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2464 pub struct PlaceholderPat {
2465 pub(crate) syntax: SyntaxNode,
2467 impl AstNode for PlaceholderPat {
2468 fn can_cast(kind: SyntaxKind) -> bool {
2470 PLACEHOLDER_PAT => true,
2474 fn cast(syntax: SyntaxNode) -> Option<Self> {
2475 if Self::can_cast(syntax.kind()) {
2476 Some(Self { syntax })
2481 fn syntax(&self) -> &SyntaxNode {
2485 impl PlaceholderPat {}
2486 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2487 pub struct PlaceholderType {
2488 pub(crate) syntax: SyntaxNode,
2490 impl AstNode for PlaceholderType {
2491 fn can_cast(kind: SyntaxKind) -> bool {
2493 PLACEHOLDER_TYPE => true,
2497 fn cast(syntax: SyntaxNode) -> Option<Self> {
2498 if Self::can_cast(syntax.kind()) {
2499 Some(Self { syntax })
2504 fn syntax(&self) -> &SyntaxNode {
2508 impl PlaceholderType {}
2509 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2510 pub struct PointerType {
2511 pub(crate) syntax: SyntaxNode,
2513 impl AstNode for PointerType {
2514 fn can_cast(kind: SyntaxKind) -> bool {
2516 POINTER_TYPE => true,
2520 fn cast(syntax: SyntaxNode) -> Option<Self> {
2521 if Self::can_cast(syntax.kind()) {
2522 Some(Self { syntax })
2527 fn syntax(&self) -> &SyntaxNode {
2532 pub fn type_ref(&self) -> Option<TypeRef> {
2533 AstChildren::new(&self.syntax).next()
2536 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2537 pub struct PrefixExpr {
2538 pub(crate) syntax: SyntaxNode,
2540 impl AstNode for PrefixExpr {
2541 fn can_cast(kind: SyntaxKind) -> bool {
2543 PREFIX_EXPR => true,
2547 fn cast(syntax: SyntaxNode) -> Option<Self> {
2548 if Self::can_cast(syntax.kind()) {
2549 Some(Self { syntax })
2554 fn syntax(&self) -> &SyntaxNode {
2559 pub fn expr(&self) -> Option<Expr> {
2560 AstChildren::new(&self.syntax).next()
2563 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2564 pub struct RangeExpr {
2565 pub(crate) syntax: SyntaxNode,
2567 impl AstNode for RangeExpr {
2568 fn can_cast(kind: SyntaxKind) -> bool {
2574 fn cast(syntax: SyntaxNode) -> Option<Self> {
2575 if Self::can_cast(syntax.kind()) {
2576 Some(Self { syntax })
2581 fn syntax(&self) -> &SyntaxNode {
2586 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2587 pub struct RangePat {
2588 pub(crate) syntax: SyntaxNode,
2590 impl AstNode for RangePat {
2591 fn can_cast(kind: SyntaxKind) -> bool {
2597 fn cast(syntax: SyntaxNode) -> Option<Self> {
2598 if Self::can_cast(syntax.kind()) {
2599 Some(Self { syntax })
2604 fn syntax(&self) -> &SyntaxNode {
2609 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2610 pub struct RecordField {
2611 pub(crate) syntax: SyntaxNode,
2613 impl AstNode for RecordField {
2614 fn can_cast(kind: SyntaxKind) -> bool {
2616 RECORD_FIELD => true,
2620 fn cast(syntax: SyntaxNode) -> Option<Self> {
2621 if Self::can_cast(syntax.kind()) {
2622 Some(Self { syntax })
2627 fn syntax(&self) -> &SyntaxNode {
2632 pub fn name_ref(&self) -> Option<NameRef> {
2633 AstChildren::new(&self.syntax).next()
2635 pub fn expr(&self) -> Option<Expr> {
2636 AstChildren::new(&self.syntax).next()
2639 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2640 pub struct RecordFieldDef {
2641 pub(crate) syntax: SyntaxNode,
2643 impl AstNode for RecordFieldDef {
2644 fn can_cast(kind: SyntaxKind) -> bool {
2646 RECORD_FIELD_DEF => true,
2650 fn cast(syntax: SyntaxNode) -> Option<Self> {
2651 if Self::can_cast(syntax.kind()) {
2652 Some(Self { syntax })
2657 fn syntax(&self) -> &SyntaxNode {
2661 impl ast::VisibilityOwner for RecordFieldDef {}
2662 impl ast::NameOwner for RecordFieldDef {}
2663 impl ast::AttrsOwner for RecordFieldDef {}
2664 impl ast::DocCommentsOwner for RecordFieldDef {}
2665 impl ast::TypeAscriptionOwner for RecordFieldDef {}
2666 impl RecordFieldDef {}
2667 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2668 pub struct RecordFieldDefList {
2669 pub(crate) syntax: SyntaxNode,
2671 impl AstNode for RecordFieldDefList {
2672 fn can_cast(kind: SyntaxKind) -> bool {
2674 RECORD_FIELD_DEF_LIST => true,
2678 fn cast(syntax: SyntaxNode) -> Option<Self> {
2679 if Self::can_cast(syntax.kind()) {
2680 Some(Self { syntax })
2685 fn syntax(&self) -> &SyntaxNode {
2689 impl RecordFieldDefList {
2690 pub fn fields(&self) -> AstChildren<RecordFieldDef> {
2691 AstChildren::new(&self.syntax)
2694 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2695 pub struct RecordFieldList {
2696 pub(crate) syntax: SyntaxNode,
2698 impl AstNode for RecordFieldList {
2699 fn can_cast(kind: SyntaxKind) -> bool {
2701 RECORD_FIELD_LIST => true,
2705 fn cast(syntax: SyntaxNode) -> Option<Self> {
2706 if Self::can_cast(syntax.kind()) {
2707 Some(Self { syntax })
2712 fn syntax(&self) -> &SyntaxNode {
2716 impl RecordFieldList {
2717 pub fn fields(&self) -> AstChildren<RecordField> {
2718 AstChildren::new(&self.syntax)
2720 pub fn spread(&self) -> Option<Expr> {
2721 AstChildren::new(&self.syntax).next()
2724 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2725 pub struct RecordFieldPat {
2726 pub(crate) syntax: SyntaxNode,
2728 impl AstNode for RecordFieldPat {
2729 fn can_cast(kind: SyntaxKind) -> bool {
2731 RECORD_FIELD_PAT => true,
2735 fn cast(syntax: SyntaxNode) -> Option<Self> {
2736 if Self::can_cast(syntax.kind()) {
2737 Some(Self { syntax })
2742 fn syntax(&self) -> &SyntaxNode {
2746 impl ast::NameOwner for RecordFieldPat {}
2747 impl RecordFieldPat {
2748 pub fn pat(&self) -> Option<Pat> {
2749 AstChildren::new(&self.syntax).next()
2752 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2753 pub struct RecordFieldPatList {
2754 pub(crate) syntax: SyntaxNode,
2756 impl AstNode for RecordFieldPatList {
2757 fn can_cast(kind: SyntaxKind) -> bool {
2759 RECORD_FIELD_PAT_LIST => true,
2763 fn cast(syntax: SyntaxNode) -> Option<Self> {
2764 if Self::can_cast(syntax.kind()) {
2765 Some(Self { syntax })
2770 fn syntax(&self) -> &SyntaxNode {
2774 impl RecordFieldPatList {
2775 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
2776 AstChildren::new(&self.syntax)
2778 pub fn bind_pats(&self) -> AstChildren<BindPat> {
2779 AstChildren::new(&self.syntax)
2782 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2783 pub struct RecordLit {
2784 pub(crate) syntax: SyntaxNode,
2786 impl AstNode for RecordLit {
2787 fn can_cast(kind: SyntaxKind) -> bool {
2793 fn cast(syntax: SyntaxNode) -> Option<Self> {
2794 if Self::can_cast(syntax.kind()) {
2795 Some(Self { syntax })
2800 fn syntax(&self) -> &SyntaxNode {
2805 pub fn path(&self) -> Option<Path> {
2806 AstChildren::new(&self.syntax).next()
2808 pub fn record_field_list(&self) -> Option<RecordFieldList> {
2809 AstChildren::new(&self.syntax).next()
2812 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2813 pub struct RecordPat {
2814 pub(crate) syntax: SyntaxNode,
2816 impl AstNode for RecordPat {
2817 fn can_cast(kind: SyntaxKind) -> bool {
2823 fn cast(syntax: SyntaxNode) -> Option<Self> {
2824 if Self::can_cast(syntax.kind()) {
2825 Some(Self { syntax })
2830 fn syntax(&self) -> &SyntaxNode {
2835 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
2836 AstChildren::new(&self.syntax).next()
2838 pub fn path(&self) -> Option<Path> {
2839 AstChildren::new(&self.syntax).next()
2842 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2843 pub struct RefExpr {
2844 pub(crate) syntax: SyntaxNode,
2846 impl AstNode for RefExpr {
2847 fn can_cast(kind: SyntaxKind) -> bool {
2853 fn cast(syntax: SyntaxNode) -> Option<Self> {
2854 if Self::can_cast(syntax.kind()) {
2855 Some(Self { syntax })
2860 fn syntax(&self) -> &SyntaxNode {
2865 pub fn expr(&self) -> Option<Expr> {
2866 AstChildren::new(&self.syntax).next()
2869 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2871 pub(crate) syntax: SyntaxNode,
2873 impl AstNode for RefPat {
2874 fn can_cast(kind: SyntaxKind) -> bool {
2880 fn cast(syntax: SyntaxNode) -> Option<Self> {
2881 if Self::can_cast(syntax.kind()) {
2882 Some(Self { syntax })
2887 fn syntax(&self) -> &SyntaxNode {
2892 pub fn pat(&self) -> Option<Pat> {
2893 AstChildren::new(&self.syntax).next()
2896 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2897 pub struct ReferenceType {
2898 pub(crate) syntax: SyntaxNode,
2900 impl AstNode for ReferenceType {
2901 fn can_cast(kind: SyntaxKind) -> bool {
2903 REFERENCE_TYPE => true,
2907 fn cast(syntax: SyntaxNode) -> Option<Self> {
2908 if Self::can_cast(syntax.kind()) {
2909 Some(Self { syntax })
2914 fn syntax(&self) -> &SyntaxNode {
2918 impl ReferenceType {
2919 pub fn type_ref(&self) -> Option<TypeRef> {
2920 AstChildren::new(&self.syntax).next()
2923 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2924 pub struct RetType {
2925 pub(crate) syntax: SyntaxNode,
2927 impl AstNode for RetType {
2928 fn can_cast(kind: SyntaxKind) -> bool {
2934 fn cast(syntax: SyntaxNode) -> Option<Self> {
2935 if Self::can_cast(syntax.kind()) {
2936 Some(Self { syntax })
2941 fn syntax(&self) -> &SyntaxNode {
2946 pub fn type_ref(&self) -> Option<TypeRef> {
2947 AstChildren::new(&self.syntax).next()
2950 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2951 pub struct ReturnExpr {
2952 pub(crate) syntax: SyntaxNode,
2954 impl AstNode for ReturnExpr {
2955 fn can_cast(kind: SyntaxKind) -> bool {
2957 RETURN_EXPR => true,
2961 fn cast(syntax: SyntaxNode) -> Option<Self> {
2962 if Self::can_cast(syntax.kind()) {
2963 Some(Self { syntax })
2968 fn syntax(&self) -> &SyntaxNode {
2973 pub fn expr(&self) -> Option<Expr> {
2974 AstChildren::new(&self.syntax).next()
2977 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2978 pub struct SelfParam {
2979 pub(crate) syntax: SyntaxNode,
2981 impl AstNode for SelfParam {
2982 fn can_cast(kind: SyntaxKind) -> bool {
2988 fn cast(syntax: SyntaxNode) -> Option<Self> {
2989 if Self::can_cast(syntax.kind()) {
2990 Some(Self { syntax })
2995 fn syntax(&self) -> &SyntaxNode {
2999 impl ast::TypeAscriptionOwner for SelfParam {}
3000 impl ast::AttrsOwner for SelfParam {}
3002 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3003 pub struct SlicePat {
3004 pub(crate) syntax: SyntaxNode,
3006 impl AstNode for SlicePat {
3007 fn can_cast(kind: SyntaxKind) -> bool {
3013 fn cast(syntax: SyntaxNode) -> Option<Self> {
3014 if Self::can_cast(syntax.kind()) {
3015 Some(Self { syntax })
3020 fn syntax(&self) -> &SyntaxNode {
3025 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3026 pub struct SliceType {
3027 pub(crate) syntax: SyntaxNode,
3029 impl AstNode for SliceType {
3030 fn can_cast(kind: SyntaxKind) -> bool {
3036 fn cast(syntax: SyntaxNode) -> Option<Self> {
3037 if Self::can_cast(syntax.kind()) {
3038 Some(Self { syntax })
3043 fn syntax(&self) -> &SyntaxNode {
3048 pub fn type_ref(&self) -> Option<TypeRef> {
3049 AstChildren::new(&self.syntax).next()
3052 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3053 pub struct SourceFile {
3054 pub(crate) syntax: SyntaxNode,
3056 impl AstNode for SourceFile {
3057 fn can_cast(kind: SyntaxKind) -> bool {
3059 SOURCE_FILE => true,
3063 fn cast(syntax: SyntaxNode) -> Option<Self> {
3064 if Self::can_cast(syntax.kind()) {
3065 Some(Self { syntax })
3070 fn syntax(&self) -> &SyntaxNode {
3074 impl ast::ModuleItemOwner for SourceFile {}
3075 impl ast::FnDefOwner for SourceFile {}
3077 pub fn modules(&self) -> AstChildren<Module> {
3078 AstChildren::new(&self.syntax)
3081 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3082 pub struct StaticDef {
3083 pub(crate) syntax: SyntaxNode,
3085 impl AstNode for StaticDef {
3086 fn can_cast(kind: SyntaxKind) -> bool {
3092 fn cast(syntax: SyntaxNode) -> Option<Self> {
3093 if Self::can_cast(syntax.kind()) {
3094 Some(Self { syntax })
3099 fn syntax(&self) -> &SyntaxNode {
3103 impl ast::VisibilityOwner for StaticDef {}
3104 impl ast::NameOwner for StaticDef {}
3105 impl ast::TypeParamsOwner for StaticDef {}
3106 impl ast::AttrsOwner for StaticDef {}
3107 impl ast::DocCommentsOwner for StaticDef {}
3108 impl ast::TypeAscriptionOwner for StaticDef {}
3110 pub fn body(&self) -> Option<Expr> {
3111 AstChildren::new(&self.syntax).next()
3114 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3119 impl From<ExprStmt> for Stmt {
3120 fn from(node: ExprStmt) -> Stmt {
3121 Stmt::ExprStmt(node)
3124 impl From<LetStmt> for Stmt {
3125 fn from(node: LetStmt) -> Stmt {
3129 impl AstNode for Stmt {
3130 fn can_cast(kind: SyntaxKind) -> bool {
3132 EXPR_STMT | LET_STMT => true,
3136 fn cast(syntax: SyntaxNode) -> Option<Self> {
3137 let res = match syntax.kind() {
3138 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
3139 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
3144 fn syntax(&self) -> &SyntaxNode {
3146 Stmt::ExprStmt(it) => &it.syntax,
3147 Stmt::LetStmt(it) => &it.syntax,
3152 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3153 pub struct StructDef {
3154 pub(crate) syntax: SyntaxNode,
3156 impl AstNode for StructDef {
3157 fn can_cast(kind: SyntaxKind) -> bool {
3163 fn cast(syntax: SyntaxNode) -> Option<Self> {
3164 if Self::can_cast(syntax.kind()) {
3165 Some(Self { syntax })
3170 fn syntax(&self) -> &SyntaxNode {
3174 impl ast::VisibilityOwner for StructDef {}
3175 impl ast::NameOwner for StructDef {}
3176 impl ast::TypeParamsOwner for StructDef {}
3177 impl ast::AttrsOwner for StructDef {}
3178 impl ast::DocCommentsOwner for StructDef {}
3180 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3181 pub struct TokenTree {
3182 pub(crate) syntax: SyntaxNode,
3184 impl AstNode for TokenTree {
3185 fn can_cast(kind: SyntaxKind) -> bool {
3191 fn cast(syntax: SyntaxNode) -> Option<Self> {
3192 if Self::can_cast(syntax.kind()) {
3193 Some(Self { syntax })
3198 fn syntax(&self) -> &SyntaxNode {
3203 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3204 pub struct TraitDef {
3205 pub(crate) syntax: SyntaxNode,
3207 impl AstNode for TraitDef {
3208 fn can_cast(kind: SyntaxKind) -> bool {
3214 fn cast(syntax: SyntaxNode) -> Option<Self> {
3215 if Self::can_cast(syntax.kind()) {
3216 Some(Self { syntax })
3221 fn syntax(&self) -> &SyntaxNode {
3225 impl ast::VisibilityOwner for TraitDef {}
3226 impl ast::NameOwner for TraitDef {}
3227 impl ast::AttrsOwner for TraitDef {}
3228 impl ast::DocCommentsOwner for TraitDef {}
3229 impl ast::TypeParamsOwner for TraitDef {}
3230 impl ast::TypeBoundsOwner for TraitDef {}
3232 pub fn item_list(&self) -> Option<ItemList> {
3233 AstChildren::new(&self.syntax).next()
3236 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3237 pub struct TryBlockExpr {
3238 pub(crate) syntax: SyntaxNode,
3240 impl AstNode for TryBlockExpr {
3241 fn can_cast(kind: SyntaxKind) -> bool {
3243 TRY_BLOCK_EXPR => true,
3247 fn cast(syntax: SyntaxNode) -> Option<Self> {
3248 if Self::can_cast(syntax.kind()) {
3249 Some(Self { syntax })
3254 fn syntax(&self) -> &SyntaxNode {
3259 pub fn body(&self) -> Option<BlockExpr> {
3260 AstChildren::new(&self.syntax).next()
3263 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3264 pub struct TryExpr {
3265 pub(crate) syntax: SyntaxNode,
3267 impl AstNode for TryExpr {
3268 fn can_cast(kind: SyntaxKind) -> bool {
3274 fn cast(syntax: SyntaxNode) -> Option<Self> {
3275 if Self::can_cast(syntax.kind()) {
3276 Some(Self { syntax })
3281 fn syntax(&self) -> &SyntaxNode {
3286 pub fn expr(&self) -> Option<Expr> {
3287 AstChildren::new(&self.syntax).next()
3290 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3291 pub struct TupleExpr {
3292 pub(crate) syntax: SyntaxNode,
3294 impl AstNode for TupleExpr {
3295 fn can_cast(kind: SyntaxKind) -> bool {
3301 fn cast(syntax: SyntaxNode) -> Option<Self> {
3302 if Self::can_cast(syntax.kind()) {
3303 Some(Self { syntax })
3308 fn syntax(&self) -> &SyntaxNode {
3313 pub fn exprs(&self) -> AstChildren<Expr> {
3314 AstChildren::new(&self.syntax)
3317 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3318 pub struct TupleFieldDef {
3319 pub(crate) syntax: SyntaxNode,
3321 impl AstNode for TupleFieldDef {
3322 fn can_cast(kind: SyntaxKind) -> bool {
3324 TUPLE_FIELD_DEF => true,
3328 fn cast(syntax: SyntaxNode) -> Option<Self> {
3329 if Self::can_cast(syntax.kind()) {
3330 Some(Self { syntax })
3335 fn syntax(&self) -> &SyntaxNode {
3339 impl ast::VisibilityOwner for TupleFieldDef {}
3340 impl ast::AttrsOwner for TupleFieldDef {}
3341 impl TupleFieldDef {
3342 pub fn type_ref(&self) -> Option<TypeRef> {
3343 AstChildren::new(&self.syntax).next()
3346 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3347 pub struct TupleFieldDefList {
3348 pub(crate) syntax: SyntaxNode,
3350 impl AstNode for TupleFieldDefList {
3351 fn can_cast(kind: SyntaxKind) -> bool {
3353 TUPLE_FIELD_DEF_LIST => true,
3357 fn cast(syntax: SyntaxNode) -> Option<Self> {
3358 if Self::can_cast(syntax.kind()) {
3359 Some(Self { syntax })
3364 fn syntax(&self) -> &SyntaxNode {
3368 impl TupleFieldDefList {
3369 pub fn fields(&self) -> AstChildren<TupleFieldDef> {
3370 AstChildren::new(&self.syntax)
3373 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3374 pub struct TuplePat {
3375 pub(crate) syntax: SyntaxNode,
3377 impl AstNode for TuplePat {
3378 fn can_cast(kind: SyntaxKind) -> bool {
3384 fn cast(syntax: SyntaxNode) -> Option<Self> {
3385 if Self::can_cast(syntax.kind()) {
3386 Some(Self { syntax })
3391 fn syntax(&self) -> &SyntaxNode {
3396 pub fn args(&self) -> AstChildren<Pat> {
3397 AstChildren::new(&self.syntax)
3400 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3401 pub struct TupleStructPat {
3402 pub(crate) syntax: SyntaxNode,
3404 impl AstNode for TupleStructPat {
3405 fn can_cast(kind: SyntaxKind) -> bool {
3407 TUPLE_STRUCT_PAT => true,
3411 fn cast(syntax: SyntaxNode) -> Option<Self> {
3412 if Self::can_cast(syntax.kind()) {
3413 Some(Self { syntax })
3418 fn syntax(&self) -> &SyntaxNode {
3422 impl TupleStructPat {
3423 pub fn args(&self) -> AstChildren<Pat> {
3424 AstChildren::new(&self.syntax)
3426 pub fn path(&self) -> Option<Path> {
3427 AstChildren::new(&self.syntax).next()
3430 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3431 pub struct TupleType {
3432 pub(crate) syntax: SyntaxNode,
3434 impl AstNode for TupleType {
3435 fn can_cast(kind: SyntaxKind) -> bool {
3441 fn cast(syntax: SyntaxNode) -> Option<Self> {
3442 if Self::can_cast(syntax.kind()) {
3443 Some(Self { syntax })
3448 fn syntax(&self) -> &SyntaxNode {
3453 pub fn fields(&self) -> AstChildren<TypeRef> {
3454 AstChildren::new(&self.syntax)
3457 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3458 pub struct TypeAliasDef {
3459 pub(crate) syntax: SyntaxNode,
3461 impl AstNode for TypeAliasDef {
3462 fn can_cast(kind: SyntaxKind) -> bool {
3464 TYPE_ALIAS_DEF => true,
3468 fn cast(syntax: SyntaxNode) -> Option<Self> {
3469 if Self::can_cast(syntax.kind()) {
3470 Some(Self { syntax })
3475 fn syntax(&self) -> &SyntaxNode {
3479 impl ast::VisibilityOwner for TypeAliasDef {}
3480 impl ast::NameOwner for TypeAliasDef {}
3481 impl ast::TypeParamsOwner for TypeAliasDef {}
3482 impl ast::AttrsOwner for TypeAliasDef {}
3483 impl ast::DocCommentsOwner for TypeAliasDef {}
3484 impl ast::TypeBoundsOwner for TypeAliasDef {}
3486 pub fn type_ref(&self) -> Option<TypeRef> {
3487 AstChildren::new(&self.syntax).next()
3490 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3491 pub struct TypeArg {
3492 pub(crate) syntax: SyntaxNode,
3494 impl AstNode for TypeArg {
3495 fn can_cast(kind: SyntaxKind) -> bool {
3501 fn cast(syntax: SyntaxNode) -> Option<Self> {
3502 if Self::can_cast(syntax.kind()) {
3503 Some(Self { syntax })
3508 fn syntax(&self) -> &SyntaxNode {
3513 pub fn type_ref(&self) -> Option<TypeRef> {
3514 AstChildren::new(&self.syntax).next()
3517 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3518 pub struct TypeArgList {
3519 pub(crate) syntax: SyntaxNode,
3521 impl AstNode for TypeArgList {
3522 fn can_cast(kind: SyntaxKind) -> bool {
3524 TYPE_ARG_LIST => true,
3528 fn cast(syntax: SyntaxNode) -> Option<Self> {
3529 if Self::can_cast(syntax.kind()) {
3530 Some(Self { syntax })
3535 fn syntax(&self) -> &SyntaxNode {
3540 pub fn type_args(&self) -> AstChildren<TypeArg> {
3541 AstChildren::new(&self.syntax)
3543 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3544 AstChildren::new(&self.syntax)
3546 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3547 AstChildren::new(&self.syntax)
3550 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3551 pub struct TypeBound {
3552 pub(crate) syntax: SyntaxNode,
3554 impl AstNode for TypeBound {
3555 fn can_cast(kind: SyntaxKind) -> bool {
3561 fn cast(syntax: SyntaxNode) -> Option<Self> {
3562 if Self::can_cast(syntax.kind()) {
3563 Some(Self { syntax })
3568 fn syntax(&self) -> &SyntaxNode {
3573 pub fn type_ref(&self) -> Option<TypeRef> {
3574 AstChildren::new(&self.syntax).next()
3577 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3578 pub struct TypeBoundList {
3579 pub(crate) syntax: SyntaxNode,
3581 impl AstNode for TypeBoundList {
3582 fn can_cast(kind: SyntaxKind) -> bool {
3584 TYPE_BOUND_LIST => true,
3588 fn cast(syntax: SyntaxNode) -> Option<Self> {
3589 if Self::can_cast(syntax.kind()) {
3590 Some(Self { syntax })
3595 fn syntax(&self) -> &SyntaxNode {
3599 impl TypeBoundList {
3600 pub fn bounds(&self) -> AstChildren<TypeBound> {
3601 AstChildren::new(&self.syntax)
3604 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3605 pub struct TypeParam {
3606 pub(crate) syntax: SyntaxNode,
3608 impl AstNode for TypeParam {
3609 fn can_cast(kind: SyntaxKind) -> bool {
3615 fn cast(syntax: SyntaxNode) -> Option<Self> {
3616 if Self::can_cast(syntax.kind()) {
3617 Some(Self { syntax })
3622 fn syntax(&self) -> &SyntaxNode {
3626 impl ast::NameOwner for TypeParam {}
3627 impl ast::AttrsOwner for TypeParam {}
3628 impl ast::TypeBoundsOwner for TypeParam {}
3629 impl ast::DefaultTypeParamOwner for TypeParam {}
3631 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3632 pub struct TypeParamList {
3633 pub(crate) syntax: SyntaxNode,
3635 impl AstNode for TypeParamList {
3636 fn can_cast(kind: SyntaxKind) -> bool {
3638 TYPE_PARAM_LIST => true,
3642 fn cast(syntax: SyntaxNode) -> Option<Self> {
3643 if Self::can_cast(syntax.kind()) {
3644 Some(Self { syntax })
3649 fn syntax(&self) -> &SyntaxNode {
3653 impl TypeParamList {
3654 pub fn type_params(&self) -> AstChildren<TypeParam> {
3655 AstChildren::new(&self.syntax)
3657 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3658 AstChildren::new(&self.syntax)
3661 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3663 ParenType(ParenType),
3664 TupleType(TupleType),
3665 NeverType(NeverType),
3667 PointerType(PointerType),
3668 ArrayType(ArrayType),
3669 SliceType(SliceType),
3670 ReferenceType(ReferenceType),
3671 PlaceholderType(PlaceholderType),
3672 FnPointerType(FnPointerType),
3674 ImplTraitType(ImplTraitType),
3675 DynTraitType(DynTraitType),
3677 impl From<ParenType> for TypeRef {
3678 fn from(node: ParenType) -> TypeRef {
3679 TypeRef::ParenType(node)
3682 impl From<TupleType> for TypeRef {
3683 fn from(node: TupleType) -> TypeRef {
3684 TypeRef::TupleType(node)
3687 impl From<NeverType> for TypeRef {
3688 fn from(node: NeverType) -> TypeRef {
3689 TypeRef::NeverType(node)
3692 impl From<PathType> for TypeRef {
3693 fn from(node: PathType) -> TypeRef {
3694 TypeRef::PathType(node)
3697 impl From<PointerType> for TypeRef {
3698 fn from(node: PointerType) -> TypeRef {
3699 TypeRef::PointerType(node)
3702 impl From<ArrayType> for TypeRef {
3703 fn from(node: ArrayType) -> TypeRef {
3704 TypeRef::ArrayType(node)
3707 impl From<SliceType> for TypeRef {
3708 fn from(node: SliceType) -> TypeRef {
3709 TypeRef::SliceType(node)
3712 impl From<ReferenceType> for TypeRef {
3713 fn from(node: ReferenceType) -> TypeRef {
3714 TypeRef::ReferenceType(node)
3717 impl From<PlaceholderType> for TypeRef {
3718 fn from(node: PlaceholderType) -> TypeRef {
3719 TypeRef::PlaceholderType(node)
3722 impl From<FnPointerType> for TypeRef {
3723 fn from(node: FnPointerType) -> TypeRef {
3724 TypeRef::FnPointerType(node)
3727 impl From<ForType> for TypeRef {
3728 fn from(node: ForType) -> TypeRef {
3729 TypeRef::ForType(node)
3732 impl From<ImplTraitType> for TypeRef {
3733 fn from(node: ImplTraitType) -> TypeRef {
3734 TypeRef::ImplTraitType(node)
3737 impl From<DynTraitType> for TypeRef {
3738 fn from(node: DynTraitType) -> TypeRef {
3739 TypeRef::DynTraitType(node)
3742 impl AstNode for TypeRef {
3743 fn can_cast(kind: SyntaxKind) -> bool {
3745 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3746 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3747 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3751 fn cast(syntax: SyntaxNode) -> Option<Self> {
3752 let res = match syntax.kind() {
3753 PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
3754 TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
3755 NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
3756 PATH_TYPE => TypeRef::PathType(PathType { syntax }),
3757 POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
3758 ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
3759 SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
3760 REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
3761 PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
3762 FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
3763 FOR_TYPE => TypeRef::ForType(ForType { syntax }),
3764 IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
3765 DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
3770 fn syntax(&self) -> &SyntaxNode {
3772 TypeRef::ParenType(it) => &it.syntax,
3773 TypeRef::TupleType(it) => &it.syntax,
3774 TypeRef::NeverType(it) => &it.syntax,
3775 TypeRef::PathType(it) => &it.syntax,
3776 TypeRef::PointerType(it) => &it.syntax,
3777 TypeRef::ArrayType(it) => &it.syntax,
3778 TypeRef::SliceType(it) => &it.syntax,
3779 TypeRef::ReferenceType(it) => &it.syntax,
3780 TypeRef::PlaceholderType(it) => &it.syntax,
3781 TypeRef::FnPointerType(it) => &it.syntax,
3782 TypeRef::ForType(it) => &it.syntax,
3783 TypeRef::ImplTraitType(it) => &it.syntax,
3784 TypeRef::DynTraitType(it) => &it.syntax,
3789 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3790 pub struct UseItem {
3791 pub(crate) syntax: SyntaxNode,
3793 impl AstNode for UseItem {
3794 fn can_cast(kind: SyntaxKind) -> bool {
3800 fn cast(syntax: SyntaxNode) -> Option<Self> {
3801 if Self::can_cast(syntax.kind()) {
3802 Some(Self { syntax })
3807 fn syntax(&self) -> &SyntaxNode {
3811 impl ast::AttrsOwner for UseItem {}
3813 pub fn use_tree(&self) -> Option<UseTree> {
3814 AstChildren::new(&self.syntax).next()
3817 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3818 pub struct UseTree {
3819 pub(crate) syntax: SyntaxNode,
3821 impl AstNode for UseTree {
3822 fn can_cast(kind: SyntaxKind) -> bool {
3828 fn cast(syntax: SyntaxNode) -> Option<Self> {
3829 if Self::can_cast(syntax.kind()) {
3830 Some(Self { syntax })
3835 fn syntax(&self) -> &SyntaxNode {
3840 pub fn path(&self) -> Option<Path> {
3841 AstChildren::new(&self.syntax).next()
3843 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3844 AstChildren::new(&self.syntax).next()
3846 pub fn alias(&self) -> Option<Alias> {
3847 AstChildren::new(&self.syntax).next()
3850 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3851 pub struct UseTreeList {
3852 pub(crate) syntax: SyntaxNode,
3854 impl AstNode for UseTreeList {
3855 fn can_cast(kind: SyntaxKind) -> bool {
3857 USE_TREE_LIST => true,
3861 fn cast(syntax: SyntaxNode) -> Option<Self> {
3862 if Self::can_cast(syntax.kind()) {
3863 Some(Self { syntax })
3868 fn syntax(&self) -> &SyntaxNode {
3873 pub fn use_trees(&self) -> AstChildren<UseTree> {
3874 AstChildren::new(&self.syntax)
3877 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3878 pub struct Visibility {
3879 pub(crate) syntax: SyntaxNode,
3881 impl AstNode for Visibility {
3882 fn can_cast(kind: SyntaxKind) -> bool {
3888 fn cast(syntax: SyntaxNode) -> Option<Self> {
3889 if Self::can_cast(syntax.kind()) {
3890 Some(Self { syntax })
3895 fn syntax(&self) -> &SyntaxNode {
3900 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3901 pub struct WhereClause {
3902 pub(crate) syntax: SyntaxNode,
3904 impl AstNode for WhereClause {
3905 fn can_cast(kind: SyntaxKind) -> bool {
3907 WHERE_CLAUSE => true,
3911 fn cast(syntax: SyntaxNode) -> Option<Self> {
3912 if Self::can_cast(syntax.kind()) {
3913 Some(Self { syntax })
3918 fn syntax(&self) -> &SyntaxNode {
3923 pub fn predicates(&self) -> AstChildren<WherePred> {
3924 AstChildren::new(&self.syntax)
3927 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3928 pub struct WherePred {
3929 pub(crate) syntax: SyntaxNode,
3931 impl AstNode for WherePred {
3932 fn can_cast(kind: SyntaxKind) -> bool {
3938 fn cast(syntax: SyntaxNode) -> Option<Self> {
3939 if Self::can_cast(syntax.kind()) {
3940 Some(Self { syntax })
3945 fn syntax(&self) -> &SyntaxNode {
3949 impl ast::TypeBoundsOwner for WherePred {}
3951 pub fn type_ref(&self) -> Option<TypeRef> {
3952 AstChildren::new(&self.syntax).next()
3955 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3956 pub struct WhileExpr {
3957 pub(crate) syntax: SyntaxNode,
3959 impl AstNode for WhileExpr {
3960 fn can_cast(kind: SyntaxKind) -> bool {
3966 fn cast(syntax: SyntaxNode) -> Option<Self> {
3967 if Self::can_cast(syntax.kind()) {
3968 Some(Self { syntax })
3973 fn syntax(&self) -> &SyntaxNode {
3977 impl ast::LoopBodyOwner for WhileExpr {}
3979 pub fn condition(&self) -> Option<Condition> {
3980 AstChildren::new(&self.syntax).next()