From d72a32c4436ee0764a0ab3de0cba8b4dd0bce546 Mon Sep 17 00:00:00 2001 From: FelixMaetzler Date: Sat, 30 Dec 2023 15:25:18 +0100 Subject: [PATCH 1/4] implemented unnecessary min --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/methods/mod.rs | 24 +++++ clippy_lints/src/methods/unnecessary_min.rs | 111 +++++++++++++++++++ tests/ui/cast.stderr | 11 +- tests/ui/unnecessary_min.fixed | 45 ++++++++ tests/ui/unnecessary_min.rs | 45 ++++++++ tests/ui/unnecessary_min.stderr | 113 ++++++++++++++++++++ 8 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 clippy_lints/src/methods/unnecessary_min.rs create mode 100644 tests/ui/unnecessary_min.fixed create mode 100644 tests/ui/unnecessary_min.rs create mode 100644 tests/ui/unnecessary_min.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index e6c081ca94f1..4fe67c554bc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5672,6 +5672,7 @@ Released 2018-09-13 [`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations [`unnecessary_literal_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_literal_unwrap [`unnecessary_map_on_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_on_constructor +[`unnecessary_min`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_min [`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed [`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation [`unnecessary_owned_empty_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_owned_empty_strings diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index f6c9ffea9fcd..052505bb779d 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -450,6 +450,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::methods::UNNECESSARY_JOIN_INFO, crate::methods::UNNECESSARY_LAZY_EVALUATIONS_INFO, crate::methods::UNNECESSARY_LITERAL_UNWRAP_INFO, + crate::methods::UNNECESSARY_MIN_INFO, crate::methods::UNNECESSARY_SORT_BY_INFO, crate::methods::UNNECESSARY_TO_OWNED_INFO, crate::methods::UNWRAP_OR_DEFAULT_INFO, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index fbca641cfa30..d25edae884f9 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -112,6 +112,7 @@ mod unnecessary_iter_cloned; mod unnecessary_join; mod unnecessary_lazy_eval; mod unnecessary_literal_unwrap; +mod unnecessary_min; mod unnecessary_sort_by; mod unnecessary_to_owned; mod unwrap_expect_used; @@ -3887,6 +3888,27 @@ declare_clippy_lint! { "splitting a trimmed string at hard-coded newlines" } +declare_clippy_lint! { + /// ### What it does + /// Checks for unnecessary calls to `min()` + /// + /// ### Why is this bad? + /// + /// In these cases it is not necessary to call `min()` + /// ### Example + /// ```no_run + /// let _ = 0.min(7_u32); + /// ``` + /// Use instead: + /// ```no_run + /// let _ = 7; + /// ``` + #[clippy::version = "1.77.0"] + pub UNNECESSARY_MIN, + complexity, + "using 'min()' when there is no need for it" +} + pub struct Methods { avoid_breaking_exported_api: bool, msrv: Msrv, @@ -4043,6 +4065,7 @@ impl_lint_pass!(Methods => [ ITER_FILTER_IS_OK, MANUAL_IS_VARIANT_AND, STR_SPLIT_AT_NEWLINE, + UNNECESSARY_MIN, ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -4324,6 +4347,7 @@ impl Methods { Some(("bytes", recv2, [], _, _)) => bytes_count_to_len::check(cx, expr, recv, recv2), _ => {}, }, + ("min", [arg]) => unnecessary_min::check(cx, expr, recv, arg), ("drain", ..) => { if let Node::Stmt(Stmt { hir_id: _, kind, .. }) = cx.tcx.hir().get_parent(expr.hir_id) && matches!(kind, StmtKind::Semi(_)) diff --git a/clippy_lints/src/methods/unnecessary_min.rs b/clippy_lints/src/methods/unnecessary_min.rs new file mode 100644 index 000000000000..5a9593e7d592 --- /dev/null +++ b/clippy_lints/src/methods/unnecessary_min.rs @@ -0,0 +1,111 @@ +use std::cmp::Ordering; + +use super::UNNECESSARY_MIN; +use clippy_utils::diagnostics::span_lint_and_sugg; + +use clippy_utils::consts::{constant, Constant}; +use clippy_utils::source::snippet; +use clippy_utils::{clip, int_bits, unsext}; +use hir::Expr; + +use rustc_errors::Applicability; +use rustc_hir as hir; +use rustc_lint::LateContext; + +use rustc_middle::ty; +use rustc_span::Span; + +pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>, arg: &'tcx Expr<'_>) { + if both_are_constant(cx, expr, recv, arg) { + return; + } + one_extrema(cx, expr, recv, arg); +} +fn lint(cx: &LateContext<'_>, expr: &Expr<'_>, sugg: Span, other: Span) { + let msg = format!( + "`{}` is never greater than `{}` and has therefore no effect", + snippet(cx, sugg, "Not yet implemented"), + snippet(cx, other, "Not yet implemented") + ); + span_lint_and_sugg( + cx, + UNNECESSARY_MIN, + expr.span, + &msg, + "try", + snippet(cx, sugg, "Not yet implemented").to_string(), + Applicability::MachineApplicable, + ); +} + +fn try_to_eval<'tcx>( + cx: &LateContext<'tcx>, + recv: &'tcx Expr<'_>, + arg: &'tcx Expr<'_>, +) -> (Option>, Option>) { + ( + (constant(cx, cx.typeck_results(), recv)), + (constant(cx, cx.typeck_results(), arg)), + ) +} +#[derive(Debug)] +enum Extrema { + Minimum, + Maximum, +} +fn detect_extrema<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { + let ty = cx.typeck_results().expr_ty(expr); + + let cv = constant(cx, cx.typeck_results(), expr)?; + + match (ty.kind(), cv) { + (&ty::Uint(_), Constant::Int(0)) => Some(Extrema::Minimum), + (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => { + Some(Extrema::Minimum) + }, + + (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) => { + Some(Extrema::Maximum) + }, + (&ty::Uint(uty), Constant::Int(i)) if i == clip(cx.tcx, u128::MAX, uty) => Some(Extrema::Maximum), + + _ => None, + } +} +fn both_are_constant<'tcx>( + cx: &LateContext<'tcx>, + expr: &'tcx Expr<'_>, + recv: &'tcx Expr<'_>, + arg: &'tcx Expr<'_>, +) -> bool { + let ty = cx.typeck_results().expr_ty(recv); + if let (Some(left), Some(right)) = try_to_eval(cx, recv, arg) + && let Some(ord) = Constant::partial_cmp(cx.tcx, ty, &left, &right) + { + let (sugg, other) = match ord { + Ordering::Less => (recv.span, arg.span), + Ordering::Equal | Ordering::Greater => (arg.span, recv.span), + }; + + lint(cx, expr, sugg, other); + return true; + } + false +} +fn one_extrema<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>, arg: &'tcx Expr<'_>) -> bool { + if let Some(extrema) = detect_extrema(cx, recv) { + match extrema { + Extrema::Minimum => lint(cx, expr, recv.span, arg.span), + Extrema::Maximum => lint(cx, expr, arg.span, recv.span), + } + return true; + } else if let Some(extrema) = detect_extrema(cx, arg) { + match extrema { + Extrema::Minimum => lint(cx, expr, arg.span, recv.span), + Extrema::Maximum => lint(cx, expr, recv.span, arg.span), + } + return true; + } + + false +} diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index bc74f7b728e8..e78de7dc00eb 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -333,6 +333,15 @@ help: ... or use `try_from` and handle the error accordingly LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +error: `(-99999999999i64)` is never greater than `1` and has therefore no effect + --> $DIR/cast.rs:179:5 + | +LL | (-99999999999i64).min(1) as i8; + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(-99999999999i64)` + | + = note: `-D clippy::unnecessary-min` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_min)]` + error: casting `u64` to `u8` may truncate the value --> $DIR/cast.rs:193:5 | @@ -444,5 +453,5 @@ help: ... or use `try_from` and handle the error accordingly LL | let c = u8::try_from(q / 1000); | ~~~~~~~~~~~~~~~~~~~~~~ -error: aborting due to 51 previous errors +error: aborting due to 52 previous errors diff --git a/tests/ui/unnecessary_min.fixed b/tests/ui/unnecessary_min.fixed new file mode 100644 index 000000000000..a81f1dabc481 --- /dev/null +++ b/tests/ui/unnecessary_min.fixed @@ -0,0 +1,45 @@ +#![allow(unused)] +#![warn(clippy::unnecessary_min)] + +fn main() { + const A: i64 = 45; + const B: i64 = -1; + const C: i64 = const_fn(B); + let _ = (A * B); // Both are constants + let _ = B; // Both are constants + let _ = B; // Both are constants + + let _ = (-6_i32); // Both are Literals + let _ = 6; // Both are Literals + + let _ = 6; // Both are Literals + + let _ = 0; // unsigned with zero + let _ = 0_u32; // unsigned with zero + + let _ = i32::MIN; // singed MIN + let _ = i32::MIN; // singed MIN + + let _ = 42; // singed MAX + let _ = 42; // singed MAX + + let _ = 0; // unsigned with zero and function + + let _ = 0; // unsigned with zero and function + + let _ = i64::MIN; // signed with MIN and function + + let _ = i64::MIN; // signed with MIN and function + + let _ = test_i64(); // signed with MAX and function + let _ = test_i64(); // signed with MAX and function +} +fn test_usize() -> usize { + 42 +} +fn test_i64() -> i64 { + 42 +} +const fn const_fn(input: i64) -> i64 { + -2 * input +} diff --git a/tests/ui/unnecessary_min.rs b/tests/ui/unnecessary_min.rs new file mode 100644 index 000000000000..8c6e50fd04b7 --- /dev/null +++ b/tests/ui/unnecessary_min.rs @@ -0,0 +1,45 @@ +#![allow(unused)] +#![warn(clippy::unnecessary_min)] + +fn main() { + const A: i64 = 45; + const B: i64 = -1; + const C: i64 = const_fn(B); + let _ = (A * B).min(B); // Both are constants + let _ = C.min(B); // Both are constants + let _ = B.min(C); // Both are constants + + let _ = (-6_i32).min(9); // Both are Literals + let _ = 9_u32.min(6); // Both are Literals + + let _ = 6.min(7_u8); // Both are Literals + + let _ = 0.min(7_u8); // unsigned with zero + let _ = 7.min(0_u32); // unsigned with zero + + let _ = i32::MIN.min(42); // singed MIN + let _ = 42.min(i32::MIN); // singed MIN + + let _ = i32::MAX.min(42); // singed MAX + let _ = 42.min(i32::MAX); // singed MAX + + let _ = 0.min(test_usize()); // unsigned with zero and function + + let _ = test_usize().min(0); // unsigned with zero and function + + let _ = i64::MIN.min(test_i64()); // signed with MIN and function + + let _ = test_i64().min(i64::MIN); // signed with MIN and function + + let _ = i64::MAX.min(test_i64()); // signed with MAX and function + let _ = test_i64().min(i64::MAX); // signed with MAX and function +} +fn test_usize() -> usize { + 42 +} +fn test_i64() -> i64 { + 42 +} +const fn const_fn(input: i64) -> i64 { + -2 * input +} diff --git a/tests/ui/unnecessary_min.stderr b/tests/ui/unnecessary_min.stderr new file mode 100644 index 000000000000..610f34416c25 --- /dev/null +++ b/tests/ui/unnecessary_min.stderr @@ -0,0 +1,113 @@ +error: `(A * B)` is never greater than `B` and has therefore no effect + --> $DIR/unnecessary_min.rs:8:13 + | +LL | let _ = (A * B).min(B); // Both are constants + | ^^^^^^^^^^^^^^ help: try: `(A * B)` + | + = note: `-D clippy::unnecessary-min` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_min)]` + +error: `B` is never greater than `C` and has therefore no effect + --> $DIR/unnecessary_min.rs:9:13 + | +LL | let _ = C.min(B); // Both are constants + | ^^^^^^^^ help: try: `B` + +error: `B` is never greater than `C` and has therefore no effect + --> $DIR/unnecessary_min.rs:10:13 + | +LL | let _ = B.min(C); // Both are constants + | ^^^^^^^^ help: try: `B` + +error: `(-6_i32)` is never greater than `9` and has therefore no effect + --> $DIR/unnecessary_min.rs:12:13 + | +LL | let _ = (-6_i32).min(9); // Both are Literals + | ^^^^^^^^^^^^^^^ help: try: `(-6_i32)` + +error: `6` is never greater than `9_u32` and has therefore no effect + --> $DIR/unnecessary_min.rs:13:13 + | +LL | let _ = 9_u32.min(6); // Both are Literals + | ^^^^^^^^^^^^ help: try: `6` + +error: `6` is never greater than `7_u8` and has therefore no effect + --> $DIR/unnecessary_min.rs:15:13 + | +LL | let _ = 6.min(7_u8); // Both are Literals + | ^^^^^^^^^^^ help: try: `6` + +error: `0` is never greater than `7_u8` and has therefore no effect + --> $DIR/unnecessary_min.rs:17:13 + | +LL | let _ = 0.min(7_u8); // unsigned with zero + | ^^^^^^^^^^^ help: try: `0` + +error: `0_u32` is never greater than `7` and has therefore no effect + --> $DIR/unnecessary_min.rs:18:13 + | +LL | let _ = 7.min(0_u32); // unsigned with zero + | ^^^^^^^^^^^^ help: try: `0_u32` + +error: `i32::MIN` is never greater than `42` and has therefore no effect + --> $DIR/unnecessary_min.rs:20:13 + | +LL | let _ = i32::MIN.min(42); // singed MIN + | ^^^^^^^^^^^^^^^^ help: try: `i32::MIN` + +error: `i32::MIN` is never greater than `42` and has therefore no effect + --> $DIR/unnecessary_min.rs:21:13 + | +LL | let _ = 42.min(i32::MIN); // singed MIN + | ^^^^^^^^^^^^^^^^ help: try: `i32::MIN` + +error: `42` is never greater than `i32::MAX` and has therefore no effect + --> $DIR/unnecessary_min.rs:23:13 + | +LL | let _ = i32::MAX.min(42); // singed MAX + | ^^^^^^^^^^^^^^^^ help: try: `42` + +error: `42` is never greater than `i32::MAX` and has therefore no effect + --> $DIR/unnecessary_min.rs:24:13 + | +LL | let _ = 42.min(i32::MAX); // singed MAX + | ^^^^^^^^^^^^^^^^ help: try: `42` + +error: `0` is never greater than `test_usize()` and has therefore no effect + --> $DIR/unnecessary_min.rs:26:13 + | +LL | let _ = 0.min(test_usize()); // unsigned with zero and function + | ^^^^^^^^^^^^^^^^^^^ help: try: `0` + +error: `0` is never greater than `test_usize()` and has therefore no effect + --> $DIR/unnecessary_min.rs:28:13 + | +LL | let _ = test_usize().min(0); // unsigned with zero and function + | ^^^^^^^^^^^^^^^^^^^ help: try: `0` + +error: `i64::MIN` is never greater than `test_i64()` and has therefore no effect + --> $DIR/unnecessary_min.rs:30:13 + | +LL | let _ = i64::MIN.min(test_i64()); // signed with MIN and function + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i64::MIN` + +error: `i64::MIN` is never greater than `test_i64()` and has therefore no effect + --> $DIR/unnecessary_min.rs:32:13 + | +LL | let _ = test_i64().min(i64::MIN); // signed with MIN and function + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i64::MIN` + +error: `test_i64()` is never greater than `i64::MAX` and has therefore no effect + --> $DIR/unnecessary_min.rs:34:13 + | +LL | let _ = i64::MAX.min(test_i64()); // signed with MAX and function + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `test_i64()` + +error: `test_i64()` is never greater than `i64::MAX` and has therefore no effect + --> $DIR/unnecessary_min.rs:35:13 + | +LL | let _ = test_i64().min(i64::MAX); // signed with MAX and function + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `test_i64()` + +error: aborting due to 18 previous errors + From 1aa9745d009b7866bed461b131fbdb2ef7427b14 Mon Sep 17 00:00:00 2001 From: FelixMaetzler Date: Thu, 4 Jan 2024 15:41:09 +0100 Subject: [PATCH 2/4] fixed description --- clippy_lints/src/methods/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index d25edae884f9..4e600bcaa243 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3901,7 +3901,7 @@ declare_clippy_lint! { /// ``` /// Use instead: /// ```no_run - /// let _ = 7; + /// let _ = 0; /// ``` #[clippy::version = "1.77.0"] pub UNNECESSARY_MIN, From 892fc29d26955cceef56e8e645651378c404d298 Mon Sep 17 00:00:00 2001 From: FelixMaetzler Date: Thu, 4 Jan 2024 16:10:47 +0100 Subject: [PATCH 3/4] added test --- tests/ui/unnecessary_min.fixed | 10 ++++++++- tests/ui/unnecessary_min.rs | 10 ++++++++- tests/ui/unnecessary_min.stderr | 36 ++++++++++++++++----------------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/tests/ui/unnecessary_min.fixed b/tests/ui/unnecessary_min.fixed index a81f1dabc481..05b65bf23fe6 100644 --- a/tests/ui/unnecessary_min.fixed +++ b/tests/ui/unnecessary_min.fixed @@ -1,6 +1,5 @@ #![allow(unused)] #![warn(clippy::unnecessary_min)] - fn main() { const A: i64 = 45; const B: i64 = -1; @@ -33,6 +32,11 @@ fn main() { let _ = test_i64(); // signed with MAX and function let _ = test_i64(); // signed with MAX and function + + let mut min = u32::MAX; + for _ in 0..1000 { + min = min.min(random_u32()); // shouldn't lint + } } fn test_usize() -> usize { 42 @@ -43,3 +47,7 @@ fn test_i64() -> i64 { const fn const_fn(input: i64) -> i64 { -2 * input } +fn random_u32() -> u32 { + // random number generator + 0 +} diff --git a/tests/ui/unnecessary_min.rs b/tests/ui/unnecessary_min.rs index 8c6e50fd04b7..c636888a73aa 100644 --- a/tests/ui/unnecessary_min.rs +++ b/tests/ui/unnecessary_min.rs @@ -1,6 +1,5 @@ #![allow(unused)] #![warn(clippy::unnecessary_min)] - fn main() { const A: i64 = 45; const B: i64 = -1; @@ -33,6 +32,11 @@ fn main() { let _ = i64::MAX.min(test_i64()); // signed with MAX and function let _ = test_i64().min(i64::MAX); // signed with MAX and function + + let mut min = u32::MAX; + for _ in 0..1000 { + min = min.min(random_u32()); // shouldn't lint + } } fn test_usize() -> usize { 42 @@ -43,3 +47,7 @@ fn test_i64() -> i64 { const fn const_fn(input: i64) -> i64 { -2 * input } +fn random_u32() -> u32 { + // random number generator + 0 +} diff --git a/tests/ui/unnecessary_min.stderr b/tests/ui/unnecessary_min.stderr index 610f34416c25..45739ae2836c 100644 --- a/tests/ui/unnecessary_min.stderr +++ b/tests/ui/unnecessary_min.stderr @@ -1,5 +1,5 @@ error: `(A * B)` is never greater than `B` and has therefore no effect - --> $DIR/unnecessary_min.rs:8:13 + --> $DIR/unnecessary_min.rs:7:13 | LL | let _ = (A * B).min(B); // Both are constants | ^^^^^^^^^^^^^^ help: try: `(A * B)` @@ -8,103 +8,103 @@ LL | let _ = (A * B).min(B); // Both are constants = help: to override `-D warnings` add `#[allow(clippy::unnecessary_min)]` error: `B` is never greater than `C` and has therefore no effect - --> $DIR/unnecessary_min.rs:9:13 + --> $DIR/unnecessary_min.rs:8:13 | LL | let _ = C.min(B); // Both are constants | ^^^^^^^^ help: try: `B` error: `B` is never greater than `C` and has therefore no effect - --> $DIR/unnecessary_min.rs:10:13 + --> $DIR/unnecessary_min.rs:9:13 | LL | let _ = B.min(C); // Both are constants | ^^^^^^^^ help: try: `B` error: `(-6_i32)` is never greater than `9` and has therefore no effect - --> $DIR/unnecessary_min.rs:12:13 + --> $DIR/unnecessary_min.rs:11:13 | LL | let _ = (-6_i32).min(9); // Both are Literals | ^^^^^^^^^^^^^^^ help: try: `(-6_i32)` error: `6` is never greater than `9_u32` and has therefore no effect - --> $DIR/unnecessary_min.rs:13:13 + --> $DIR/unnecessary_min.rs:12:13 | LL | let _ = 9_u32.min(6); // Both are Literals | ^^^^^^^^^^^^ help: try: `6` error: `6` is never greater than `7_u8` and has therefore no effect - --> $DIR/unnecessary_min.rs:15:13 + --> $DIR/unnecessary_min.rs:14:13 | LL | let _ = 6.min(7_u8); // Both are Literals | ^^^^^^^^^^^ help: try: `6` error: `0` is never greater than `7_u8` and has therefore no effect - --> $DIR/unnecessary_min.rs:17:13 + --> $DIR/unnecessary_min.rs:16:13 | LL | let _ = 0.min(7_u8); // unsigned with zero | ^^^^^^^^^^^ help: try: `0` error: `0_u32` is never greater than `7` and has therefore no effect - --> $DIR/unnecessary_min.rs:18:13 + --> $DIR/unnecessary_min.rs:17:13 | LL | let _ = 7.min(0_u32); // unsigned with zero | ^^^^^^^^^^^^ help: try: `0_u32` error: `i32::MIN` is never greater than `42` and has therefore no effect - --> $DIR/unnecessary_min.rs:20:13 + --> $DIR/unnecessary_min.rs:19:13 | LL | let _ = i32::MIN.min(42); // singed MIN | ^^^^^^^^^^^^^^^^ help: try: `i32::MIN` error: `i32::MIN` is never greater than `42` and has therefore no effect - --> $DIR/unnecessary_min.rs:21:13 + --> $DIR/unnecessary_min.rs:20:13 | LL | let _ = 42.min(i32::MIN); // singed MIN | ^^^^^^^^^^^^^^^^ help: try: `i32::MIN` error: `42` is never greater than `i32::MAX` and has therefore no effect - --> $DIR/unnecessary_min.rs:23:13 + --> $DIR/unnecessary_min.rs:22:13 | LL | let _ = i32::MAX.min(42); // singed MAX | ^^^^^^^^^^^^^^^^ help: try: `42` error: `42` is never greater than `i32::MAX` and has therefore no effect - --> $DIR/unnecessary_min.rs:24:13 + --> $DIR/unnecessary_min.rs:23:13 | LL | let _ = 42.min(i32::MAX); // singed MAX | ^^^^^^^^^^^^^^^^ help: try: `42` error: `0` is never greater than `test_usize()` and has therefore no effect - --> $DIR/unnecessary_min.rs:26:13 + --> $DIR/unnecessary_min.rs:25:13 | LL | let _ = 0.min(test_usize()); // unsigned with zero and function | ^^^^^^^^^^^^^^^^^^^ help: try: `0` error: `0` is never greater than `test_usize()` and has therefore no effect - --> $DIR/unnecessary_min.rs:28:13 + --> $DIR/unnecessary_min.rs:27:13 | LL | let _ = test_usize().min(0); // unsigned with zero and function | ^^^^^^^^^^^^^^^^^^^ help: try: `0` error: `i64::MIN` is never greater than `test_i64()` and has therefore no effect - --> $DIR/unnecessary_min.rs:30:13 + --> $DIR/unnecessary_min.rs:29:13 | LL | let _ = i64::MIN.min(test_i64()); // signed with MIN and function | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i64::MIN` error: `i64::MIN` is never greater than `test_i64()` and has therefore no effect - --> $DIR/unnecessary_min.rs:32:13 + --> $DIR/unnecessary_min.rs:31:13 | LL | let _ = test_i64().min(i64::MIN); // signed with MIN and function | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i64::MIN` error: `test_i64()` is never greater than `i64::MAX` and has therefore no effect - --> $DIR/unnecessary_min.rs:34:13 + --> $DIR/unnecessary_min.rs:33:13 | LL | let _ = i64::MAX.min(test_i64()); // signed with MAX and function | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `test_i64()` error: `test_i64()` is never greater than `i64::MAX` and has therefore no effect - --> $DIR/unnecessary_min.rs:35:13 + --> $DIR/unnecessary_min.rs:34:13 | LL | let _ = test_i64().min(i64::MAX); // signed with MAX and function | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `test_i64()` From bdb42e035a77a49b92eb5bd72f8ded9a71350c34 Mon Sep 17 00:00:00 2001 From: FelixMaetzler Date: Thu, 4 Jan 2024 16:44:59 +0100 Subject: [PATCH 4/4] fixed update_lints --- README.md | 2 +- book/src/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb3f7109d7e6..fa18447090c1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are over 650 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are over 700 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) Lints are divided into categories, each with a default [lint level](https://doc.rust-lang.org/rustc/lints/levels.html). You can choose how much Clippy is supposed to ~~annoy~~ help you by changing the lint level by category. diff --git a/book/src/README.md b/book/src/README.md index 486ea3df7042..e7972b0db19c 100644 --- a/book/src/README.md +++ b/book/src/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are over 650 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are over 700 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) Lints are divided into categories, each with a default [lint level](https://doc.rust-lang.org/rustc/lints/levels.html). You can choose how