@@ -413,7 +413,7 @@ fn suggestion_snippet_for_continue_inside_else(cx: &LateContext<'_>, data: &Lint
413413 )
414414}
415415
416- fn check_last_stmt_in_expr < F > ( inner_expr : & Expr < ' _ > , func : & F )
416+ fn check_last_stmt_in_expr < F > ( cx : & LateContext < ' _ > , inner_expr : & Expr < ' _ > , func : & F )
417417where
418418 F : Fn ( Option < & Label > , Span ) ,
419419{
@@ -422,36 +422,40 @@ where
422422 func ( continue_label. label . as_ref ( ) , inner_expr. span ) ;
423423 } ,
424424 ExprKind :: If ( _, then_block, else_block) if let ExprKind :: Block ( then_block, _) = then_block. kind => {
425- check_last_stmt_in_block ( then_block, func) ;
425+ check_last_stmt_in_block ( cx , then_block, func) ;
426426 if let Some ( else_block) = else_block {
427- check_last_stmt_in_expr ( else_block, func) ;
427+ check_last_stmt_in_expr ( cx , else_block, func) ;
428428 }
429429 } ,
430430 ExprKind :: Match ( _, arms, _) => {
431+ let match_ty = cx. typeck_results ( ) . expr_ty ( inner_expr) ;
432+ if !match_ty. is_unit ( ) && !match_ty. is_never ( ) {
433+ return ;
434+ }
431435 for arm in arms. iter ( ) {
432- check_last_stmt_in_expr ( arm. body , func) ;
436+ check_last_stmt_in_expr ( cx , arm. body , func) ;
433437 }
434438 } ,
435439 ExprKind :: Block ( b, _) => {
436- check_last_stmt_in_block ( b, func) ;
440+ check_last_stmt_in_block ( cx , b, func) ;
437441 } ,
438442 _ => { } ,
439443 }
440444}
441445
442- fn check_last_stmt_in_block < F > ( b : & Block < ' _ > , func : & F )
446+ fn check_last_stmt_in_block < F > ( cx : & LateContext < ' _ > , b : & Block < ' _ > , func : & F )
443447where
444448 F : Fn ( Option < & Label > , Span ) ,
445449{
446450 if let Some ( expr) = b. expr {
447- check_last_stmt_in_expr ( expr, func) ;
451+ check_last_stmt_in_expr ( cx , expr, func) ;
448452 return ;
449453 }
450454
451455 if let Some ( last_stmt) = b. stmts . last ( )
452456 && let StmtKind :: Expr ( inner_expr) | StmtKind :: Semi ( inner_expr) = last_stmt. kind
453457 {
454- check_last_stmt_in_expr ( inner_expr, func) ;
458+ check_last_stmt_in_expr ( cx , inner_expr, func) ;
455459 }
456460}
457461
@@ -501,7 +505,7 @@ fn check_and_warn(cx: &LateContext<'_>, expr: &Expr<'_>) {
501505 }
502506
503507 if i == stmts. len ( ) - 1 && loop_block. expr . is_none ( ) && !maybe_emitted_in_if {
504- check_last_stmt_in_block ( loop_block, & p) ;
508+ check_last_stmt_in_block ( cx , loop_block, & p) ;
505509 }
506510 }
507511
@@ -534,7 +538,7 @@ fn check_and_warn(cx: &LateContext<'_>, expr: &Expr<'_>) {
534538 } ) ;
535539
536540 if !maybe_emitted_in_if {
537- check_last_stmt_in_block ( loop_block, & p) ;
541+ check_last_stmt_in_block ( cx , loop_block, & p) ;
538542 }
539543 }
540544 } ) ;
0 commit comments