Skip to content

Commit 161d305

Browse files
committed
use tail_expr().
1 parent a3be52c commit 161d305

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ pub(crate) fn merge_nested_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
5353
return None;
5454
}
5555

56-
let nested_if_to_merge = then_branch.syntax().descendants().find_map(ast::IfExpr::cast)?;
56+
let nested_if_to_merge = then_branch.tail_expr().and_then(|e| match e {
57+
ast::Expr::IfExpr(e) => Some(e),
58+
_ => None,
59+
})?;
5760
// should not apply to nested if with else branch.
5861
if nested_if_to_merge.else_branch().is_some() {
5962
return None;
@@ -232,4 +235,12 @@ mod tests {
232235
"fn f() { i$0f x == 0 { if y == 3 { foo(); } foo(); } }",
233236
)
234237
}
238+
239+
#[test]
240+
fn merge_nested_if_do_not_apply_with_multiply_nested_if() {
241+
check_assist_not_applicable(
242+
merge_nested_if,
243+
"fn f() { i$0f x == 0 { if y == 3 { foo(); } if z == 3 { 2 } } }",
244+
)
245+
}
235246
}

0 commit comments

Comments
 (0)