diff options
Diffstat (limited to 'crates/ra_assists/src/replace_if_let_with_match.rs')
-rw-r--r-- | crates/ra_assists/src/replace_if_let_with_match.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/crates/ra_assists/src/replace_if_let_with_match.rs b/crates/ra_assists/src/replace_if_let_with_match.rs index 683f0d119..a22ec5584 100644 --- a/crates/ra_assists/src/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/replace_if_let_with_match.rs | |||
@@ -17,6 +17,7 @@ pub(crate) fn replace_if_let_with_match(ctx: AssistCtx<impl HirDatabase>) -> Opt | |||
17 | 17 | ||
18 | ctx.build("replace with match", |edit| { | 18 | ctx.build("replace with match", |edit| { |
19 | let match_expr = build_match_expr(expr, pat, then_block, else_block); | 19 | let match_expr = build_match_expr(expr, pat, then_block, else_block); |
20 | edit.target(if_expr.syntax().range()); | ||
20 | edit.replace_node_and_indent(if_expr.syntax(), match_expr); | 21 | edit.replace_node_and_indent(if_expr.syntax(), match_expr); |
21 | edit.set_cursor(if_expr.syntax().range().start()) | 22 | edit.set_cursor(if_expr.syntax().range().start()) |
22 | }) | 23 | }) |
@@ -46,7 +47,7 @@ fn format_arm(block: &ast::Block) -> String { | |||
46 | #[cfg(test)] | 47 | #[cfg(test)] |
47 | mod tests { | 48 | mod tests { |
48 | use super::*; | 49 | use super::*; |
49 | use crate::helpers::check_assist; | 50 | use crate::helpers::{check_assist, check_assist_target}; |
50 | 51 | ||
51 | #[test] | 52 | #[test] |
52 | fn test_replace_if_let_with_match_unwraps_simple_expressions() { | 53 | fn test_replace_if_let_with_match_unwraps_simple_expressions() { |
@@ -73,4 +74,26 @@ impl VariantData { | |||
73 | } ", | 74 | } ", |
74 | ) | 75 | ) |
75 | } | 76 | } |
77 | |||
78 | #[test] | ||
79 | fn replace_if_let_with_match_target() { | ||
80 | check_assist_target( | ||
81 | replace_if_let_with_match, | ||
82 | " | ||
83 | impl VariantData { | ||
84 | pub fn is_struct(&self) -> bool { | ||
85 | if <|>let VariantData::Struct(..) = *self { | ||
86 | true | ||
87 | } else { | ||
88 | false | ||
89 | } | ||
90 | } | ||
91 | } ", | ||
92 | "if let VariantData::Struct(..) = *self { | ||
93 | true | ||
94 | } else { | ||
95 | false | ||
96 | }", | ||
97 | ); | ||
98 | } | ||
76 | } | 99 | } |