Skip to content

Commit ea11846

Browse files
committed
fix parens when inlining closure in body of function
1 parent 60f7473 commit ea11846

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

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

+30-1
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,12 @@ fn inline(
481481
};
482482
body.reindent_to(original_indentation);
483483

484+
let no_stmts = body.statements().next().is_none();
484485
match body.tail_expr() {
485-
Some(expr) if !is_async_fn && body.statements().next().is_none() => expr,
486+
Some(expr) if matches!(expr, ast::Expr::ClosureExpr(_)) && no_stmts => {
487+
make::expr_paren(expr).clone_for_update()
488+
}
489+
Some(expr) if !is_async_fn && no_stmts => expr,
486490
_ => match node
487491
.syntax()
488492
.parent()
@@ -1471,6 +1475,31 @@ fn main() {
14711475
}
14721476
});
14731477
}
1478+
"#,
1479+
);
1480+
}
1481+
1482+
#[test]
1483+
fn inline_call_closure_body() {
1484+
check_assist(
1485+
inline_call,
1486+
r#"
1487+
fn f() -> impl Fn() -> i32 {
1488+
|| 2
1489+
}
1490+
1491+
fn main() {
1492+
let _ = $0f()();
1493+
}
1494+
"#,
1495+
r#"
1496+
fn f() -> impl Fn() -> i32 {
1497+
|| 2
1498+
}
1499+
1500+
fn main() {
1501+
let _ = (|| 2)();
1502+
}
14741503
"#,
14751504
);
14761505
}

0 commit comments

Comments
 (0)