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 +---- 3 files changed, 5 insertions(+), 17 deletions(-) (limited to 'crates/ra_assists') 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)] -- cgit v1.2.3