@@ -413,7 +413,7 @@ fn suggestion_snippet_for_continue_inside_else(cx: &LateContext<'_>, data: &Lint
413
413
)
414
414
}
415
415
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 )
417
417
where
418
418
F : Fn ( Option < & Label > , Span ) ,
419
419
{
@@ -422,36 +422,40 @@ where
422
422
func ( continue_label. label . as_ref ( ) , inner_expr. span ) ;
423
423
} ,
424
424
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) ;
426
426
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) ;
428
428
}
429
429
} ,
430
430
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
+ }
431
435
for arm in arms. iter ( ) {
432
- check_last_stmt_in_expr ( arm. body , func) ;
436
+ check_last_stmt_in_expr ( cx , arm. body , func) ;
433
437
}
434
438
} ,
435
439
ExprKind :: Block ( b, _) => {
436
- check_last_stmt_in_block ( b, func) ;
440
+ check_last_stmt_in_block ( cx , b, func) ;
437
441
} ,
438
442
_ => { } ,
439
443
}
440
444
}
441
445
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 )
443
447
where
444
448
F : Fn ( Option < & Label > , Span ) ,
445
449
{
446
450
if let Some ( expr) = b. expr {
447
- check_last_stmt_in_expr ( expr, func) ;
451
+ check_last_stmt_in_expr ( cx , expr, func) ;
448
452
return ;
449
453
}
450
454
451
455
if let Some ( last_stmt) = b. stmts . last ( )
452
456
&& let StmtKind :: Expr ( inner_expr) | StmtKind :: Semi ( inner_expr) = last_stmt. kind
453
457
{
454
- check_last_stmt_in_expr ( inner_expr, func) ;
458
+ check_last_stmt_in_expr ( cx , inner_expr, func) ;
455
459
}
456
460
}
457
461
@@ -501,7 +505,7 @@ fn check_and_warn(cx: &LateContext<'_>, expr: &Expr<'_>) {
501
505
}
502
506
503
507
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) ;
505
509
}
506
510
}
507
511
@@ -534,7 +538,7 @@ fn check_and_warn(cx: &LateContext<'_>, expr: &Expr<'_>) {
534
538
} ) ;
535
539
536
540
if !maybe_emitted_in_if {
537
- check_last_stmt_in_block ( loop_block, & p) ;
541
+ check_last_stmt_in_block ( cx , loop_block, & p) ;
538
542
}
539
543
}
540
544
} ) ;
0 commit comments