@@ -116,7 +116,8 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) ->
116
116
. into_iter ( )
117
117
. map ( |( call_info, mut_node) | {
118
118
let replacement =
119
- inline ( & ctx. sema , def_file, function, & func_body, & params, & call_info) ;
119
+ inline ( & ctx. sema , def_file, function, & func_body, & params, & call_info)
120
+ . unwrap ( ) ;
120
121
ted:: replace ( mut_node, replacement. syntax ( ) ) ;
121
122
} )
122
123
. count ( ) ;
@@ -218,13 +219,12 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
218
219
}
219
220
220
221
let syntax = call_info. node . syntax ( ) . clone ( ) ;
222
+ let replacement = inline ( & ctx. sema , file_id, function, & fn_body, & params, & call_info) ?;
221
223
acc. add (
222
224
AssistId ( "inline_call" , AssistKind :: RefactorInline ) ,
223
225
label,
224
226
syntax. text_range ( ) ,
225
227
|builder| {
226
- let replacement = inline ( & ctx. sema , file_id, function, & fn_body, & params, & call_info) ;
227
-
228
228
builder. replace_ast (
229
229
match call_info. node {
230
230
ast:: CallableExpr :: Call ( it) => ast:: Expr :: CallExpr ( it) ,
@@ -305,7 +305,7 @@ fn inline(
305
305
fn_body : & ast:: BlockExpr ,
306
306
params : & [ ( ast:: Pat , Option < ast:: Type > , hir:: Param ) ] ,
307
307
CallInfo { node, arguments, generic_arg_list } : & CallInfo ,
308
- ) -> ast:: Expr {
308
+ ) -> Option < ast:: Expr > {
309
309
let mut body = if sema. hir_file_for ( fn_body. syntax ( ) ) . is_macro ( ) {
310
310
cov_mark:: hit!( inline_call_defined_in_macro) ;
311
311
if let Some ( body) = ast:: BlockExpr :: cast ( insert_ws_into ( fn_body. syntax ( ) . clone ( ) ) ) {
@@ -363,16 +363,17 @@ fn inline(
363
363
. collect ( ) ;
364
364
365
365
if function. self_param ( sema. db ) . is_some ( ) {
366
- let this = || make:: name_ref ( "this" ) . syntax ( ) . clone_for_update ( ) . first_token ( ) . unwrap ( ) ;
366
+ let this = || make:: name_ref ( "this" ) . syntax ( ) . clone_for_update ( ) . first_token ( ) ;
367
367
if let Some ( self_local) = params[ 0 ] . 2 . as_local ( sema. db ) {
368
- usages_for_locals ( self_local)
369
- . filter_map ( |FileReference { name, range, .. } | match name {
368
+ let usages = usages_for_locals ( self_local) . filter_map (
369
+ |FileReference { name, range, .. } | match name {
370
370
ast:: NameLike :: NameRef ( _) => Some ( body. syntax ( ) . covering_element ( range) ) ,
371
371
_ => None ,
372
- } )
373
- . for_each ( |it| {
374
- ted:: replace ( it, & this ( ) ) ;
375
- } )
372
+ } ,
373
+ ) ;
374
+ for usage in usages {
375
+ ted:: replace ( usage, & this ( ) ?) ;
376
+ }
376
377
}
377
378
}
378
379
@@ -470,7 +471,7 @@ fn inline(
470
471
}
471
472
} else if let Some ( stmt_list) = body. stmt_list ( ) {
472
473
ted:: insert_all (
473
- ted:: Position :: after ( stmt_list. l_curly_token ( ) . unwrap ( ) ) ,
474
+ ted:: Position :: after ( stmt_list. l_curly_token ( ) ? ) ,
474
475
let_stmts. into_iter ( ) . map ( |stmt| stmt. syntax ( ) . clone ( ) . into ( ) ) . collect ( ) ,
475
476
) ;
476
477
}
@@ -481,7 +482,7 @@ fn inline(
481
482
} ;
482
483
body. reindent_to ( original_indentation) ;
483
484
484
- match body. tail_expr ( ) {
485
+ Some ( match body. tail_expr ( ) {
485
486
Some ( expr) if !is_async_fn && body. statements ( ) . next ( ) . is_none ( ) => expr,
486
487
_ => match node
487
488
. syntax ( )
@@ -494,7 +495,7 @@ fn inline(
494
495
}
495
496
_ => ast:: Expr :: BlockExpr ( body) ,
496
497
} ,
497
- }
498
+ } )
498
499
}
499
500
500
501
fn path_expr_as_record_field ( usage : & PathExpr ) -> Option < ast:: RecordExprField > {
0 commit comments