Skip to content

Commit

Permalink
change name to [infinite_loop];
Browse files Browse the repository at this point in the history
& apply review suggestions;
  • Loading branch information
J-ZhengLi committed Nov 28, 2023
1 parent 0d26f91 commit 758d0e8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use rustc_errors::Applicability;
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>,
expr: &Expr<'_>,
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;
}

Expand Down Expand Up @@ -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,
Expand All @@ -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");
}
});
}
Expand Down
12 changes: 6 additions & 6 deletions clippy_lints/src/loops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod explicit_counter_loop;
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;
Expand Down Expand Up @@ -642,7 +642,7 @@ declare_clippy_lint! {
/// 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
Expand Down Expand Up @@ -673,9 +673,9 @@ declare_clippy_lint! {
/// }
/// ```
#[clippy::version = "1.75.0"]
pub INFINITE_LOOPS,
pub INFINITE_LOOP,
restriction,
"possibly unintended infinite loops"
"possibly unintended infinite loop"
}

pub struct Loops {
Expand Down Expand Up @@ -712,7 +712,7 @@ impl_lint_pass!(Loops => [
MANUAL_FIND,
MANUAL_WHILE_LET_SOME,
UNUSED_ENUMERATE_INDEX,
INFINITE_LOOPS,
INFINITE_LOOP,
]);

impl<'tcx> LateLintPass<'tcx> for Loops {
Expand Down Expand Up @@ -755,7 +755,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
// 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);
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/infinite_loops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@no-rustfix
#![allow(clippy::never_loop)]
#![warn(clippy::infinite_loops)]
#![warn(clippy::infinite_loop)]

fn do_something() {}

Expand Down Expand Up @@ -357,4 +357,10 @@ fn inf_loop_in_closure() {
};
}

fn inf_loop_in_res() -> Result<(), i32> {
Ok(loop {
do_something()
})
}

fn main() {}
26 changes: 15 additions & 11 deletions tests/ui/infinite_loops.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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() -> ! {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 758d0e8

Please sign in to comment.