Skip to content

Commit 47ada9a

Browse files
committed
Auto merge of #4243 - mikerite:fix-4058, r=flip1995
Fix `never_loop` false positive Closes #4058 changelog: none
2 parents ad638a3 + 7c98915 commit 47ada9a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clippy_lints/src/loops.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,7 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
727727
NeverLoopResult::AlwaysBreak
728728
}
729729
},
730-
ExprKind::Break(_, _) => NeverLoopResult::AlwaysBreak,
731-
ExprKind::Ret(ref e) => {
730+
ExprKind::Break(_, ref e) | ExprKind::Ret(ref e) => {
732731
if let Some(ref e) = *e {
733732
combine_seq(never_loop_expr(e, main_loop_id), NeverLoopResult::AlwaysBreak)
734733
} else {

tests/ui/never_loop.rs

+11
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ pub fn test15() {
175175
}
176176
}
177177

178+
// Issue #4058: `continue` in `break` expression
179+
pub fn test16() {
180+
let mut n = 1;
181+
loop {
182+
break if n != 5 {
183+
n += 1;
184+
continue;
185+
};
186+
}
187+
}
188+
178189
fn main() {
179190
test1();
180191
test2();

0 commit comments

Comments
 (0)