@@ -9,7 +9,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
99use clippy_utils:: source:: { indent_of, reindent_multiline, snippet_with_applicability} ;
1010use clippy_utils:: ty:: get_type_diagnostic_name;
1111use clippy_utils:: visitors:: for_each_unconsumed_temporary;
12- use clippy_utils:: { get_parent_expr , peel_blocks} ;
12+ use clippy_utils:: { is_expr_final_block_expr , peel_blocks} ;
1313
1414use super :: RETURN_AND_THEN ;
1515
@@ -21,7 +21,7 @@ pub(super) fn check<'tcx>(
2121 recv : & ' tcx hir:: Expr < ' tcx > ,
2222 arg : & ' tcx hir:: Expr < ' _ > ,
2323) {
24- if cx. tcx . hir_get_fn_id_for_return_block ( expr. hir_id ) . is_none ( ) {
24+ if ! is_expr_final_block_expr ( cx. tcx , expr) {
2525 return ;
2626 }
2727
@@ -55,24 +55,12 @@ pub(super) fn check<'tcx>(
5555 None => & body_snip,
5656 } ;
5757
58- // If suggestion is going to get inserted as part of a `return` expression, it must be blockified.
59- let sugg = if let Some ( parent_expr) = get_parent_expr ( cx, expr) {
60- let base_indent = indent_of ( cx, parent_expr. span ) ;
61- let inner_indent = base_indent. map ( |i| i + 4 ) ;
62- format ! (
63- "{}\n {}\n {}" ,
64- reindent_multiline( & format!( "{{\n let {arg_snip} = {recv_snip}?;" ) , true , inner_indent) ,
65- reindent_multiline( inner, false , inner_indent) ,
66- reindent_multiline( "}" , false , base_indent) ,
67- )
68- } else {
69- format ! (
70- "let {} = {}?;\n {}" ,
71- arg_snip,
72- recv_snip,
73- reindent_multiline( inner, false , indent_of( cx, expr. span) )
74- )
75- } ;
58+ let sugg = format ! (
59+ "let {} = {}?;\n {}" ,
60+ arg_snip,
61+ recv_snip,
62+ reindent_multiline( inner, false , indent_of( cx, expr. span) )
63+ ) ;
7664
7765 span_lint_and_sugg (
7866 cx,
0 commit comments