|
1 | 1 | use super::SINGLE_ELEMENT_LOOP; |
2 | 2 | use clippy_utils::diagnostics::span_lint_and_sugg; |
3 | 3 | use clippy_utils::source::{indent_of, snippet_with_applicability}; |
| 4 | +use clippy_utils::visitors::for_each_expr; |
4 | 5 | use if_chain::if_chain; |
5 | 6 | use rustc_ast::util::parser::PREC_PREFIX; |
6 | 7 | use rustc_ast::Mutability; |
7 | 8 | use rustc_errors::Applicability; |
8 | 9 | use rustc_hir::{is_range_literal, BorrowKind, Expr, ExprKind, Pat}; |
9 | 10 | use rustc_lint::LateContext; |
10 | 11 | use rustc_span::edition::Edition; |
| 12 | +use std::ops::ControlFlow; |
| 13 | + |
| 14 | +fn contains_break_or_continue(expr: &Expr<'_>) -> bool { |
| 15 | + for_each_expr(expr, |e| { |
| 16 | + if matches!(e.kind, ExprKind::Break(..) | ExprKind::Continue(..)) { |
| 17 | + ControlFlow::Break(()) |
| 18 | + } else { |
| 19 | + ControlFlow::Continue(()) |
| 20 | + } |
| 21 | + }) |
| 22 | + .is_some() |
| 23 | +} |
11 | 24 |
|
12 | 25 | pub(super) fn check<'tcx>( |
13 | 26 | cx: &LateContext<'tcx>, |
@@ -67,6 +80,7 @@ pub(super) fn check<'tcx>( |
67 | 80 | if_chain! { |
68 | 81 | if let ExprKind::Block(block, _) = body.kind; |
69 | 82 | if !block.stmts.is_empty(); |
| 83 | + if !contains_break_or_continue(body); |
70 | 84 | then { |
71 | 85 | let mut applicability = Applicability::MachineApplicable; |
72 | 86 | let pat_snip = snippet_with_applicability(cx, pat.span, "..", &mut applicability); |
|
0 commit comments