Skip to content

Commit a167973

Browse files
committed
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. ```
2 parents fff790b + 891fffe commit a167973

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Diff for: clippy_lints/src/operators/arithmetic_side_effects.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[
2121
["f64", "f64"],
2222
["std::num::Saturating", "std::num::Saturating"],
2323
["std::num::Wrapping", "std::num::Wrapping"],
24-
["std::string::String", "&str"],
24+
["std::string::String", "str"],
2525
];
2626
const HARD_CODED_ALLOWED_UNARY: &[&str] = &["f32", "f64", "std::num::Saturating", "std::num::Wrapping"];
2727
const INTEGER_METHODS: &[&str] = &["saturating_div", "wrapping_div", "wrapping_rem", "wrapping_rem_euclid"];
@@ -144,8 +144,10 @@ impl ArithmeticSideEffects {
144144
) {
145145
return;
146146
};
147-
let lhs_ty = cx.typeck_results().expr_ty(lhs);
148-
let rhs_ty = cx.typeck_results().expr_ty(rhs);
147+
let (actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs);
148+
let (actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs);
149+
let lhs_ty = cx.typeck_results().expr_ty(actual_lhs).peel_refs();
150+
let rhs_ty = cx.typeck_results().expr_ty(actual_rhs).peel_refs();
149151
if self.has_allowed_binary(lhs_ty, rhs_ty) {
150152
return;
151153
}
@@ -154,8 +156,6 @@ impl ArithmeticSideEffects {
154156
// At least for integers, shifts are already handled by the CTFE
155157
return;
156158
}
157-
let (actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs);
158-
let (actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs);
159159
match (
160160
Self::literal_integer(cx, actual_lhs),
161161
Self::literal_integer(cx, actual_rhs),

Diff for: tests/ui/arithmetic_side_effects.rs

+8
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,12 @@ pub fn issue_10583(a: u16) -> u16 {
458458
10 / a
459459
}
460460

461+
pub fn issue_10767() {
462+
let n = &1.0;
463+
n + n;
464+
3.1_f32 + &1.2_f32;
465+
&3.4_f32 + 1.5_f32;
466+
&3.5_f32 + &1.3_f32;
467+
}
468+
461469
fn main() {}

0 commit comments

Comments
 (0)