diff options
| author | l1nxy <l1nxy.zy@gmail.com> | 2024-01-01 21:53:57 +0800 |
|---|---|---|
| committer | l1nxy <l1nxy.zy@gmail.com> | 2024-01-01 21:53:57 +0800 |
| commit | edb9ad21bd8f0a692d100f6d3282e2b442fabc64 (patch) | |
| tree | f6df1c5c9bc83f37483e5f6c9508ab5748ebbcfb | |
| parent | 7fee0881db85600a4a31442555a305d215064283 (diff) | |
| download | rust-edb9ad21bd8f0a692d100f6d3282e2b442fabc64.tar.gz rust-edb9ad21bd8f0a692d100f6d3282e2b442fabc64.zip | |
apply to only has nested if.
| -rw-r--r-- | crates/ide-assists/src/handlers/merge_nested_if.rs | 6 |
1 files changed, 5 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 af99d6fdef0..39db42faaea 100644 --- a/crates/ide-assists/src/handlers/merge_nested_if.rs +++ b/crates/ide-assists/src/handlers/merge_nested_if.rs @@ -47,6 +47,10 @@ pub(crate) fn merge_nested_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt //check if the then branch is a nested if let then_branch = expr.then_branch()?; + let stmt = then_branch.stmt_list()?; + if stmt.statements().count() != 0 { + return None; + } let nested_if_to_merge = then_branch.syntax().descendants().find_map(ast::IfExpr::cast)?; // should not apply to nested if with else branch. @@ -221,7 +225,7 @@ mod tests { ) } #[test] - fn merge_nested_if_do_not_apply_with_not_only_has_nested_if(){ + fn merge_nested_if_do_not_apply_with_not_only_has_nested_if() { check_assist_not_applicable( merge_nested_if, "fn f() { i$0f x == 0 { if y == 3 { foo(); } foo(); } }", |
