From e618d129030b10ddd55d76c3e451799c7dba3f8d Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 10 Jan 2021 16:40:52 +0100 Subject: Replace SyntaxKind usage with T! macro where applicable --- crates/completion/src/completions/attribute.rs | 7 +++---- crates/completion/src/completions/trait_impl.rs | 6 +++--- crates/completion/src/patterns.rs | 10 +++++----- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'crates/completion') diff --git a/crates/completion/src/completions/attribute.rs b/crates/completion/src/completions/attribute.rs index a52ca107e..e5522980d 100644 --- a/crates/completion/src/completions/attribute.rs +++ b/crates/completion/src/completions/attribute.rs @@ -5,7 +5,7 @@ use itertools::Itertools; use rustc_hash::FxHashSet; -use syntax::{ast, AstNode, SyntaxKind}; +use syntax::{ast, AstNode, T}; use crate::{ context::CompletionContext, @@ -205,8 +205,7 @@ fn complete_lint( fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Result, ()> { match (derive_input.left_delimiter_token(), derive_input.right_delimiter_token()) { (Some(left_paren), Some(right_paren)) - if left_paren.kind() == SyntaxKind::L_PAREN - && right_paren.kind() == SyntaxKind::R_PAREN => + if left_paren.kind() == T!['('] && right_paren.kind() == T![')'] => { let mut input_derives = FxHashSet::default(); let mut current_derive = String::new(); @@ -218,7 +217,7 @@ fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Result Option<(ImplCompletionKind, Synt // `impl .. { const $0 }` // ERROR 0 // CONST_KW <- * - SyntaxKind::CONST_KW => 0, + T![const] => 0, // `impl .. { fn/type $0 }` // FN/TYPE_ALIAS 0 // FN_KW <- * - SyntaxKind::FN_KW | SyntaxKind::TYPE_KW => 0, + T![fn] | T![type] => 0, // `impl .. { fn/type/const foo$0 }` // FN/TYPE_ALIAS/CONST 1 // NAME 0 @@ -121,7 +121,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Synt let impl_def = ast::Impl::cast(impl_item.parent()?.parent()?)?; let kind = match impl_item.kind() { // `impl ... { const $0 fn/type/const }` - _ if token.kind() == SyntaxKind::CONST_KW => ImplCompletionKind::Const, + _ if token.kind() == T![const] => ImplCompletionKind::Const, SyntaxKind::CONST | SyntaxKind::ERROR => ImplCompletionKind::Const, SyntaxKind::TYPE_ALIAS => ImplCompletionKind::TypeAlias, SyntaxKind::FN => ImplCompletionKind::Fn, diff --git a/crates/completion/src/patterns.rs b/crates/completion/src/patterns.rs index f148b9402..f3ce91dd1 100644 --- a/crates/completion/src/patterns.rs +++ b/crates/completion/src/patterns.rs @@ -5,7 +5,7 @@ use syntax::{ ast::{self, LoopBodyOwner}, match_ast, AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind::*, - SyntaxNode, SyntaxToken, + SyntaxNode, SyntaxToken, T, }; #[cfg(test)] @@ -119,7 +119,7 @@ pub(crate) fn unsafe_is_prev(element: SyntaxElement) -> bool { element .into_token() .and_then(|it| previous_non_trivia_token(it)) - .filter(|it| it.kind() == UNSAFE_KW) + .filter(|it| it.kind() == T![unsafe]) .is_some() } #[test] @@ -131,7 +131,7 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool { element .into_token() .and_then(|it| previous_non_trivia_token(it)) - .filter(|it| it.kind() == IF_KW) + .filter(|it| it.kind() == T![if]) .is_some() } @@ -139,7 +139,7 @@ pub(crate) fn fn_is_prev(element: SyntaxElement) -> bool { element .into_token() .and_then(|it| previous_non_trivia_token(it)) - .filter(|it| it.kind() == FN_KW) + .filter(|it| it.kind() == T![fn]) .is_some() } #[test] @@ -154,7 +154,7 @@ pub(crate) fn for_is_prev2(element: SyntaxElement) -> bool { .into_token() .and_then(|it| previous_non_trivia_token(it)) .and_then(|it| previous_non_trivia_token(it)) - .filter(|it| it.kind() == FOR_KW) + .filter(|it| it.kind() == T![for]) .is_some() } #[test] -- cgit v1.2.3