aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/assists/replace_if_let_with_match.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/crates/ra_assists/src/assists/replace_if_let_with_match.rs b/crates/ra_assists/src/assists/replace_if_let_with_match.rs
index dff84d865..3272801ff 100644
--- a/crates/ra_assists/src/assists/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/assists/replace_if_let_with_match.rs
@@ -66,8 +66,8 @@ fn build_match_expr(
66 66
67fn format_arm(block: &ast::BlockExpr) -> String { 67fn format_arm(block: &ast::BlockExpr) -> String {
68 match extract_trivial_expression(block) { 68 match extract_trivial_expression(block) {
69 None => block.syntax().text().to_string(), 69 Some(e) if !e.syntax().text().contains_char('\n') => format!("{},", e.syntax().text()),
70 Some(e) => format!("{},", e.syntax().text()), 70 _ => block.syntax().text().to_string(),
71 } 71 }
72} 72}
73 73
@@ -103,6 +103,34 @@ impl VariantData {
103 } 103 }
104 104
105 #[test] 105 #[test]
106 fn test_replace_if_let_with_match_doesnt_unwrap_multiline_expressions() {
107 check_assist(
108 replace_if_let_with_match,
109 "
110fn foo() {
111 if <|>let VariantData::Struct(..) = a {
112 bar(
113 123
114 )
115 } else {
116 false
117 }
118} ",
119 "
120fn foo() {
121 <|>match a {
122 VariantData::Struct(..) => {
123 bar(
124 123
125 )
126 }
127 _ => false,
128 }
129} ",
130 )
131 }
132
133 #[test]
106 fn replace_if_let_with_match_target() { 134 fn replace_if_let_with_match_target() {
107 check_assist_target( 135 check_assist_target(
108 replace_if_let_with_match, 136 replace_if_let_with_match,