@@ -1610,30 +1610,35 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
16101610 let mut applicability = Applicability :: MachineApplicable ;
16111611
16121612 //Special handling for `format!` as arg_root
1613- if let hir:: ExprKind :: Call ( ref inner_fun, ref inner_args) = arg_root. kind {
1614- if is_expn_of ( inner_fun. span , "format" ) . is_some ( ) && inner_args. len ( ) == 1 {
1615- if let hir:: ExprKind :: Call ( _, format_args) = & inner_args[ 0 ] . kind {
1616- let fmt_spec = & format_args[ 0 ] ;
1617- let fmt_args = & format_args[ 1 ] ;
1613+ if_chain ! {
1614+ if let hir:: ExprKind :: Block ( block, None ) = & arg_root. kind;
1615+ if block. stmts. len( ) == 1 ;
1616+ if let hir:: StmtKind :: Local ( local) = & block. stmts[ 0 ] . kind;
1617+ if let Some ( arg_root) = & local. init;
1618+ if let hir:: ExprKind :: Call ( ref inner_fun, ref inner_args) = arg_root. kind;
1619+ if is_expn_of( inner_fun. span, "format" ) . is_some( ) && inner_args. len( ) == 1 ;
1620+ if let hir:: ExprKind :: Call ( _, format_args) = & inner_args[ 0 ] . kind;
1621+ then {
1622+ let fmt_spec = & format_args[ 0 ] ;
1623+ let fmt_args = & format_args[ 1 ] ;
16181624
1619- let mut args = vec ! [ snippet( cx, fmt_spec. span, ".." ) . into_owned( ) ] ;
1625+ let mut args = vec![ snippet( cx, fmt_spec. span, ".." ) . into_owned( ) ] ;
16201626
1621- args. extend ( generate_format_arg_snippet ( cx, fmt_args, & mut applicability) ) ;
1627+ args. extend( generate_format_arg_snippet( cx, fmt_args, & mut applicability) ) ;
16221628
1623- let sugg = args. join ( ", " ) ;
1629+ let sugg = args. join( ", " ) ;
16241630
1625- span_lint_and_sugg (
1626- cx,
1627- EXPECT_FUN_CALL ,
1628- span_replace_word,
1629- & format ! ( "use of `{}` followed by a function call" , name) ,
1630- "try this" ,
1631- format ! ( "unwrap_or_else({} panic!({}))" , closure_args, sugg) ,
1632- applicability,
1633- ) ;
1631+ span_lint_and_sugg(
1632+ cx,
1633+ EXPECT_FUN_CALL ,
1634+ span_replace_word,
1635+ & format!( "use of `{}` followed by a function call" , name) ,
1636+ "try this" ,
1637+ format!( "unwrap_or_else({} panic!({}))" , closure_args, sugg) ,
1638+ applicability,
1639+ ) ;
16341640
1635- return ;
1636- }
1641+ return ;
16371642 }
16381643 }
16391644
0 commit comments