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.
```
This commit is contained in:
bors 2023-05-14 04:41:41 +00:00
commit a167973e81
2 changed files with 13 additions and 5 deletions

View File

@ -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),

View File

@ -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() {}