Skip to content

Commit edb9ad2

Browse files
committed
apply to only has nested if.
1 parent 7fee088 commit edb9ad2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crates/ide-assists/src/handlers/merge_nested_if.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ pub(crate) fn merge_nested_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
4747

4848
//check if the then branch is a nested if
4949
let then_branch = expr.then_branch()?;
50+
let stmt = then_branch.stmt_list()?;
51+
if stmt.statements().count() != 0 {
52+
return None;
53+
}
5054

5155
let nested_if_to_merge = then_branch.syntax().descendants().find_map(ast::IfExpr::cast)?;
5256
// should not apply to nested if with else branch.
@@ -221,7 +225,7 @@ mod tests {
221225
)
222226
}
223227
#[test]
224-
fn merge_nested_if_do_not_apply_with_not_only_has_nested_if(){
228+
fn merge_nested_if_do_not_apply_with_not_only_has_nested_if() {
225229
check_assist_not_applicable(
226230
merge_nested_if,
227231
"fn f() { i$0f x == 0 { if y == 3 { foo(); } foo(); } }",

0 commit comments

Comments
 (0)