Skip to content

Commit 38d2387

Browse files
committed
Simplify is_simple_break_expr
This is shorter, and also avoids overloading the `peel_blocks()` from `clippy_utils` with different semantics.
1 parent f88f9a9 commit 38d2387

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

clippy_lints/src/loops/while_let_loop.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,17 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_blo
4242
}
4343
}
4444

45-
/// Returns `true` if expr contains a single break expression without a label or eub-expression.
45+
/// Returns `true` if expr contains a single break expression without a label or sub-expression,
46+
/// possibly embedded in blocks.
4647
fn is_simple_break_expr(e: &Expr<'_>) -> bool {
47-
matches!(peel_blocks(e).kind, ExprKind::Break(dest, None) if dest.label.is_none())
48-
}
49-
50-
/// Removes any blocks containing only a single expression.
51-
fn peel_blocks<'tcx>(e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
5248
if let ExprKind::Block(b, _) = e.kind {
5349
match (b.stmts, b.expr) {
54-
([s], None) => {
55-
if let StmtKind::Expr(e) | StmtKind::Semi(e) = s.kind {
56-
peel_blocks(e)
57-
} else {
58-
e
59-
}
60-
},
61-
([], Some(e)) => peel_blocks(e),
62-
_ => e,
50+
([s], None) => matches!(s.kind, StmtKind::Expr(e) | StmtKind::Semi(e) if is_simple_break_expr(e)),
51+
([], Some(e)) => is_simple_break_expr(e),
52+
_ => false,
6353
}
6454
} else {
65-
e
55+
matches!(e.kind, ExprKind::Break(dest, None) if dest.label.is_none())
6656
}
6757
}
6858

0 commit comments

Comments
 (0)