From e75e2ae5b6b6b1364368ceb3d4081b6508b2f001 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 28 Jun 2020 04:02:03 +0300 Subject: Simlify with matches!() --- crates/ra_assists/src/handlers/change_visibility.rs | 11 +++-------- crates/ra_assists/src/handlers/fix_visibility.rs | 6 +----- crates/ra_assists/src/handlers/merge_match_arms.rs | 5 +---- crates/ra_hir_def/src/nameres.rs | 5 +---- crates/ra_hir_ty/src/infer/expr.rs | 6 +----- crates/ra_hir_ty/src/lib.rs | 10 ++-------- crates/ra_ide/src/inlay_hints.rs | 6 ++---- crates/ra_ide/src/join_lines.rs | 5 +---- crates/ra_ide_db/src/symbol_index.rs | 5 +---- crates/ra_mbe/src/parser.rs | 5 +---- crates/ra_parser/src/grammar.rs | 5 +---- crates/ra_parser/src/grammar/paths.rs | 5 +---- crates/ra_parser/src/grammar/type_params.rs | 5 +---- crates/ra_parser/src/syntax_kind.rs | 5 +---- crates/ra_syntax/src/ast/expr_extensions.rs | 5 +---- crates/ra_syntax/src/ast/extensions.rs | 16 ++++++++-------- crates/ra_syntax/src/parsing/reparsing.rs | 5 +---- crates/ra_tt/src/buffer.rs | 5 +---- crates/rust-analyzer/src/cli.rs | 10 ++-------- crates/rust-analyzer/src/cli/analysis_bench.rs | 5 +---- 20 files changed, 32 insertions(+), 98 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index c21d75be0..18e92e393 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs @@ -30,9 +30,8 @@ pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Optio } fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { - let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { - T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, - _ => false, + let item_keyword = ctx.token_at_offset().find(|leaf| { + matches!(leaf.kind(), T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait]) }); let (offset, target) = if let Some(keyword) = item_keyword { @@ -73,11 +72,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn vis_offset(node: &SyntaxNode) -> TextSize { node.children_with_tokens() - .skip_while(|it| match it.kind() { - WHITESPACE | COMMENT | ATTR => true, - _ => false, - }) - .next() + .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) .map(|it| it.text_range().start()) .unwrap_or_else(|| node.text_range().start()) } diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs index 54601d1f3..02763c5b9 100644 --- a/crates/ra_assists/src/handlers/fix_visibility.rs +++ b/crates/ra_assists/src/handlers/fix_visibility.rs @@ -179,11 +179,7 @@ fn target_data_for_def( fn vis_offset(node: &SyntaxNode) -> TextSize { node.children_with_tokens() - .skip_while(|it| match it.kind() { - WHITESPACE | COMMENT | ATTR => true, - _ => false, - }) - .next() + .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) .map(|it| it.text_range().start()) .unwrap_or_else(|| node.text_range().start()) } diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs index ca04ec671..53c2c130f 100644 --- a/crates/ra_assists/src/handlers/merge_match_arms.rs +++ b/crates/ra_assists/src/handlers/merge_match_arms.rs @@ -81,10 +81,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option } fn contains_placeholder(a: &ast::MatchArm) -> bool { - match a.pat() { - Some(ra_syntax::ast::Pat::PlaceholderPat(..)) => true, - _ => false, - } + matches!(a.pat(), Some(ra_syntax::ast::Pat::PlaceholderPat(..))) } #[cfg(test)] diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index b279bdeef..0c18df1a9 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -137,10 +137,7 @@ impl ModuleOrigin { } pub fn is_inline(&self) -> bool { - match self { - ModuleOrigin::Inline { .. } => true, - ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false, - } + matches!(self, ModuleOrigin::Inline { .. }) } /// Returns a node which defines this module. diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 61af5f064..22884522a 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -785,11 +785,7 @@ impl<'a> InferenceContext<'a> { for &check_closures in &[false, true] { let param_iter = param_tys.iter().cloned().chain(repeat(Ty::Unknown)); for (&arg, param_ty) in args.iter().zip(param_iter) { - let is_closure = match &self.body[arg] { - Expr::Lambda { .. } => true, - _ => false, - }; - + let is_closure = matches!(&self.body[arg], Expr::Lambda { .. }); if is_closure != check_closures { continue; } diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 414158139..c9513b752 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -620,17 +620,11 @@ pub enum GenericPredicate { impl GenericPredicate { pub fn is_error(&self) -> bool { - match self { - GenericPredicate::Error => true, - _ => false, - } + matches!(self, GenericPredicate::Error) } pub fn is_implemented(&self) -> bool { - match self { - GenericPredicate::Implemented(_) => true, - _ => false, - } + matches!(self, GenericPredicate::Implemented(_)) } pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option { diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 3fd08b1e8..886346991 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -312,10 +312,8 @@ fn get_string_representation(expr: &ast::Expr) -> Option { } fn is_obvious_param(param_name: &str) -> bool { - let is_obvious_param_name = match param_name { - "predicate" | "value" | "pat" | "rhs" | "other" => true, - _ => false, - }; + let is_obvious_param_name = + matches!(param_name, "predicate" | "value" | "pat" | "rhs" | "other"); param_name.len() == 1 || is_obvious_param_name } diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs index 5036c1fb0..6907c09e8 100644 --- a/crates/ra_ide/src/join_lines.rs +++ b/crates/ra_ide/src/join_lines.rs @@ -165,10 +165,7 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Opti } fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { - match (left, right) { - (T![,], T![')']) | (T![,], T![']']) => true, - _ => false, - } + matches!((left, right), (T![,], T![')']) | (T![,], T![']'])) } #[cfg(test)] diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs index 6929055b2..5a09e7d1d 100644 --- a/crates/ra_ide_db/src/symbol_index.rs +++ b/crates/ra_ide_db/src/symbol_index.rs @@ -346,10 +346,7 @@ impl Query { } fn is_type(kind: SyntaxKind) -> bool { - match kind { - STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => true, - _ => false, - } + matches!(kind, STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF) } /// The actual data that is stored in the index. It should be as compact as diff --git a/crates/ra_mbe/src/parser.rs b/crates/ra_mbe/src/parser.rs index 034150432..1e5dafbdf 100644 --- a/crates/ra_mbe/src/parser.rs +++ b/crates/ra_mbe/src/parser.rs @@ -137,10 +137,7 @@ fn eat_fragment_kind<'a>( } fn is_boolean_literal(lit: &tt::Literal) -> bool { - match lit.text.as_str() { - "true" | "false" => true, - _ => false, - } + matches!(lit.text.as_str(), "true" | "false") } fn parse_repeat(src: &mut TtIter) -> Result<(Option, RepeatKind), ExpandError> { diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 293baecf6..caedeead0 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -73,10 +73,7 @@ pub(crate) mod fragments { // Parse a meta item , which excluded [], e.g : #[ MetaItem ] pub(crate) fn meta_item(p: &mut Parser) { fn is_delimiter(p: &mut Parser) -> bool { - match p.current() { - T!['{'] | T!['('] | T!['['] => true, - _ => false, - } + matches!(p.current(), T!['{'] | T!['('] | T!['[']) } if is_delimiter(p) { diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index fd51189d5..b503af1dc 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs @@ -41,10 +41,7 @@ fn path(p: &mut Parser, mode: Mode) { path_segment(p, mode, true); let mut qual = path.complete(p, PATH); loop { - let use_tree = match p.nth(2) { - T![*] | T!['{'] => true, - _ => false, - }; + let use_tree = matches!(p.nth(2), T![*] | T!['{']); if p.at(T![::]) && !use_tree { let path = qual.precede(p); p.bump(T![::]); diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs index 325d566ad..d1330d4b9 100644 --- a/crates/ra_parser/src/grammar/type_params.rs +++ b/crates/ra_parser/src/grammar/type_params.rs @@ -169,10 +169,7 @@ fn is_where_predicate(p: &mut Parser) -> bool { } fn is_where_clause_end(p: &mut Parser) -> bool { - match p.current() { - T!['{'] | T![;] | T![=] => true, - _ => false, - } + matches!(p.current(), T!['{'] | T![;] | T![=]) } fn where_predicate(p: &mut Parser) { diff --git a/crates/ra_parser/src/syntax_kind.rs b/crates/ra_parser/src/syntax_kind.rs index 8d6bd057b..63204436c 100644 --- a/crates/ra_parser/src/syntax_kind.rs +++ b/crates/ra_parser/src/syntax_kind.rs @@ -20,9 +20,6 @@ impl From for u16 { impl SyntaxKind { pub fn is_trivia(self) -> bool { - match self { - SyntaxKind::WHITESPACE | SyntaxKind::COMMENT => true, - _ => false, - } + matches!(self, SyntaxKind::WHITESPACE | SyntaxKind::COMMENT) } } diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 7771d6759..db5438d68 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -399,10 +399,7 @@ impl ast::BlockExpr { Some(it) => it, None => return true, }; - match parent.kind() { - FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR => false, - _ => true, - } + !matches!(parent.kind(), FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR) } } diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 98c38d009..662c6f73e 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -459,16 +459,16 @@ impl ast::RangePat { impl ast::TokenTree { pub fn left_delimiter_token(&self) -> Option { - self.syntax().first_child_or_token()?.into_token().filter(|it| match it.kind() { - T!['{'] | T!['('] | T!['['] => true, - _ => false, - }) + self.syntax() + .first_child_or_token()? + .into_token() + .filter(|it| matches!(it.kind(), T!['{'] | T!['('] | T!['['])) } pub fn right_delimiter_token(&self) -> Option { - self.syntax().last_child_or_token()?.into_token().filter(|it| match it.kind() { - T!['}'] | T![')'] | T![']'] => true, - _ => false, - }) + self.syntax() + .last_child_or_token()? + .into_token() + .filter(|it| matches!(it.kind(), T!['}'] | T![')'] | T![']'])) } } diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index edbc190f8..ed5a42ea3 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -120,10 +120,7 @@ fn get_text_after_edit(element: SyntaxElement, edit: &Indel) -> String { } fn is_contextual_kw(text: &str) -> bool { - match text { - "auto" | "default" | "union" => true, - _ => false, - } + matches!(text, "auto" | "default" | "union") } fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(SyntaxNode, Reparser)> { diff --git a/crates/ra_tt/src/buffer.rs b/crates/ra_tt/src/buffer.rs index 5967f44cd..02c771f70 100644 --- a/crates/ra_tt/src/buffer.rs +++ b/crates/ra_tt/src/buffer.rs @@ -105,10 +105,7 @@ impl<'a> Eq for Cursor<'a> {} impl<'a> Cursor<'a> { /// Check whether it is eof pub fn eof(self) -> bool { - match self.buffer.entry(&self.ptr) { - None | Some(Entry::End(None)) => true, - _ => false, - } + matches!(self.buffer.entry(&self.ptr), None | Some(Entry::End(None))) } /// If the cursor is pointing at the end of a subtree, returns diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs index 39ce77900..c5faec83a 100644 --- a/crates/rust-analyzer/src/cli.rs +++ b/crates/rust-analyzer/src/cli.rs @@ -28,16 +28,10 @@ pub enum Verbosity { impl Verbosity { pub fn is_verbose(self) -> bool { - match self { - Verbosity::Verbose | Verbosity::Spammy => true, - _ => false, - } + matches!(self, Verbosity::Verbose | Verbosity::Spammy) } pub fn is_spammy(self) -> bool { - match self { - Verbosity::Spammy => true, - _ => false, - } + matches!(self, Verbosity::Spammy) } } diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index 4fe99ff68..930375d3e 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs @@ -78,10 +78,7 @@ pub fn analysis_bench( } } BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => { - let is_completion = match what { - BenchWhat::Complete(..) => true, - _ => false, - }; + let is_completion = matches!(what, BenchWhat::Complete(..)); let offset = host .analysis() -- cgit v1.2.3