Skip to content

Commit

Permalink
Auto merge of #4243 - mikerite:fix-4058, r=flip1995
Browse files Browse the repository at this point in the history
Fix `never_loop` false positive

Closes #4058

changelog: none
  • Loading branch information
bors committed Jul 1, 2019
2 parents ad638a3 + 7c98915 commit 47ada9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,7 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
NeverLoopResult::AlwaysBreak
}
},
ExprKind::Break(_, _) => NeverLoopResult::AlwaysBreak,
ExprKind::Ret(ref e) => {
ExprKind::Break(_, ref e) | ExprKind::Ret(ref e) => {
if let Some(ref e) = *e {
combine_seq(never_loop_expr(e, main_loop_id), NeverLoopResult::AlwaysBreak)
} else {
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/never_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ pub fn test15() {
}
}

// Issue #4058: `continue` in `break` expression
pub fn test16() {
let mut n = 1;
loop {
break if n != 5 {
n += 1;
continue;
};
}
}

fn main() {
test1();
test2();
Expand Down

0 comments on commit 47ada9a

Please sign in to comment.