diff --git a/clippy_lints/src/is_unit_expr.rs b/clippy_lints/src/is_unit_expr.rs index 152612bd8ff..58df45ad89a 100644 --- a/clippy_lints/src/is_unit_expr.rs +++ b/clippy_lints/src/is_unit_expr.rs @@ -98,6 +98,7 @@ impl EarlyLintPass for UnitExpr { } } } + fn is_unit_expr(expr: &Expr) -> Option { match expr.node { ExprKind::Block(ref block) => if check_last_stmt_in_block(block) { @@ -139,9 +140,13 @@ fn check_last_stmt_in_block(block: &Block) -> bool { // like `panic!()` match final_stmt.node { StmtKind::Expr(_) => false, - StmtKind::Semi(ref expr) => match expr.node { - ExprKind::Break(_, _) | ExprKind::Ret(_) => false, - _ => true, + StmtKind::Semi(ref expr) => { + match expr.node { + ExprKind::Break(_, _) | + ExprKind::Continue(_) | + ExprKind::Ret(_) => false, + _ => true, + } }, _ => true, } diff --git a/tests/ui/is_unit_expr.rs b/tests/ui/is_unit_expr.rs index d1f45d517b0..164e391ff24 100644 --- a/tests/ui/is_unit_expr.rs +++ b/tests/ui/is_unit_expr.rs @@ -45,4 +45,29 @@ fn main() { 0; }, }; + + loop { + let a2 = match a1 { + Some(x) => x, + _ => { + break; + }, + }; + let a2 = match a1 { + Some(x) => x, + _ => { + continue; + }, + }; + } +} + +pub fn foo() -> i32 { + let a2 = match None { + Some(x) => x, + _ => { + return 42; + }, + }; + 55 }