Auto merge of #4243 - mikerite:fix-4058, r=flip1995

Fix `never_loop` false positive

Closes #4058

changelog: none
This commit is contained in:
bors 2019-07-01 08:10:25 +00:00
commit 47ada9ae07
2 changed files with 12 additions and 2 deletions

View File

@ -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 {

View File

@ -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();