Skip to content

Commit 45dd90b

Browse files
committed
Cleanup
1 parent c9e1aab commit 45dd90b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

crates/ra_assists/src/assists/merge_match_arms.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::{Assist, AssistCtx, AssistId, TextRange, TextUnit};
21
use hir::db::HirDatabase;
3-
use ra_syntax::ast::{AstNode, MatchArm};
2+
use ra_syntax::ast::{self, AstNode};
3+
4+
use crate::{Assist, AssistCtx, AssistId, TextRange, TextUnit};
45

56
// Assist: merge_match_arms
67
//
@@ -27,12 +28,12 @@ use ra_syntax::ast::{AstNode, MatchArm};
2728
// }
2829
// ```
2930
pub(crate) fn merge_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
30-
let current_arm = ctx.find_node_at_offset::<MatchArm>()?;
31+
let current_arm = ctx.find_node_at_offset::<ast::MatchArm>()?;
3132

3233
// We check if the following match arm matches this one. We could, but don't,
3334
// compare to the previous match arm as well.
3435
let next = current_arm.syntax().next_sibling();
35-
let next_arm = MatchArm::cast(next?)?;
36+
let next_arm = ast::MatchArm::cast(next?)?;
3637

3738
// Don't try to handle arms with guards for now - can add support for this later
3839
if current_arm.guard().is_some() || next_arm.guard().is_some() {
@@ -53,13 +54,6 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assis
5354
let cursor_to_end = current_arm.syntax().text_range().end() - ctx.frange.range.start();
5455

5556
ctx.add_assist(AssistId("merge_match_arms"), "Merge match arms", |edit| {
56-
fn contains_placeholder(a: &MatchArm) -> bool {
57-
a.pats().any(|x| match x {
58-
ra_syntax::ast::Pat::PlaceholderPat(..) => true,
59-
_ => false,
60-
})
61-
}
62-
6357
let pats = if contains_placeholder(&current_arm) || contains_placeholder(&next_arm) {
6458
"_".into()
6559
} else {
@@ -83,6 +77,13 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assis
8377
})
8478
}
8579

80+
fn contains_placeholder(a: &ast::MatchArm) -> bool {
81+
a.pats().any(|x| match x {
82+
ra_syntax::ast::Pat::PlaceholderPat(..) => true,
83+
_ => false,
84+
})
85+
}
86+
8687
#[cfg(test)]
8788
mod tests {
8889
use super::merge_match_arms;

0 commit comments

Comments
 (0)