about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJ-ZhengLi <lizheng135@huawei.com>2023-11-28 10:28:55 +0800
committerJ-ZhengLi <lizheng135@huawei.com>2023-11-28 10:28:55 +0800
commit758d0e8661fd757ed12a07959eae142c695500ed (patch)
treee5618672ffd602f218ecc4892f6393e9dca08746
parent0d26f9183b3d8b9354c35d6ecdd4c1367d5d5eec (diff)
downloadrust-758d0e8661fd757ed12a07959eae142c695500ed.tar.gz
rust-758d0e8661fd757ed12a07959eae142c695500ed.zip
change name to [`infinite_loop`];
& apply review suggestions;
-rw-r--r--CHANGELOG.md2
-rw-r--r--clippy_lints/src/declared_lints.rs2
-rw-r--r--clippy_lints/src/loops/infinite_loop.rs (renamed from clippy_lints/src/loops/infinite_loops.rs)11
-rw-r--r--clippy_lints/src/loops/mod.rs12
-rw-r--r--tests/ui/infinite_loops.rs8
-rw-r--r--tests/ui/infinite_loops.stderr26
6 files changed, 34 insertions, 27 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c62cf51559..924d346a9c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs
index 7520b57891e..6422c6cc6df 100644
--- a/clippy_lints/src/declared_lints.rs
+++ b/clippy_lints/src/declared_lints.rs
@@ -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,
diff --git a/clippy_lints/src/loops/infinite_loops.rs b/clippy_lints/src/loops/infinite_loop.rs
index 5e474bf45ee..9b88dd76e5c 100644
--- a/clippy_lints/src/loops/infinite_loops.rs
+++ b/clippy_lints/src/loops/infinite_loop.rs
@@ -7,7 +7,7 @@ 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>,
@@ -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");
             }
         });
     }
diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs
index 214e406374f..61ff491716b 100644
--- a/clippy_lints/src/loops/mod.rs
+++ b/clippy_lints/src/loops/mod.rs
@@ -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;
@@ -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
@@ -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 {
@@ -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 {
@@ -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);
diff --git a/tests/ui/infinite_loops.rs b/tests/ui/infinite_loops.rs
index 0c18ad620bf..646f1eca56d 100644
--- a/tests/ui/infinite_loops.rs
+++ b/tests/ui/infinite_loops.rs
@@ -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() {}
diff --git a/tests/ui/infinite_loops.stderr b/tests/ui/infinite_loops.stderr
index ebbc6151188..f58b3cebbc3 100644
--- a/tests/ui/infinite_loops.stderr
+++ b/tests/ui/infinite_loops.stderr
@@ -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