mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
catch never loops through diverging functions
This commit is contained in:
parent
39b316db61
commit
b3980d8497
3 changed files with 26 additions and 3 deletions
|
@ -148,7 +148,7 @@ fn never_loop_expr<'tcx>(
|
|||
local_labels: &mut Vec<(HirId, bool)>,
|
||||
main_loop_id: HirId,
|
||||
) -> NeverLoopResult {
|
||||
match expr.kind {
|
||||
let result = match expr.kind {
|
||||
ExprKind::Unary(_, e)
|
||||
| ExprKind::Cast(e, _)
|
||||
| ExprKind::Type(e, _)
|
||||
|
@ -262,7 +262,14 @@ fn never_loop_expr<'tcx>(
|
|||
| ExprKind::ConstBlock(_)
|
||||
| ExprKind::Lit(_)
|
||||
| ExprKind::Err(_) => NeverLoopResult::Normal,
|
||||
}
|
||||
};
|
||||
combine_seq(result, || {
|
||||
if cx.typeck_results().expr_ty(expr).is_never() {
|
||||
NeverLoopResult::Diverging
|
||||
} else {
|
||||
NeverLoopResult::Normal
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn never_loop_expr_all<'tcx, T: Iterator<Item = &'tcx Expr<'tcx>>>(
|
||||
|
|
|
@ -385,6 +385,13 @@ pub fn test31(b: bool) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn test32(b: bool) {
|
||||
loop {
|
||||
//~^ ERROR: this loop never actually loops
|
||||
panic!("oh no");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test1();
|
||||
test2();
|
||||
|
|
|
@ -161,5 +161,14 @@ LL | | if b { break 'c } else { break 'b }
|
|||
LL | | }
|
||||
| |_____________^
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
error: this loop never actually loops
|
||||
--> $DIR/never_loop.rs:389:5
|
||||
|
|
||||
LL | / loop {
|
||||
LL | |
|
||||
LL | | panic!("oh no");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue