From a463154bf0a4028fb6f4027ad58fc45a30379103 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Wed, 19 Mar 2025 21:37:42 +0900 Subject: [PATCH] set the applicability of `op_ref` to `MachineApplicable` --- clippy_lints/src/operators/op_ref.rs | 8 ++++---- tests/ui/op_ref.fixed | 12 ++++++++++++ tests/ui/op_ref.rs | 12 ++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/operators/op_ref.rs b/clippy_lints/src/operators/op_ref.rs index c3c09946c27d..b03985d15654 100644 --- a/clippy_lints/src/operators/op_ref.rs +++ b/clippy_lints/src/operators/op_ref.rs @@ -86,7 +86,7 @@ pub(crate) fn check<'tcx>( left.span, "use the left value directly", lsnip, - Applicability::MaybeIncorrect, // FIXME #2597 + Applicability::MachineApplicable, ); }, ); @@ -105,7 +105,7 @@ pub(crate) fn check<'tcx>( right.span, "use the right value directly", rsnip, - Applicability::MaybeIncorrect, // FIXME #2597 + Applicability::MachineApplicable, ); }, ); @@ -137,7 +137,7 @@ pub(crate) fn check<'tcx>( left.span, "use the left value directly", lsnip, - Applicability::MaybeIncorrect, // FIXME #2597 + Applicability::MachineApplicable, ); }, ); @@ -164,7 +164,7 @@ pub(crate) fn check<'tcx>( right.span, "use the right value directly", rsnip, - Applicability::MaybeIncorrect, // FIXME #2597 + Applicability::MachineApplicable, ); }); } diff --git a/tests/ui/op_ref.fixed b/tests/ui/op_ref.fixed index 46a59e419cce..f412190b9fd9 100644 --- a/tests/ui/op_ref.fixed +++ b/tests/ui/op_ref.fixed @@ -98,3 +98,15 @@ impl Mul for A { self * &rhs } } + +mod issue_2597 { + fn ex1() { + let a: &str = "abc"; + let b: String = "abc".to_owned(); + println!("{}", a > &b); + } + + pub fn ex2(array: &[T], val: &T, idx: usize) -> bool { + &array[idx] < val + } +} diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs index e10840ff4b97..a4bbd86c7e95 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -98,3 +98,15 @@ impl Mul for A { self * &rhs } } + +mod issue_2597 { + fn ex1() { + let a: &str = "abc"; + let b: String = "abc".to_owned(); + println!("{}", a > &b); + } + + pub fn ex2(array: &[T], val: &T, idx: usize) -> bool { + &array[idx] < val + } +}