diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-20 18:16:35 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-20 18:16:35 +0000 |
commit | 5aec3e4a7b21855fb4688e466d4f5bee9feabe2e (patch) | |
tree | 41a304a33955dd12d1f0ec127a80551367c8ffa0 /crates/ra_assists/src/assists | |
parent | 7a5fd1f3f3c4a8f64407f9bd08a3d5e7f79417e0 (diff) | |
parent | bcb2ea912bf96f38505c67a0b6896c6a5ac278ed (diff) |
Merge #2329
2329: fix 2190; add test for "replace if let with match" r=matklad a=fkohlgrueber
Fixes #2190.
Check that the expression doesn't contain newlines only for "replace if let with match". For "join lines", enclosing blocks for multiline expressions should be removed.
Co-authored-by: Felix Kohlgrüber <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r-- | crates/ra_assists/src/assists/replace_if_let_with_match.rs | 32 |
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 | ||
67 | fn format_arm(block: &ast::BlockExpr) -> String { | 67 | fn 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 | " | ||
110 | fn foo() { | ||
111 | if <|>let VariantData::Struct(..) = a { | ||
112 | bar( | ||
113 | 123 | ||
114 | ) | ||
115 | } else { | ||
116 | false | ||
117 | } | ||
118 | } ", | ||
119 | " | ||
120 | fn 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, |