From 8c8d0bb34f5495e0f260b5aaf3685ecb98406f32 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 9 Feb 2020 18:57:01 +0000 Subject: Add or- and parenthesized-patterns --- crates/ra_assists/src/handlers/fill_match_arms.rs | 6 +++--- crates/ra_assists/src/handlers/merge_match_arms.rs | 8 ++++---- crates/ra_assists/src/handlers/move_guard.rs | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 0908fc246..ae2437ed3 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -75,10 +75,10 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option { } fn is_trivial(arm: &ast::MatchArm) -> bool { - arm.pats().any(|pat| match pat { - ast::Pat::PlaceholderPat(..) => true, + match arm.pat() { + Some(ast::Pat::PlaceholderPat(..)) => true, _ => false, - }) + } } fn resolve_enum_def( diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs index 670614dd8..b2a194cb5 100644 --- a/crates/ra_assists/src/handlers/merge_match_arms.rs +++ b/crates/ra_assists/src/handlers/merge_match_arms.rs @@ -75,7 +75,7 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option { } else { arms_to_merge .iter() - .flat_map(ast::MatchArm::pats) + .filter_map(ast::MatchArm::pat) .map(|x| x.syntax().to_string()) .collect::>() .join(" | ") @@ -96,10 +96,10 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option { } fn contains_placeholder(a: &ast::MatchArm) -> bool { - a.pats().any(|x| match x { - ra_syntax::ast::Pat::PlaceholderPat(..) => true, + match a.pat() { + Some(ra_syntax::ast::Pat::PlaceholderPat(..)) => true, _ => false, - }) + } } fn next_arm(arm: &ast::MatchArm) -> Option { diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs index 2b91ce7c4..a61a2ba3e 100644 --- a/crates/ra_assists/src/handlers/move_guard.rs +++ b/crates/ra_assists/src/handlers/move_guard.rs @@ -90,7 +90,7 @@ pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option { // ``` pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option { let match_arm: MatchArm = ctx.find_node_at_offset::()?; - let last_match_pat = match_arm.pats().last()?; + let match_pat = match_arm.pat()?; let arm_body = match_arm.expr()?; let if_expr: IfExpr = IfExpr::cast(arm_body.syntax().clone())?; @@ -122,8 +122,8 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option { _ => edit.replace(if_expr.syntax().text_range(), then_block.syntax().text()), } - edit.insert(last_match_pat.syntax().text_range().end(), buf); - edit.set_cursor(last_match_pat.syntax().text_range().end() + TextUnit::from(1)); + edit.insert(match_pat.syntax().text_range().end(), buf); + edit.set_cursor(match_pat.syntax().text_range().end() + TextUnit::from(1)); }, ) } -- cgit v1.2.3