diff options
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/assists/early_return.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/assists/early_return.rs index 3169be2b9..8f30dc586 100644 --- a/crates/ra_assists/src/assists/early_return.rs +++ b/crates/ra_assists/src/assists/early_return.rs | |||
@@ -10,6 +10,7 @@ use ra_syntax::{ | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | assist_ctx::{Assist, AssistCtx}, | 12 | assist_ctx::{Assist, AssistCtx}, |
13 | assists::invert_if::invert_boolean_expression, | ||
13 | AssistId, | 14 | AssistId, |
14 | }; | 15 | }; |
15 | 16 | ||
@@ -99,9 +100,13 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> { | |||
99 | let new_block = match if_let_pat { | 100 | let new_block = match if_let_pat { |
100 | None => { | 101 | None => { |
101 | // If. | 102 | // If. |
102 | let early_expression = &(early_expression.syntax().to_string() + ";"); | 103 | let new_expr = { |
103 | let new_expr = if_indent_level | 104 | let then_branch = |
104 | .increase_indent(make::if_expression(cond_expr, early_expression)); | 105 | make::block_expr(once(make::expr_stmt(early_expression).into()), None); |
106 | let cond = invert_boolean_expression(cond_expr); | ||
107 | let e = make::expr_if(cond, then_branch); | ||
108 | if_indent_level.increase_indent(e) | ||
109 | }; | ||
105 | replace(new_expr.syntax(), &then_block, &parent_block, &if_expr) | 110 | replace(new_expr.syntax(), &then_block, &parent_block, &if_expr) |
106 | } | 111 | } |
107 | Some((path, bound_ident)) => { | 112 | Some((path, bound_ident)) => { |