diff options
author | Veetaha <[email protected]> | 2020-06-28 02:02:03 +0100 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-06-28 02:03:59 +0100 |
commit | e75e2ae5b6b6b1364368ceb3d4081b6508b2f001 (patch) | |
tree | e88a9920a908bfdf66c156ab582ce90d77d55c2f /crates/ra_assists | |
parent | 513924a7e01ef81a03869249c902daf148439736 (diff) |
Simlify with matches!()
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/handlers/change_visibility.rs | 11 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/fix_visibility.rs | 6 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/merge_match_arms.rs | 5 |
3 files changed, 5 insertions, 17 deletions
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 | |||
30 | } | 30 | } |
31 | 31 | ||
32 | fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 32 | fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
33 | let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { | 33 | let item_keyword = ctx.token_at_offset().find(|leaf| { |
34 | T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, | 34 | matches!(leaf.kind(), T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait]) |
35 | _ => false, | ||
36 | }); | 35 | }); |
37 | 36 | ||
38 | let (offset, target) = if let Some(keyword) = item_keyword { | 37 | let (offset, target) = if let Some(keyword) = item_keyword { |
@@ -73,11 +72,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | |||
73 | 72 | ||
74 | fn vis_offset(node: &SyntaxNode) -> TextSize { | 73 | fn vis_offset(node: &SyntaxNode) -> TextSize { |
75 | node.children_with_tokens() | 74 | node.children_with_tokens() |
76 | .skip_while(|it| match it.kind() { | 75 | .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) |
77 | WHITESPACE | COMMENT | ATTR => true, | ||
78 | _ => false, | ||
79 | }) | ||
80 | .next() | ||
81 | .map(|it| it.text_range().start()) | 76 | .map(|it| it.text_range().start()) |
82 | .unwrap_or_else(|| node.text_range().start()) | 77 | .unwrap_or_else(|| node.text_range().start()) |
83 | } | 78 | } |
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( | |||
179 | 179 | ||
180 | fn vis_offset(node: &SyntaxNode) -> TextSize { | 180 | fn vis_offset(node: &SyntaxNode) -> TextSize { |
181 | node.children_with_tokens() | 181 | node.children_with_tokens() |
182 | .skip_while(|it| match it.kind() { | 182 | .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) |
183 | WHITESPACE | COMMENT | ATTR => true, | ||
184 | _ => false, | ||
185 | }) | ||
186 | .next() | ||
187 | .map(|it| it.text_range().start()) | 183 | .map(|it| it.text_range().start()) |
188 | .unwrap_or_else(|| node.text_range().start()) | 184 | .unwrap_or_else(|| node.text_range().start()) |
189 | } | 185 | } |
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 | |||
81 | } | 81 | } |
82 | 82 | ||
83 | fn contains_placeholder(a: &ast::MatchArm) -> bool { | 83 | fn contains_placeholder(a: &ast::MatchArm) -> bool { |
84 | match a.pat() { | 84 | matches!(a.pat(), Some(ra_syntax::ast::Pat::PlaceholderPat(..))) |
85 | Some(ra_syntax::ast::Pat::PlaceholderPat(..)) => true, | ||
86 | _ => false, | ||
87 | } | ||
88 | } | 85 | } |
89 | 86 | ||
90 | #[cfg(test)] | 87 | #[cfg(test)] |