From 689661c95968cb438f8bd1f10ce0ee096287741b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 13:00:09 +0200 Subject: [PATCH] Scale back to only two traits --- .../src/handlers/introduce_variable.rs | 4 +- crates/ra_hir_def/src/body/lower.rs | 1 - crates/ra_syntax/src/ast.rs | 16 + crates/ra_syntax/src/ast/extensions.rs | 13 +- crates/ra_syntax/src/ast/generated.rs | 2093 +++++++++++++++-- crates/ra_syntax/src/ast/traits.rs | 26 +- xtask/src/ast_src.rs | 8 - xtask/src/codegen/gen_syntax.rs | 87 +- 8 files changed, 2020 insertions(+), 228 deletions(-) diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs index 9963f884bb..8a02f1a32c 100644 --- a/crates/ra_assists/src/handlers/introduce_variable.rs +++ b/crates/ra_assists/src/handlers/introduce_variable.rs @@ -1,5 +1,5 @@ use ra_syntax::{ - ast::{self, AstElement, AstNode}, + ast::{self, AstNode}, SyntaxKind::{ BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, WHITESPACE, @@ -124,7 +124,7 @@ fn anchor_stmt(expr: ast::Expr) -> Option<(SyntaxNode, bool)> { } } - if ast::Stmt::cast_element(node.clone().into()).is_some() { + if ast::Stmt::cast(node.clone().into()).is_some() { return Some((node, false)); } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 8338414faa..b02de5d67d 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -492,7 +492,6 @@ impl ExprCollector<'_> { ast::Stmt::ExprStmt(stmt) => { Some(Statement::Expr(self.collect_expr_opt(stmt.expr()))) } - ast::Stmt::ModuleItem(_) => None, }) .collect(); let tail = block.expr().map(|e| self.collect_expr(e)); diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index c81b68d3e2..e1ebd5b928 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -64,6 +64,22 @@ pub trait AstToken { } } +mod support { + use super::{AstChildren, AstNode, AstToken, SyntaxNode}; + + pub(super) fn child(parent: &SyntaxNode) -> Option { + parent.children().find_map(N::cast) + } + + pub(super) fn children(parent: &SyntaxNode) -> AstChildren { + AstChildren::new(parent) + } + + pub(super) fn token(parent: &SyntaxNode) -> Option { + parent.children_with_tokens().filter_map(|it| it.into_token()).find_map(T::cast) + } +} + /// An iterator over `SyntaxNode` children of a particular AST type. #[derive(Debug, Clone)] pub struct AstChildren { diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 400eba210a..33fe60762a 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -5,8 +5,7 @@ use itertools::Itertools; use crate::{ ast::{ - self, child_opt, child_token_opt, children, AstElement, AstNode, AstToken, AttrInput, - NameOwner, SyntaxNode, + self, child_opt, children, support, AstNode, AstToken, AttrInput, NameOwner, SyntaxNode, }, SmolStr, SyntaxElement, SyntaxKind::*, @@ -437,7 +436,7 @@ impl ast::TypeBound { .skip_while(|it| it.kind() != T![const]) .find_map(ast::Question::cast) } else { - child_token_opt(self) + support::token(&self.syntax) } } } @@ -509,7 +508,7 @@ impl ast::RangePat { pub fn start(&self) -> Option { self.syntax() .children_with_tokens() - .take_while(|it| !ast::RangeSeparator::can_cast_element(it.kind())) + .take_while(|it| !ast::RangeSeparator::can_cast(it.kind())) .filter_map(|it| it.into_node()) .find_map(ast::Pat::cast) } @@ -517,7 +516,7 @@ impl ast::RangePat { pub fn end(&self) -> Option { self.syntax() .children_with_tokens() - .skip_while(|it| !ast::RangeSeparator::can_cast_element(it.kind())) + .skip_while(|it| !ast::RangeSeparator::can_cast(it.kind())) .filter_map(|it| it.into_node()) .find_map(ast::Pat::cast) } @@ -525,10 +524,10 @@ impl ast::RangePat { impl ast::TokenTree { pub fn left_delimiter(&self) -> Option { - self.syntax().first_child_or_token().and_then(ast::LeftDelimiter::cast_element) + self.syntax().first_child_or_token()?.into_token().and_then(ast::LeftDelimiter::cast) } pub fn right_delimiter(&self) -> Option { - self.syntax().last_child_or_token().and_then(ast::RightDelimiter::cast_element) + self.syntax().last_child_or_token()?.into_token().and_then(ast::RightDelimiter::cast) } } diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 385fddc89e..bd92e9c874 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -2,7 +2,7 @@ #[allow(unused_imports)] use crate::{ - ast::{self, AstChildren, AstNode, AstToken}, + ast::{self, support, AstChildren, AstNode, AstToken}, NodeOrToken, SyntaxElement, SyntaxKind::{self, *}, SyntaxNode, SyntaxToken, @@ -2600,6 +2600,33 @@ impl AstToken for UnionKw { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RawKw { + pub(crate) syntax: SyntaxToken, +} +impl std::fmt::Display for RawKw { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt(&self.syntax, f) + } +} +impl AstToken for RawKw { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RAW_KW => true, + _ => false, + } + } + fn cast(syntax: SyntaxToken) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxToken { + &self.syntax + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct IntNumber { pub(crate) syntax: SyntaxToken, } @@ -3060,9 +3087,10 @@ impl AstNode for SourceFile { } impl ast::ModuleItemOwner for SourceFile {} impl ast::FnDefOwner for SourceFile {} +impl ast::AttrsOwner for SourceFile {} impl SourceFile { pub fn modules(&self) -> AstChildren { - AstChildren::new(&self.syntax) + support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3098,14 +3126,35 @@ impl ast::TypeParamsOwner for FnDef {} impl ast::DocCommentsOwner for FnDef {} impl ast::AttrsOwner for FnDef {} impl FnDef { + pub fn abi(&self) -> Option { + support::child(&self.syntax) + } + pub fn const_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn default_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn async_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn unsafe_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn fn_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn param_list(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } pub fn ret_type(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } pub fn body(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn semi(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3136,8 +3185,11 @@ impl AstNode for RetType { } } impl RetType { + pub fn thin_arrow(&self) -> Option { + support::token(&self.syntax) + } pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3172,7 +3224,17 @@ impl ast::NameOwner for StructDef {} impl ast::TypeParamsOwner for StructDef {} impl ast::AttrsOwner for StructDef {} impl ast::DocCommentsOwner for StructDef {} -impl StructDef {} +impl StructDef { + pub fn struct_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn field_def_list(&self) -> Option { + support::child(&self.syntax) + } + pub fn semi(&self) -> Option { + support::token(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UnionDef { pub(crate) syntax: SyntaxNode, @@ -3206,8 +3268,11 @@ impl ast::TypeParamsOwner for UnionDef {} impl ast::AttrsOwner for UnionDef {} impl ast::DocCommentsOwner for UnionDef {} impl UnionDef { + pub fn union_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn record_field_def_list(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3238,8 +3303,14 @@ impl AstNode for RecordFieldDefList { } } impl RecordFieldDefList { + pub fn l_curly(&self) -> Option { + support::token(&self.syntax) + } pub fn fields(&self) -> AstChildren { - AstChildren::new(&self.syntax) + support::children(&self.syntax) + } + pub fn r_curly(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3303,8 +3374,14 @@ impl AstNode for TupleFieldDefList { } } impl TupleFieldDefList { + pub fn l_paren(&self) -> Option { + support::token(&self.syntax) + } pub fn fields(&self) -> AstChildren { - AstChildren::new(&self.syntax) + support::children(&self.syntax) + } + pub fn r_paren(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3338,7 +3415,7 @@ impl ast::VisibilityOwner for TupleFieldDef {} impl ast::AttrsOwner for TupleFieldDef {} impl TupleFieldDef { pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3374,8 +3451,11 @@ impl ast::TypeParamsOwner for EnumDef {} impl ast::AttrsOwner for EnumDef {} impl ast::DocCommentsOwner for EnumDef {} impl EnumDef { + pub fn enum_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn variant_list(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3406,8 +3486,14 @@ impl AstNode for EnumVariantList { } } impl EnumVariantList { + pub fn l_curly(&self) -> Option { + support::token(&self.syntax) + } pub fn variants(&self) -> AstChildren { - AstChildren::new(&self.syntax) + support::children(&self.syntax) + } + pub fn r_curly(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3437,12 +3523,19 @@ impl AstNode for EnumVariant { &self.syntax } } +impl ast::VisibilityOwner for EnumVariant {} impl ast::NameOwner for EnumVariant {} impl ast::DocCommentsOwner for EnumVariant {} impl ast::AttrsOwner for EnumVariant {} impl EnumVariant { + pub fn field_def_list(&self) -> Option { + support::child(&self.syntax) + } + pub fn eq(&self) -> Option { + support::token(&self.syntax) + } pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3479,8 +3572,17 @@ impl ast::DocCommentsOwner for TraitDef {} impl ast::TypeParamsOwner for TraitDef {} impl ast::TypeBoundsOwner for TraitDef {} impl TraitDef { + pub fn unsafe_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn auto_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn trait_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn item_list(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3515,8 +3617,14 @@ impl ast::NameOwner for Module {} impl ast::AttrsOwner for Module {} impl ast::DocCommentsOwner for Module {} impl Module { + pub fn mod_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn item_list(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn semi(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3549,8 +3657,14 @@ impl AstNode for ItemList { impl ast::FnDefOwner for ItemList {} impl ast::ModuleItemOwner for ItemList {} impl ItemList { + pub fn l_curly(&self) -> Option { + support::token(&self.syntax) + } pub fn impl_items(&self) -> AstChildren { - AstChildren::new(&self.syntax) + support::children(&self.syntax) + } + pub fn r_curly(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3587,8 +3701,20 @@ impl ast::AttrsOwner for ConstDef {} impl ast::DocCommentsOwner for ConstDef {} impl ast::TypeAscriptionOwner for ConstDef {} impl ConstDef { + pub fn default_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn const_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn eq(&self) -> Option { + support::token(&self.syntax) + } pub fn body(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn semi(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3625,8 +3751,20 @@ impl ast::AttrsOwner for StaticDef {} impl ast::DocCommentsOwner for StaticDef {} impl ast::TypeAscriptionOwner for StaticDef {} impl StaticDef { + pub fn static_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn mut_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn eq(&self) -> Option { + support::token(&self.syntax) + } pub fn body(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn semi(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3663,8 +3801,20 @@ impl ast::AttrsOwner for TypeAliasDef {} impl ast::DocCommentsOwner for TypeAliasDef {} impl ast::TypeBoundsOwner for TypeAliasDef {} impl TypeAliasDef { + pub fn default_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn type_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn eq(&self) -> Option { + support::token(&self.syntax) + } pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn semi(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3697,8 +3847,26 @@ impl AstNode for ImplDef { impl ast::TypeParamsOwner for ImplDef {} impl ast::AttrsOwner for ImplDef {} impl ImplDef { + pub fn default_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn const_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn unsafe_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn impl_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn excl(&self) -> Option { + support::token(&self.syntax) + } + pub fn for_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn item_list(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3729,8 +3897,14 @@ impl AstNode for ParenType { } } impl ParenType { + pub fn l_paren(&self) -> Option { + support::token(&self.syntax) + } pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn r_paren(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3761,8 +3935,14 @@ impl AstNode for TupleType { } } impl TupleType { + pub fn l_paren(&self) -> Option { + support::token(&self.syntax) + } pub fn fields(&self) -> AstChildren { - AstChildren::new(&self.syntax) + support::children(&self.syntax) + } + pub fn r_paren(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3792,7 +3972,11 @@ impl AstNode for NeverType { &self.syntax } } -impl NeverType {} +impl NeverType { + pub fn excl(&self) -> Option { + support::token(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PathType { pub(crate) syntax: SyntaxNode, @@ -3822,7 +4006,7 @@ impl AstNode for PathType { } impl PathType { pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3853,8 +4037,14 @@ impl AstNode for PointerType { } } impl PointerType { + pub fn star(&self) -> Option { + support::token(&self.syntax) + } + pub fn const_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3885,11 +4075,20 @@ impl AstNode for ArrayType { } } impl ArrayType { + pub fn l_brack(&self) -> Option { + support::token(&self.syntax) + } pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn semi(&self) -> Option { + support::token(&self.syntax) } pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn r_brack(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3920,8 +4119,14 @@ impl AstNode for SliceType { } } impl SliceType { + pub fn l_brack(&self) -> Option { + support::token(&self.syntax) + } pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn r_brack(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3952,8 +4157,17 @@ impl AstNode for ReferenceType { } } impl ReferenceType { + pub fn amp(&self) -> Option { + support::token(&self.syntax) + } + pub fn lifetime(&self) -> Option { + support::token(&self.syntax) + } + pub fn mut_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3983,7 +4197,11 @@ impl AstNode for PlaceholderType { &self.syntax } } -impl PlaceholderType {} +impl PlaceholderType { + pub fn underscore(&self) -> Option { + support::token(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FnPointerType { pub(crate) syntax: SyntaxNode, @@ -4012,11 +4230,20 @@ impl AstNode for FnPointerType { } } impl FnPointerType { + pub fn abi(&self) -> Option { + support::child(&self.syntax) + } + pub fn unsafe_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn fn_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn param_list(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } pub fn ret_type(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4047,8 +4274,14 @@ impl AstNode for ForType { } } impl ForType { + pub fn for_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn type_param_list(&self) -> Option { + support::child(&self.syntax) + } pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4079,7 +4312,11 @@ impl AstNode for ImplTraitType { } } impl ast::TypeBoundsOwner for ImplTraitType {} -impl ImplTraitType {} +impl ImplTraitType { + pub fn impl_kw(&self) -> Option { + support::token(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DynTraitType { pub(crate) syntax: SyntaxNode, @@ -4108,7 +4345,11 @@ impl AstNode for DynTraitType { } } impl ast::TypeBoundsOwner for DynTraitType {} -impl DynTraitType {} +impl DynTraitType { + pub fn dyn_kw(&self) -> Option { + support::token(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TupleExpr { pub(crate) syntax: SyntaxNode, @@ -4136,9 +4377,16 @@ impl AstNode for TupleExpr { &self.syntax } } +impl ast::AttrsOwner for TupleExpr {} impl TupleExpr { + pub fn l_paren(&self) -> Option { + support::token(&self.syntax) + } pub fn exprs(&self) -> AstChildren { - AstChildren::new(&self.syntax) + support::children(&self.syntax) + } + pub fn r_paren(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4168,9 +4416,19 @@ impl AstNode for ArrayExpr { &self.syntax } } +impl ast::AttrsOwner for ArrayExpr {} impl ArrayExpr { + pub fn l_brack(&self) -> Option { + support::token(&self.syntax) + } pub fn exprs(&self) -> AstChildren { - AstChildren::new(&self.syntax) + support::children(&self.syntax) + } + pub fn semi(&self) -> Option { + support::token(&self.syntax) + } + pub fn r_brack(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4200,9 +4458,16 @@ impl AstNode for ParenExpr { &self.syntax } } +impl ast::AttrsOwner for ParenExpr {} impl ParenExpr { + pub fn l_paren(&self) -> Option { + support::token(&self.syntax) + } pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn r_paren(&self) -> Option { + support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4234,7 +4499,7 @@ impl AstNode for PathExpr { } impl PathExpr { pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4264,15 +4529,25 @@ impl AstNode for LambdaExpr { &self.syntax } } +impl ast::AttrsOwner for LambdaExpr {} impl LambdaExpr { + pub fn static_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn async_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn move_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn param_list(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } pub fn ret_type(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } pub fn body(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4302,9 +4577,13 @@ impl AstNode for IfExpr { &self.syntax } } +impl ast::AttrsOwner for IfExpr {} impl IfExpr { + pub fn if_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn condition(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4334,8 +4613,13 @@ impl AstNode for LoopExpr { &self.syntax } } +impl ast::AttrsOwner for LoopExpr {} impl ast::LoopBodyOwner for LoopExpr {} -impl LoopExpr {} +impl LoopExpr { + pub fn loop_kw(&self) -> Option { + support::token(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TryBlockExpr { pub(crate) syntax: SyntaxNode, @@ -4363,9 +4647,13 @@ impl AstNode for TryBlockExpr { &self.syntax } } +impl ast::AttrsOwner for TryBlockExpr {} impl TryBlockExpr { + pub fn try_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn body(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4395,13 +4683,20 @@ impl AstNode for ForExpr { &self.syntax } } +impl ast::AttrsOwner for ForExpr {} impl ast::LoopBodyOwner for ForExpr {} impl ForExpr { + pub fn for_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) + } + pub fn in_kw(&self) -> Option { + support::token(&self.syntax) } pub fn iterable(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4431,10 +4726,14 @@ impl AstNode for WhileExpr { &self.syntax } } +impl ast::AttrsOwner for WhileExpr {} impl ast::LoopBodyOwner for WhileExpr {} impl WhileExpr { + pub fn while_kw(&self) -> Option { + support::token(&self.syntax) + } pub fn condition(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4464,7 +4763,15 @@ impl AstNode for ContinueExpr { &self.syntax } } -impl ContinueExpr {} +impl ast::AttrsOwner for ContinueExpr {} +impl ContinueExpr { + pub fn continue_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn lifetime(&self) -> Option { + support::token(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BreakExpr { pub(crate) syntax: SyntaxNode, @@ -4492,9 +4799,16 @@ impl AstNode for BreakExpr { &self.syntax } } +impl ast::AttrsOwner for BreakExpr {} impl BreakExpr { + pub fn break_kw(&self) -> Option { + support::token(&self.syntax) + } + pub fn lifetime(&self) -> Option { + support::token(&self.syntax) + } pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() + support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -4524,7 +4838,11 @@ impl AstNode for Label { &self.syntax } } -impl Label {} +impl Label { + pub fn lifetime(&self) -> Option { + support::token(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BlockExpr { pub(crate) syntax: SyntaxNode, @@ -4552,9 +4870,16 @@ impl AstNode for BlockExpr { &self.syntax } } +impl ast::AttrsOwner for BlockExpr {} impl BlockExpr { + pub fn label(&self) -> Option