@@ -135,7 +135,15 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
135
135
136
136
match & then_block. tail_expr ( ) {
137
137
Some ( then_expr) if then_only_expr => {
138
- edit. replace ( replace_node. text_range ( ) , then_expr. syntax ( ) . text ( ) )
138
+ edit. replace ( replace_node. text_range ( ) , then_expr. syntax ( ) . text ( ) ) ;
139
+ // Insert comma for expression if there isn't one
140
+ match match_arm. syntax ( ) . last_child_or_token ( ) {
141
+ Some ( NodeOrToken :: Token ( t) ) if t. kind ( ) == COMMA => { }
142
+ _ => {
143
+ cov_mark:: hit!( move_guard_if_add_comma) ;
144
+ edit. insert ( match_arm. syntax ( ) . text_range ( ) . end ( ) , "," ) ;
145
+ }
146
+ }
139
147
}
140
148
_ if replace_node != * if_expr. syntax ( ) => {
141
149
// Dedent because if_expr is in a BlockExpr
@@ -150,13 +158,6 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
150
158
// If with only an else branch
151
159
if let Some ( ElseBranch :: Block ( else_block) ) = if_expr. else_branch ( ) {
152
160
let then_arm_end = match_arm. syntax ( ) . text_range ( ) . end ( ) ;
153
- if then_block. tail_expr ( ) . is_some ( ) && then_only_expr {
154
- // Insert comma for expression if there isn't one
155
- match match_arm. syntax ( ) . last_child_or_token ( ) {
156
- Some ( NodeOrToken :: Token ( t) ) if t. kind ( ) == COMMA => { }
157
- _ => edit. insert ( then_arm_end, "," ) ,
158
- }
159
- }
160
161
let else_only_expr = else_block. statements ( ) . next ( ) . is_none ( ) ;
161
162
let indent_level = match_arm. indent_level ( ) ;
162
163
let spaces = " " . repeat ( indent_level. 0 as _ ) ;
@@ -318,6 +319,34 @@ fn main() {
318
319
) ;
319
320
}
320
321
322
+ #[ test]
323
+ fn move_arm_cond_in_block_to_match_guard_add_comma_works ( ) {
324
+ cov_mark:: check!( move_guard_if_add_comma) ;
325
+ check_assist (
326
+ move_arm_cond_to_match_guard,
327
+ r#"
328
+ fn main() {
329
+ match 92 {
330
+ x => {
331
+ $0if x > 10 {
332
+ false
333
+ }
334
+ }
335
+ _ => true
336
+ }
337
+ }
338
+ "# ,
339
+ r#"
340
+ fn main() {
341
+ match 92 {
342
+ x if x > 10 => false,
343
+ _ => true
344
+ }
345
+ }
346
+ "# ,
347
+ ) ;
348
+ }
349
+
321
350
#[ test]
322
351
fn move_arm_cond_to_match_guard_if_let_not_works ( ) {
323
352
check_assist_not_applicable (
0 commit comments