Consider referenced allowed or hard-coded types

This commit is contained in:
Caio 2023-05-13 23:24:33 -03:00
parent 1407c7627e
commit 891fffef0c
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() {}