@@ -116,7 +116,8 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) ->
116116 . into_iter ( )
117117 . map ( |( call_info, mut_node) | {
118118 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 ( ) ;
120121 ted:: replace ( mut_node, replacement. syntax ( ) ) ;
121122 } )
122123 . count ( ) ;
@@ -218,13 +219,12 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
218219 }
219220
220221 let syntax = call_info. node . syntax ( ) . clone ( ) ;
222+ let replacement = inline ( & ctx. sema , file_id, function, & fn_body, & params, & call_info) ?;
221223 acc. add (
222224 AssistId ( "inline_call" , AssistKind :: RefactorInline ) ,
223225 label,
224226 syntax. text_range ( ) ,
225227 |builder| {
226- let replacement = inline ( & ctx. sema , file_id, function, & fn_body, & params, & call_info) ;
227-
228228 builder. replace_ast (
229229 match call_info. node {
230230 ast:: CallableExpr :: Call ( it) => ast:: Expr :: CallExpr ( it) ,
@@ -305,7 +305,7 @@ fn inline(
305305 fn_body : & ast:: BlockExpr ,
306306 params : & [ ( ast:: Pat , Option < ast:: Type > , hir:: Param ) ] ,
307307 CallInfo { node, arguments, generic_arg_list } : & CallInfo ,
308- ) -> ast:: Expr {
308+ ) -> Option < ast:: Expr > {
309309 let mut body = if sema. hir_file_for ( fn_body. syntax ( ) ) . is_macro ( ) {
310310 cov_mark:: hit!( inline_call_defined_in_macro) ;
311311 if let Some ( body) = ast:: BlockExpr :: cast ( insert_ws_into ( fn_body. syntax ( ) . clone ( ) ) ) {
@@ -363,16 +363,17 @@ fn inline(
363363 . collect ( ) ;
364364
365365 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 ( ) ;
367367 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 {
370370 ast:: NameLike :: NameRef ( _) => Some ( body. syntax ( ) . covering_element ( range) ) ,
371371 _ => 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+ }
376377 }
377378 }
378379
@@ -470,7 +471,7 @@ fn inline(
470471 }
471472 } else if let Some ( stmt_list) = body. stmt_list ( ) {
472473 ted:: insert_all (
473- ted:: Position :: after ( stmt_list. l_curly_token ( ) . unwrap ( ) ) ,
474+ ted:: Position :: after ( stmt_list. l_curly_token ( ) ? ) ,
474475 let_stmts. into_iter ( ) . map ( |stmt| stmt. syntax ( ) . clone ( ) . into ( ) ) . collect ( ) ,
475476 ) ;
476477 }
@@ -481,7 +482,7 @@ fn inline(
481482 } ;
482483 body. reindent_to ( original_indentation) ;
483484
484- match body. tail_expr ( ) {
485+ Some ( match body. tail_expr ( ) {
485486 Some ( expr) if !is_async_fn && body. statements ( ) . next ( ) . is_none ( ) => expr,
486487 _ => match node
487488 . syntax ( )
@@ -494,7 +495,7 @@ fn inline(
494495 }
495496 _ => ast:: Expr :: BlockExpr ( body) ,
496497 } ,
497- }
498+ } )
498499}
499500
500501fn path_expr_as_record_field ( usage : & PathExpr ) -> Option < ast:: RecordExprField > {
0 commit comments