diff options
| author | bors <bors@rust-lang.org> | 2023-01-07 11:53:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-01-07 11:53:45 +0000 |
| commit | cf1d3d03700069d6a31fc142a1808a7f3dcde429 (patch) | |
| tree | 8f7dc6233b1f205d09ba1da3d38f76cf9a5c0980 /clippy_utils | |
| parent | ef5a545f9860fbbea3f6c94bad60ab87f384d458 (diff) | |
| parent | ce56cf71d956ea78c319ff510651473ca8dce47c (diff) | |
Auto merge of #10162 - tamaroning:fix10018, r=xFrednet
Fix FP of single-element-loop closes #10018 --- changelog: [`single_element_loop`]: No longer lints, if the loop contains a `break` or `continue` [#10162](https://github.com/rust-lang/rust-clippy/pull/10162) <!-- changelog_checked -->
Diffstat (limited to 'clippy_utils')
| -rw-r--r-- | clippy_utils/src/visitors.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 863fb60fcfc..14c01a60b4c 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -724,3 +724,14 @@ pub fn for_each_local_assignment<'tcx, B>( ControlFlow::Continue(()) } } + +pub fn contains_break_or_continue(expr: &Expr<'_>) -> bool { + for_each_expr(expr, |e| { + if matches!(e.kind, ExprKind::Break(..) | ExprKind::Continue(..)) { + ControlFlow::Break(()) + } else { + ControlFlow::Continue(()) + } + }) + .is_some() +} |
