From 2d9fc6dfc8160f47f13da9be3fb5fc48ef62880f Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Fri, 17 Nov 2023 18:10:50 +0800 Subject: [PATCH 1/4] implement unoptimized code logic for [`infinite_loops`] --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/loops/infinite_loops.rs | 92 ++++++++ clippy_lints/src/loops/mod.rs | 79 ++++++- tests/ui/infinite_loops.rs | 259 +++++++++++++++++++++++ tests/ui/infinite_loops.stderr | 147 +++++++++++++ 6 files changed, 571 insertions(+), 8 deletions(-) create mode 100644 clippy_lints/src/loops/infinite_loops.rs create mode 100644 tests/ui/infinite_loops.rs create mode 100644 tests/ui/infinite_loops.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index e74df808e06..5c62cf51559 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5147,6 +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 [`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 85854a0dfb7..7520b57891e 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -263,6 +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::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_loops.rs new file mode 100644 index 00000000000..b97cd8bd006 --- /dev/null +++ b/clippy_lints/src/loops/infinite_loops.rs @@ -0,0 +1,92 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::is_lint_allowed; +use hir::intravisit::{walk_expr, Visitor}; +use hir::{Block, Destination, Expr, ExprKind, FnRetTy, Ty, TyKind}; +use rustc_ast::Label; +use rustc_errors::Applicability; +use rustc_hir as hir; +use rustc_lint::LateContext; + +use super::INFINITE_LOOPS; + +pub(super) fn check( + cx: &LateContext<'_>, + expr: &Expr<'_>, + loop_block: &Block<'_>, + label: Option