Skip to content

Commit ce56cf7

Browse files
committed
chore
1 parent 79ed23f commit ce56cf7

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

clippy_lints/src/loops/single_element_loop.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
use super::SINGLE_ELEMENT_LOOP;
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::{indent_of, snippet_with_applicability};
4-
use clippy_utils::visitors::for_each_expr;
4+
use clippy_utils::visitors::contains_break_or_continue;
55
use if_chain::if_chain;
66
use rustc_ast::util::parser::PREC_PREFIX;
77
use rustc_ast::Mutability;
88
use rustc_errors::Applicability;
99
use rustc_hir::{is_range_literal, BorrowKind, Expr, ExprKind, Pat};
1010
use rustc_lint::LateContext;
1111
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-
}
2412

2513
pub(super) fn check<'tcx>(
2614
cx: &LateContext<'tcx>,

clippy_utils/src/visitors.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,14 @@ pub fn for_each_local_assignment<'tcx, B>(
724724
ControlFlow::Continue(())
725725
}
726726
}
727+
728+
pub fn contains_break_or_continue(expr: &Expr<'_>) -> bool {
729+
for_each_expr(expr, |e| {
730+
if matches!(e.kind, ExprKind::Break(..) | ExprKind::Continue(..)) {
731+
ControlFlow::Break(())
732+
} else {
733+
ControlFlow::Continue(())
734+
}
735+
})
736+
.is_some()
737+
}

0 commit comments

Comments
 (0)