File tree 1 file changed +30
-1
lines changed
crates/ide-assists/src/handlers
1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -481,8 +481,12 @@ fn inline(
481
481
} ;
482
482
body. reindent_to ( original_indentation) ;
483
483
484
+ let no_stmts = body. statements ( ) . next ( ) . is_none ( ) ;
484
485
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,
486
490
_ => match node
487
491
. syntax ( )
488
492
. parent ( )
@@ -1471,6 +1475,31 @@ fn main() {
1471
1475
}
1472
1476
});
1473
1477
}
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
+ }
1474
1503
"# ,
1475
1504
) ;
1476
1505
}
You can’t perform that action at this time.
0 commit comments