Skip to content

Commit 5436dba

Browse files
committed
Auto merge of rust-lang#11263 - c410-f3r:let-chain, r=Centri3
[`arithmetic_side_effects`] Fix rust-lang#11262 Fix rust-lang#11262 Rustc already handles paths that refer literals -> https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d795058a2e1634c867288c20ff9432c8 ``` changelog: [`arithmetic_side_effects`]: Ignore paths that refer literals ```
2 parents 2ab1241 + 35d434d commit 5436dba

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::ARITHMETIC_SIDE_EFFECTS;
22
use clippy_utils::consts::{constant, constant_simple, Constant};
33
use clippy_utils::diagnostics::span_lint;
4-
use clippy_utils::{is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary};
4+
use clippy_utils::{expr_or_init, is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary};
55
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::ty::Ty;
@@ -138,8 +138,10 @@ impl ArithmeticSideEffects {
138138
) {
139139
return;
140140
};
141-
let (actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs);
142-
let (actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs);
141+
let (mut actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs);
142+
let (mut actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs);
143+
actual_lhs = expr_or_init(cx, actual_lhs);
144+
actual_rhs = expr_or_init(cx, actual_rhs);
143145
let lhs_ty = cx.typeck_results().expr_ty(actual_lhs).peel_refs();
144146
let rhs_ty = cx.typeck_results().expr_ty(actual_rhs).peel_refs();
145147
if self.has_allowed_binary(lhs_ty, rhs_ty) {

Diff for: tests/ui/arithmetic_side_effects.rs

+7
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,11 @@ pub fn issue_11145() {
486486
x += 1;
487487
}
488488

489+
pub fn issue_11262() {
490+
let one = 1;
491+
let zero = 0;
492+
let _ = 2 / one;
493+
let _ = 2 / zero;
494+
}
495+
489496
fn main() {}

0 commit comments

Comments
 (0)