change name to [infinite_loop];

& apply review suggestions;
This commit is contained in:
J-ZhengLi 2023-11-28 10:28:55 +08:00
parent 0d26f9183b
commit 758d0e8661
6 changed files with 34 additions and 27 deletions

View File

@ -5147,7 +5147,7 @@ Released 2018-09-13
[`inefficient_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inefficient_to_string
[`infallible_destructuring_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#infallible_destructuring_match
[`infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#infinite_iter
[`infinite_loops`]: https://rust-lang.github.io/rust-clippy/master/index.html#infinite_loops
[`infinite_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#infinite_loop
[`inherent_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string
[`inherent_to_string_shadow_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string_shadow_display
[`init_numbered_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#init_numbered_fields

View File

@ -263,7 +263,7 @@
crate::loops::EXPLICIT_INTO_ITER_LOOP_INFO,
crate::loops::EXPLICIT_ITER_LOOP_INFO,
crate::loops::FOR_KV_MAP_INFO,
crate::loops::INFINITE_LOOPS_INFO,
crate::loops::INFINITE_LOOP_INFO,
crate::loops::ITER_NEXT_LOOP_INFO,
crate::loops::MANUAL_FIND_INFO,
crate::loops::MANUAL_FLATTEN_INFO,

View File

@ -7,7 +7,7 @@
use rustc_hir as hir;
use rustc_lint::LateContext;
use super::INFINITE_LOOPS;
use super::INFINITE_LOOP;
pub(super) fn check<'tcx>(
cx: &LateContext<'tcx>,
@ -15,7 +15,7 @@ pub(super) fn check<'tcx>(
loop_block: &'tcx hir::Block<'_>,
label: Option<Label>,
) {
if is_lint_allowed(cx, INFINITE_LOOPS, expr.hir_id) {
if is_lint_allowed(cx, INFINITE_LOOP, expr.hir_id) {
return;
}
@ -45,7 +45,7 @@ pub(super) fn check<'tcx>(
let is_finite_loop = loop_visitor.is_finite;
if !is_finite_loop {
span_lint_and_then(cx, INFINITE_LOOPS, expr.span, "infinite loop detected", |diag| {
span_lint_and_then(cx, INFINITE_LOOP, expr.span, "infinite loop detected", |diag| {
if let FnRetTy::DefaultReturn(ret_span) = parent_fn_ret {
diag.span_suggestion(
ret_span,
@ -54,10 +54,7 @@ pub(super) fn check<'tcx>(
Applicability::MaybeIncorrect,
);
} else {
diag.span_help(
expr.span,
"if this is not intended, try adding a `break` or `return` condition in this loop",
);
diag.help("if this is not intended, try adding a `break` or `return` condition in the loop");
}
});
}

View File

@ -3,7 +3,7 @@
mod explicit_into_iter_loop;
mod explicit_iter_loop;
mod for_kv_map;
mod infinite_loops;
mod infinite_loop;
mod iter_next_loop;
mod manual_find;
mod manual_flatten;
@ -642,7 +642,7 @@
/// and lint accordingly.
///
/// ### Why is this bad?
/// A loop should be gently exited somewhere, or at lease mark its parent function as
/// A loop should be gently exited somewhere, or at least mark its parent function as
/// never return (`!`).
///
/// ### Example
@ -673,9 +673,9 @@
/// }
/// ```
#[clippy::version = "1.75.0"]
pub INFINITE_LOOPS,
pub INFINITE_LOOP,
restriction,
"possibly unintended infinite loops"
"possibly unintended infinite loop"
}
pub struct Loops {
@ -712,7 +712,7 @@ pub fn new(msrv: Msrv, enforce_iter_loop_reborrow: bool) -> Self {
MANUAL_FIND,
MANUAL_WHILE_LET_SOME,
UNUSED_ENUMERATE_INDEX,
INFINITE_LOOPS,
INFINITE_LOOP,
]);
impl<'tcx> LateLintPass<'tcx> for Loops {
@ -755,7 +755,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// also check for empty `loop {}` statements, skipping those in #[panic_handler]
empty_loop::check(cx, expr, block);
while_let_loop::check(cx, expr, block);
infinite_loops::check(cx, expr, block, label);
infinite_loop::check(cx, expr, block, label);
}
while_let_on_iterator::check(cx, expr);

View File

@ -1,6 +1,6 @@
//@no-rustfix
#![allow(clippy::never_loop)]
#![warn(clippy::infinite_loops)]
#![warn(clippy::infinite_loop)]
fn do_something() {}
@ -357,4 +357,10 @@ fn inf_loop_in_closure() {
};
}
fn inf_loop_in_res() -> Result<(), i32> {
Ok(loop {
do_something()
})
}
fn main() {}

View File

@ -7,8 +7,8 @@ LL | | do_something();
LL | | }
| |_____^
|
= note: `-D clippy::infinite-loops` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::infinite_loops)]`
= note: `-D clippy::infinite-loop` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::infinite_loop)]`
help: if this is intentional, consider specifing `!` as function return
|
LL | fn no_break() -> ! {
@ -71,14 +71,7 @@ LL | | do_something();
LL | | }
| |_____^
|
help: if this is not intended, try adding a `break` or `return` condition in this loop
--> $DIR/infinite_loops.rs:33:5
|
LL | / loop {
LL | |
LL | | do_something();
LL | | }
| |_____^
= help: if this is not intended, try adding a `break` or `return` condition in the loop
error: infinite loop detected
--> $DIR/infinite_loops.rs:46:5
@ -251,5 +244,16 @@ help: if this is intentional, consider specifing `!` as function return
LL | let _loop_forever = || -> ! {
| ++++
error: aborting due to 16 previous errors
error: infinite loop detected
--> $DIR/infinite_loops.rs:361:8
|
LL | Ok(loop {
| ________^
LL | | do_something()
LL | | })
| |_____^
|
= help: if this is not intended, try adding a `break` or `return` condition in the loop
error: aborting due to 17 previous errors