From 0ed27c388adca887cda3d8141efaf974e90a5958 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:02:10 +0200 Subject: Drop needless trait --- crates/ra_ide/src/completion/complete_fn_param.rs | 30 ++++++++++++----------- crates/ra_syntax/src/ast/generated/nodes.rs | 4 --- crates/ra_syntax/src/ast/traits.rs | 6 ----- 3 files changed, 16 insertions(+), 24 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 62ae5ccb4..f84b559fc 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -1,6 +1,9 @@ //! FIXME: write short doc here -use ra_syntax::{ast, match_ast, AstNode}; +use ra_syntax::{ + ast::{self, ModuleItemOwner}, + match_ast, AstNode, +}; use rustc_hash::FxHashMap; use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; @@ -16,11 +19,19 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) let mut params = FxHashMap::default(); for node in ctx.token.parent().ancestors() { - match_ast! { + let items = match_ast! { match node { - ast::SourceFile(it) => process(it, &mut params), - ast::ItemList(it) => process(it, &mut params), - _ => (), + ast::SourceFile(it) => it.items(), + ast::ItemList(it) => it.items(), + _ => continue, + } + }; + for item in items { + if let ast::ModuleItem::FnDef(func) = item { + func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { + let text = param.syntax().text().to_string(); + params.entry(text).or_insert((0, param)).0 += 1; + }) } } } @@ -39,15 +50,6 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) .lookup_by(lookup) .add_to(acc) }); - - fn process(node: N, params: &mut FxHashMap) { - node.functions().filter_map(|it| it.param_list()).flat_map(|it| it.params()).for_each( - |param| { - let text = param.syntax().text().to_string(); - params.entry(text).or_insert((0, param)).0 += 1; - }, - ) - } } #[cfg(test)] diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index bcbfd1129..3b820507d 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -22,7 +22,6 @@ impl AstNode for SourceFile { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::ModuleItemOwner for SourceFile {} -impl ast::FnDefOwner for SourceFile {} impl ast::AttrsOwner for SourceFile {} impl SourceFile { pub fn modules(&self) -> AstChildren { support::children(&self.syntax) } @@ -344,7 +343,6 @@ impl AstNode for ItemList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ast::FnDefOwner for ItemList {} impl ast::ModuleItemOwner for ItemList {} impl ItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax) } @@ -2512,7 +2510,6 @@ impl AstNode for MacroItems { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::ModuleItemOwner for MacroItems {} -impl ast::FnDefOwner for MacroItems {} impl MacroItems {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MacroStmts { @@ -2548,7 +2545,6 @@ impl AstNode for ExternItemList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ast::FnDefOwner for ExternItemList {} impl ast::ModuleItemOwner for ExternItemList {} impl ExternItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax) } diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index f6c786e44..f0b54cf29 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -43,12 +43,6 @@ pub trait ArgListOwner: AstNode { } } -pub trait FnDefOwner: AstNode { - fn functions(&self) -> AstChildren { - support::children(self.syntax()) - } -} - pub trait ModuleItemOwner: AstNode { fn items(&self) -> AstChildren { support::children(self.syntax()) -- cgit v1.2.3 From 046a02101355bb58cf66218f7dd6dc4fa78fc53f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:05:13 +0200 Subject: use stdx --- crates/ra_syntax/src/ast/traits.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index f0b54cf29..4ed7cf73b 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -1,8 +1,7 @@ //! Various traits that are implemented by ast nodes. //! //! The implementations are usually trivial, and live in generated.rs - -use itertools::Itertools; +use stdx::SepBy; use crate::{ ast::{self, support, AstChildren, AstNode, AstToken}, @@ -116,7 +115,8 @@ pub trait DocCommentsOwner: AstNode { // of a line in markdown. line[pos..end].to_owned() }) - .join("\n"); + .sep_by("\n") + .to_string(); if has_comments { Some(docs) -- cgit v1.2.3 From 00ec0c10669307bc752812f535f96e121338d688 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:19:51 +0200 Subject: use uniform accessor --- crates/ra_hir_def/src/body/lower.rs | 2 +- crates/ra_syntax/src/ast/expr_extensions.rs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index df560155c..4f23cb5c8 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -372,7 +372,7 @@ impl ExprCollector<'_> { } ast::Expr::RefExpr(e) => { let expr = self.collect_expr_opt(e.expr()); - let mutability = Mutability::from_mutable(e.is_mut()); + let mutability = Mutability::from_mutable(e.mut_kw_token().is_some()); self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) } ast::Expr::PrefixExpr(e) => { diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 003ee00b3..5c5f19622 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -49,10 +49,6 @@ impl ast::IfExpr { } impl ast::RefExpr { - pub fn is_mut(&self) -> bool { - self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) - } - pub fn raw_token(&self) -> Option { None // FIXME: implement &raw } -- cgit v1.2.3 From 30084a56a5731343bd4cec727646a6c55900234f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:35:05 +0200 Subject: Simpler acessors for keywords --- .../src/handlers/inline_local_variable.rs | 2 +- crates/ra_hir_def/src/body/lower.rs | 10 +- crates/ra_hir_def/src/data.rs | 4 +- crates/ra_hir_def/src/type_ref.rs | 4 +- crates/ra_hir_ty/src/tests.rs | 4 +- crates/ra_ide/src/completion/completion_context.rs | 4 +- crates/ra_ide/src/references.rs | 2 +- crates/ra_syntax/src/ast.rs | 6 +- crates/ra_syntax/src/ast/expr_extensions.rs | 6 - crates/ra_syntax/src/ast/extensions.rs | 18 +- crates/ra_syntax/src/ast/generated/nodes.rs | 140 ++-- crates/ra_syntax/src/ast/generated/tokens.rs | 916 +-------------------- 12 files changed, 101 insertions(+), 1015 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index b9eb09676..c4fb425b0 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs @@ -29,7 +29,7 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option { ast::Pat::BindPat(pat) => pat, _ => return None, }; - if bind_pat.mut_kw_token().is_some() { + if bind_pat.mut_token().is_some() { tested_by!(test_not_inline_mut_variable); return None; } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 4f23cb5c8..b0d71eb3d 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -372,7 +372,7 @@ impl ExprCollector<'_> { } ast::Expr::RefExpr(e) => { let expr = self.collect_expr_opt(e.expr()); - let mutability = Mutability::from_mutable(e.mut_kw_token().is_some()); + let mutability = Mutability::from_mutable(e.mut_token().is_some()); self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) } ast::Expr::PrefixExpr(e) => { @@ -587,10 +587,8 @@ impl ExprCollector<'_> { let pattern = match &pat { ast::Pat::BindPat(bp) => { let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); - let annotation = BindingAnnotation::new( - bp.mut_kw_token().is_some(), - bp.ref_kw_token().is_some(), - ); + let annotation = + BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some()); let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); if annotation == BindingAnnotation::Unannotated && subpat.is_none() { // This could also be a single-segment path pattern. To @@ -631,7 +629,7 @@ impl ExprCollector<'_> { } ast::Pat::RefPat(p) => { let pat = self.collect_pat_opt(p.pat()); - let mutability = Mutability::from_mutable(p.mut_kw_token().is_some()); + let mutability = Mutability::from_mutable(p.mut_token().is_some()); Pat::Ref { pat, mutability } } ast::Pat::PathPat(p) => { diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 419d62c28..b8fbf0ed4 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -74,7 +74,7 @@ impl FunctionData { TypeRef::unit() }; - let ret_type = if src.value.async_kw_token().is_some() { + let ret_type = if src.value.async_token().is_some() { let future_impl = desugar_future_path(ret_type); let ty_bound = TypeBound::Path(future_impl); TypeRef::ImplTrait(vec![ty_bound]) @@ -135,7 +135,7 @@ impl TraitData { pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc { let src = tr.lookup(db).source(db); let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); - let auto = src.value.auto_kw_token().is_some(); + let auto = src.value.auto_token().is_some(); let ast_id_map = db.ast_id_map(src.file_id); let container = AssocContainerId::TraitId(tr); diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index 7a8338937..ea29c4176 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs @@ -77,7 +77,7 @@ impl TypeRef { } ast::TypeRef::PointerType(inner) => { let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); - let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some()); + let mutability = Mutability::from_mutable(inner.mut_token().is_some()); TypeRef::RawPtr(Box::new(inner_ty), mutability) } ast::TypeRef::ArrayType(inner) => { @@ -88,7 +88,7 @@ impl TypeRef { } ast::TypeRef::ReferenceType(inner) => { let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); - let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some()); + let mutability = Mutability::from_mutable(inner.mut_token().is_some()); TypeRef::Reference(Box::new(inner_ty), mutability) } ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 3b078b8c7..002cffba6 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs @@ -23,7 +23,7 @@ use insta::assert_snapshot; use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase}; use ra_syntax::{ algo, - ast::{self, AstNode, AstToken}, + ast::{self, AstNode}, }; use stdx::format_to; @@ -101,7 +101,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { let node = src_ptr.value.to_node(&src_ptr.file_syntax(&db)); let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.clone()) { - (self_param.self_kw_token().unwrap().syntax().text_range(), "self".to_string()) + (self_param.self_token().unwrap().text_range(), "self".to_string()) } else { (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) }; diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 0e34d85db..6637afaf7 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -191,8 +191,8 @@ impl<'a> CompletionContext<'a> { if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { self.is_pat_binding_or_const = true; if bind_pat.at_token().is_some() - || bind_pat.ref_kw_token().is_some() - || bind_pat.mut_kw_token().is_some() + || bind_pat.ref_token().is_some() + || bind_pat.mut_token().is_some() { self.is_pat_binding_or_const = false; } diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index ad6fd50aa..7d0544ff4 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -152,7 +152,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio if stmt.initializer().is_some() { let pat = stmt.pat()?; if let ast::Pat::BindPat(it) = pat { - if it.mut_kw_token().is_some() { + if it.mut_token().is_some() { return Some(ReferenceAccess::Write); } } diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index cb701f7f6..1ee60e74c 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -80,7 +80,7 @@ impl Iterator for AstChildren { } mod support { - use super::{AstChildren, AstNode, AstToken, SyntaxNode}; + use super::{AstChildren, AstNode, AstToken, SyntaxKind, SyntaxNode, SyntaxToken}; pub(super) fn child(parent: &SyntaxNode) -> Option { parent.children().find_map(N::cast) @@ -93,6 +93,10 @@ mod support { pub(super) fn token(parent: &SyntaxNode) -> Option { parent.children_with_tokens().filter_map(|it| it.into_token()).find_map(T::cast) } + + pub(super) fn token2(parent: &SyntaxNode, kind: SyntaxKind) -> Option { + parent.children_with_tokens().filter_map(|it| it.into_token()).find(|it| it.kind() == kind) + } } #[test] diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 5c5f19622..93aa3d45f 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -48,12 +48,6 @@ impl ast::IfExpr { } } -impl ast::RefExpr { - pub fn raw_token(&self) -> Option { - None // FIXME: implement &raw - } -} - #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub enum PrefixOp { /// The `*` operator for dereferencing diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index fc252e79c..11ec70bc0 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -279,7 +279,7 @@ pub enum SelfParamKind { impl ast::SelfParam { pub fn kind(&self) -> SelfParamKind { if self.amp_token().is_some() { - if self.amp_mut_kw_token().is_some() { + if self.amp_mut_token().is_some() { SelfParamKind::MutRef } else { SelfParamKind::Ref @@ -290,21 +290,21 @@ impl ast::SelfParam { } /// the "mut" in "mut self", not the one in "&mut self" - pub fn mut_kw_token(&self) -> Option { + pub fn mut_token(&self) -> Option { self.syntax() .children_with_tokens() .filter_map(|it| it.into_token()) .take_while(|it| it.kind() != T![&]) - .find_map(ast::MutKw::cast) + .find(|it| it.kind() == T![mut]) } /// the "mut" in "&mut self", not the one in "mut self" - pub fn amp_mut_kw_token(&self) -> Option { + pub fn amp_mut_token(&self) -> Option { self.syntax() .children_with_tokens() .filter_map(|it| it.into_token()) .skip_while(|it| it.kind() != T![&]) - .find_map(ast::MutKw::cast) + .find(|it| it.kind() == T![mut]) } } @@ -340,7 +340,7 @@ impl ast::TypeBound { } pub fn question_token(&self) -> Option { - if self.const_kw_token().is_some() { + if self.const_token().is_some() { self.syntax() .children_with_tokens() .filter_map(|it| it.into_token()) @@ -364,11 +364,11 @@ impl ast::Visibility { pub fn kind(&self) -> VisibilityKind { if let Some(path) = support::children(self.syntax()).next() { VisibilityKind::In(path) - } else if self.crate_kw_token().is_some() { + } else if self.crate_token().is_some() { VisibilityKind::PubCrate - } else if self.super_kw_token().is_some() { + } else if self.super_token().is_some() { VisibilityKind::PubSuper - } else if self.self_kw_token().is_some() { + } else if self.self_token().is_some() { VisibilityKind::PubSuper } else { VisibilityKind::Pub diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 3b820507d..20f663046 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -4,7 +4,7 @@ use super::tokens::*; use crate::{ ast::{self, support, AstChildren, AstNode}, SyntaxKind::{self, *}, - SyntaxNode, + SyntaxNode, SyntaxToken, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SourceFile { @@ -48,11 +48,11 @@ 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_token(&self) -> Option { support::token(&self.syntax) } - pub fn default_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn async_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn unsafe_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn fn_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn const_token(&self) -> Option { support::token2(&self.syntax, CONST_KW) } + pub fn default_token(&self) -> Option { support::token2(&self.syntax, DEFAULT_KW) } + pub fn async_token(&self) -> Option { support::token2(&self.syntax, ASYNC_KW) } + pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, UNSAFE_KW) } + pub fn fn_token(&self) -> Option { support::token2(&self.syntax, FN_KW) } pub fn param_list(&self) -> Option { support::child(&self.syntax) } pub fn ret_type(&self) -> Option { support::child(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } @@ -98,7 +98,7 @@ impl ast::TypeParamsOwner for StructDef {} impl ast::AttrsOwner for StructDef {} impl ast::DocCommentsOwner for StructDef {} impl StructDef { - pub fn struct_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn struct_token(&self) -> Option { support::token2(&self.syntax, STRUCT_KW) } pub fn field_def_list(&self) -> Option { support::child(&self.syntax) } pub fn semi_token(&self) -> Option { support::token(&self.syntax) } } @@ -123,7 +123,7 @@ impl ast::TypeParamsOwner for UnionDef {} impl ast::AttrsOwner for UnionDef {} impl ast::DocCommentsOwner for UnionDef {} impl UnionDef { - pub fn union_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn union_token(&self) -> Option { support::token2(&self.syntax, UNION_KW) } pub fn record_field_def_list(&self) -> Option { support::child(&self.syntax) } @@ -230,7 +230,7 @@ impl ast::TypeParamsOwner for EnumDef {} impl ast::AttrsOwner for EnumDef {} impl ast::DocCommentsOwner for EnumDef {} impl EnumDef { - pub fn enum_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn enum_token(&self) -> Option { support::token2(&self.syntax, ENUM_KW) } pub fn variant_list(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -299,9 +299,9 @@ impl ast::DocCommentsOwner for TraitDef {} impl ast::TypeParamsOwner for TraitDef {} impl ast::TypeBoundsOwner for TraitDef {} impl TraitDef { - pub fn unsafe_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn auto_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn trait_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, UNSAFE_KW) } + pub fn auto_token(&self) -> Option { support::token2(&self.syntax, AUTO_KW) } + pub fn trait_token(&self) -> Option { support::token2(&self.syntax, TRAIT_KW) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -324,7 +324,7 @@ impl ast::NameOwner for Module {} impl ast::AttrsOwner for Module {} impl ast::DocCommentsOwner for Module {} impl Module { - pub fn mod_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn mod_token(&self) -> Option { support::token2(&self.syntax, MOD_KW) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } pub fn semi_token(&self) -> Option { support::token(&self.syntax) } } @@ -371,8 +371,8 @@ impl ast::AttrsOwner for ConstDef {} impl ast::DocCommentsOwner for ConstDef {} impl ast::TypeAscriptionOwner for ConstDef {} impl ConstDef { - pub fn default_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn const_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn default_token(&self) -> Option { support::token2(&self.syntax, DEFAULT_KW) } + pub fn const_token(&self) -> Option { support::token2(&self.syntax, CONST_KW) } pub fn eq_token(&self) -> Option { support::token(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } pub fn semi_token(&self) -> Option { support::token(&self.syntax) } @@ -399,8 +399,8 @@ impl ast::AttrsOwner for StaticDef {} impl ast::DocCommentsOwner for StaticDef {} impl ast::TypeAscriptionOwner for StaticDef {} impl StaticDef { - pub fn static_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn mut_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn static_token(&self) -> Option { support::token2(&self.syntax, STATIC_KW) } + pub fn mut_token(&self) -> Option { support::token2(&self.syntax, MUT_KW) } pub fn eq_token(&self) -> Option { support::token(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } pub fn semi_token(&self) -> Option { support::token(&self.syntax) } @@ -427,8 +427,8 @@ impl ast::AttrsOwner for TypeAliasDef {} impl ast::DocCommentsOwner for TypeAliasDef {} impl ast::TypeBoundsOwner for TypeAliasDef {} impl TypeAliasDef { - pub fn default_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn type_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn default_token(&self) -> Option { support::token2(&self.syntax, DEFAULT_KW) } + pub fn type_token(&self) -> Option { support::token2(&self.syntax, TYPE_KW) } pub fn eq_token(&self) -> Option { support::token(&self.syntax) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } pub fn semi_token(&self) -> Option { support::token(&self.syntax) } @@ -451,12 +451,12 @@ impl AstNode for ImplDef { impl ast::TypeParamsOwner for ImplDef {} impl ast::AttrsOwner for ImplDef {} impl ImplDef { - pub fn default_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn const_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn unsafe_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn impl_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn default_token(&self) -> Option { support::token2(&self.syntax, DEFAULT_KW) } + pub fn const_token(&self) -> Option { support::token2(&self.syntax, CONST_KW) } + pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, UNSAFE_KW) } + pub fn impl_token(&self) -> Option { support::token2(&self.syntax, IMPL_KW) } pub fn excl_token(&self) -> Option { support::token(&self.syntax) } - pub fn for_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn for_token(&self) -> Option { support::token2(&self.syntax, FOR_KW) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -552,8 +552,8 @@ impl AstNode for PointerType { } impl PointerType { pub fn star_token(&self) -> Option { support::token(&self.syntax) } - pub fn const_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn mut_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn const_token(&self) -> Option { support::token2(&self.syntax, CONST_KW) } + pub fn mut_token(&self) -> Option { support::token2(&self.syntax, MUT_KW) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -616,7 +616,7 @@ impl AstNode for ReferenceType { impl ReferenceType { pub fn amp_token(&self) -> Option { support::token(&self.syntax) } pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } - pub fn mut_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn mut_token(&self) -> Option { support::token2(&self.syntax, MUT_KW) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -654,8 +654,8 @@ impl AstNode for FnPointerType { } impl FnPointerType { pub fn abi(&self) -> Option { support::child(&self.syntax) } - pub fn unsafe_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn fn_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, UNSAFE_KW) } + pub fn fn_token(&self) -> Option { support::token2(&self.syntax, FN_KW) } pub fn param_list(&self) -> Option { support::child(&self.syntax) } pub fn ret_type(&self) -> Option { support::child(&self.syntax) } } @@ -675,7 +675,7 @@ impl AstNode for ForType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ForType { - pub fn for_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn for_token(&self) -> Option { support::token2(&self.syntax, FOR_KW) } pub fn type_param_list(&self) -> Option { support::child(&self.syntax) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } @@ -696,7 +696,7 @@ impl AstNode for ImplTraitType { } impl ast::TypeBoundsOwner for ImplTraitType {} impl ImplTraitType { - pub fn impl_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn impl_token(&self) -> Option { support::token2(&self.syntax, IMPL_KW) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DynTraitType { @@ -715,7 +715,7 @@ impl AstNode for DynTraitType { } impl ast::TypeBoundsOwner for DynTraitType {} impl DynTraitType { - pub fn dyn_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn dyn_token(&self) -> Option { support::token2(&self.syntax, DYN_KW) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TupleExpr { @@ -816,9 +816,9 @@ impl AstNode for LambdaExpr { } impl ast::AttrsOwner for LambdaExpr {} impl LambdaExpr { - pub fn static_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn async_kw_token(&self) -> Option { support::token(&self.syntax) } - pub fn move_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn static_token(&self) -> Option { support::token2(&self.syntax, STATIC_KW) } + pub fn async_token(&self) -> Option { support::token2(&self.syntax, ASYNC_KW) } + pub fn move_token(&self) -> Option { support::token2(&self.syntax, MOVE_KW) } pub fn param_list(&self) -> Option { support::child(&self.syntax) } pub fn ret_type(&self) -> Option { support::child(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } @@ -840,7 +840,7 @@ impl AstNode for IfExpr { } impl ast::AttrsOwner for IfExpr {} impl IfExpr { - pub fn if_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn if_token(&self) -> Option { support::token2(&self.syntax, IF_KW) } pub fn condition(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -861,7 +861,7 @@ impl AstNode for LoopExpr { impl ast::AttrsOwner for LoopExpr {} impl ast::LoopBodyOwner for LoopExpr {} impl LoopExpr { - pub fn loop_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn loop_token(&self) -> Option { support::token2(&self.syntax, LOOP_KW) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TryBlockExpr { @@ -880,7 +880,7 @@ impl AstNode for TryBlockExpr { } impl ast::AttrsOwner for TryBlockExpr {} impl TryBlockExpr { - pub fn try_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn try_token(&self) -> Option { support::token2(&self.syntax, TRY_KW) } pub fn body(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -901,9 +901,9 @@ impl AstNode for ForExpr { impl ast::AttrsOwner for ForExpr {} impl ast::LoopBodyOwner for ForExpr {} impl ForExpr { - pub fn for_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn for_token(&self) -> Option { support::token2(&self.syntax, FOR_KW) } pub fn pat(&self) -> Option { support::child(&self.syntax) } - pub fn in_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn in_token(&self) -> Option { support::token2(&self.syntax, IN_KW) } pub fn iterable(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -924,7 +924,7 @@ impl AstNode for WhileExpr { impl ast::AttrsOwner for WhileExpr {} impl ast::LoopBodyOwner for WhileExpr {} impl WhileExpr { - pub fn while_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn while_token(&self) -> Option { support::token2(&self.syntax, WHILE_KW) } pub fn condition(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -944,7 +944,9 @@ impl AstNode for ContinueExpr { } impl ast::AttrsOwner for ContinueExpr {} impl ContinueExpr { - pub fn continue_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn continue_token(&self) -> Option { + support::token2(&self.syntax, CONTINUE_KW) + } pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -964,7 +966,7 @@ impl AstNode for BreakExpr { } impl ast::AttrsOwner for BreakExpr {} impl BreakExpr { - pub fn break_kw_token(&self) -> Option { support::token(&self.syntax) } + pub fn break_token(&self) -> Option { support::token2(&self.syntax, BREAK_KW) } pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } pub fn expr(&self) -> Option { support::child(&self.syntax) } } @@ -1004,7 +1006,7 @@ impl AstNode for BlockExpr { impl ast::AttrsOwner for BlockExpr {} impl BlockExpr { pub fn label(&self) -> Option