[arithmetic_side_effects] Fix #11262

This commit is contained in:
Caio 2023-07-30 14:33:38 -03:00
parent a447725394
commit 35d434d08e
2 changed files with 12 additions and 3 deletions

View file

@ -1,7 +1,7 @@
use super::ARITHMETIC_SIDE_EFFECTS;
use clippy_utils::consts::{constant, constant_simple, Constant};
use clippy_utils::diagnostics::span_lint;
use clippy_utils::{is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary};
use clippy_utils::{expr_or_init, is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::Ty;
@ -138,8 +138,10 @@ impl ArithmeticSideEffects {
) {
return;
};
let (actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs);
let (actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs);
let (mut actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs);
let (mut actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs);
actual_lhs = expr_or_init(cx, actual_lhs);
actual_rhs = expr_or_init(cx, actual_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) {

View file

@ -486,4 +486,11 @@ pub fn issue_11145() {
x += 1;
}
pub fn issue_11262() {
let one = 1;
let zero = 0;
let _ = 2 / one;
let _ = 2 / zero;
}
fn main() {}