diff options
| author | l1nxy <l1nxy.zy@gmail.com> | 2024-01-03 09:48:49 +0800 |
|---|---|---|
| committer | l1nxy <l1nxy.zy@gmail.com> | 2024-01-03 09:48:49 +0800 |
| commit | 161d3055d192e36b87bfb0abd2c66f1356ed8681 (patch) | |
| tree | 7b47bf03ab282f7c2c639287d9a5747df35768d7 | |
| parent | a3be52cbc0ff88f2e06e117b8e0843531832a37d (diff) | |
| download | rust-161d3055d192e36b87bfb0abd2c66f1356ed8681.tar.gz rust-161d3055d192e36b87bfb0abd2c66f1356ed8681.zip | |
use tail_expr().
| -rw-r--r-- | crates/ide-assists/src/handlers/merge_nested_if.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/crates/ide-assists/src/handlers/merge_nested_if.rs b/crates/ide-assists/src/handlers/merge_nested_if.rs index 5742f60a1e3..2f3136f027b 100644 --- a/crates/ide-assists/src/handlers/merge_nested_if.rs +++ b/crates/ide-assists/src/handlers/merge_nested_if.rs @@ -53,7 +53,10 @@ pub(crate) fn merge_nested_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt return None; } - let nested_if_to_merge = then_branch.syntax().descendants().find_map(ast::IfExpr::cast)?; + let nested_if_to_merge = then_branch.tail_expr().and_then(|e| match e { + ast::Expr::IfExpr(e) => Some(e), + _ => None, + })?; // should not apply to nested if with else branch. if nested_if_to_merge.else_branch().is_some() { return None; @@ -232,4 +235,12 @@ mod tests { "fn f() { i$0f x == 0 { if y == 3 { foo(); } foo(); } }", ) } + + #[test] + fn merge_nested_if_do_not_apply_with_multiply_nested_if() { + check_assist_not_applicable( + merge_nested_if, + "fn f() { i$0f x == 0 { if y == 3 { foo(); } if z == 3 { 2 } } }", + ) + } } |
