diff options
| author | bors <bors@rust-lang.org> | 2023-05-14 04:41:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-14 04:41:41 +0000 |
| commit | a167973e8171bce22ded246283faaf80b729382d (patch) | |
| tree | 4baf4637b246364c280f40198cb64597590fa3f6 | |
| parent | fff790b6590ca249e3fde5614c05a86cde20a5f0 (diff) | |
| parent | 891fffef0ced6a62406db1b9c7742cc064af96ba (diff) | |
| download | rust-a167973e8171bce22ded246283faaf80b729382d.tar.gz rust-a167973e8171bce22ded246283faaf80b729382d.zip | |
Auto merge of #10768 - c410-f3r:arith-3, r=Jarcho
[arithmetic_side_effects] Consider referenced allowed or hard-coded types Fix #10767 ``` changelog: [`arithmetic_side_effects`]: Do not fire when dealing with allowed or hard-coded types that are referenced. ```
| -rw-r--r-- | clippy_lints/src/operators/arithmetic_side_effects.rs | 10 | ||||
| -rw-r--r-- | tests/ui/arithmetic_side_effects.rs | 8 |
2 files changed, 13 insertions, 5 deletions
diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index f72595987ee..c80e2ff7057 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -21,7 +21,7 @@ const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[ ["f64", "f64"], ["std::num::Saturating", "std::num::Saturating"], ["std::num::Wrapping", "std::num::Wrapping"], - ["std::string::String", "&str"], + ["std::string::String", "str"], ]; const HARD_CODED_ALLOWED_UNARY: &[&str] = &["f32", "f64", "std::num::Saturating", "std::num::Wrapping"]; const INTEGER_METHODS: &[&str] = &["saturating_div", "wrapping_div", "wrapping_rem", "wrapping_rem_euclid"]; @@ -144,8 +144,10 @@ impl ArithmeticSideEffects { ) { return; }; - let lhs_ty = cx.typeck_results().expr_ty(lhs); - let rhs_ty = cx.typeck_results().expr_ty(rhs); + let (actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs); + let (actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs); + let lhs_ty = cx.typeck_results().expr_ty(actual_lhs).peel_refs(); + let rhs_ty = cx.typeck_results().expr_ty(actual_rhs).peel_refs(); if self.has_allowed_binary(lhs_ty, rhs_ty) { return; } @@ -154,8 +156,6 @@ impl ArithmeticSideEffects { // At least for integers, shifts are already handled by the CTFE return; } - let (actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs); - let (actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs); match ( Self::literal_integer(cx, actual_lhs), Self::literal_integer(cx, actual_rhs), diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index ab408bdf261..f95af1017bc 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -458,4 +458,12 @@ pub fn issue_10583(a: u16) -> u16 { 10 / a } +pub fn issue_10767() { + let n = &1.0; + n + n; + 3.1_f32 + &1.2_f32; + &3.4_f32 + 1.5_f32; + &3.5_f32 + &1.3_f32; +} + fn main() {} |
