Skip to content

Commit 270cbeb

Browse files
committed
Auto merge of #10674 - c410-f3r:macro-lint, r=Jarcho
Rename `integer_arithmetic` The lack of official feedback in #10200 made me give up on pursuing the matter but after yet another use-case that is not handled by `integer_arithmetic` (#10615), I think it is worth trying again. --- changelog: Move/Deprecation: Rename `integer_arithmetic` to `arithmetic_side_effects` [#10674](#10674) <!-- changelog_checked -->
2 parents 815a07e + 493b2ae commit 270cbeb

13 files changed

+81
-407
lines changed

Diff for: clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
491491
crate::operators::FLOAT_EQUALITY_WITHOUT_ABS_INFO,
492492
crate::operators::IDENTITY_OP_INFO,
493493
crate::operators::INEFFECTIVE_BIT_MASK_INFO,
494-
crate::operators::INTEGER_ARITHMETIC_INFO,
495494
crate::operators::INTEGER_DIVISION_INFO,
496495
crate::operators::MISREFACTORED_ASSIGN_OP_INFO,
497496
crate::operators::MODULO_ARITHMETIC_INFO,

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

-27
Original file line numberDiff line numberDiff line change
@@ -96,32 +96,6 @@ declare_clippy_lint! {
9696
"any arithmetic expression that can cause side effects like overflows or panics"
9797
}
9898

99-
declare_clippy_lint! {
100-
/// ### What it does
101-
/// Checks for integer arithmetic operations which could overflow or panic.
102-
///
103-
/// Specifically, checks for any operators (`+`, `-`, `*`, `<<`, etc) which are capable
104-
/// of overflowing according to the [Rust
105-
/// Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow),
106-
/// or which can panic (`/`, `%`). No bounds analysis or sophisticated reasoning is
107-
/// attempted.
108-
///
109-
/// ### Why is this bad?
110-
/// Integer overflow will trigger a panic in debug builds or will wrap in
111-
/// release mode. Division by zero will cause a panic in either mode. In some applications one
112-
/// wants explicitly checked, wrapping or saturating arithmetic.
113-
///
114-
/// ### Example
115-
/// ```rust
116-
/// # let a = 0;
117-
/// a + 1;
118-
/// ```
119-
#[clippy::version = "pre 1.29.0"]
120-
pub INTEGER_ARITHMETIC,
121-
restriction,
122-
"any integer arithmetic expression which could overflow or panic"
123-
}
124-
12599
declare_clippy_lint! {
126100
/// ### What it does
127101
/// Checks for float arithmetic.
@@ -787,7 +761,6 @@ pub struct Operators {
787761
impl_lint_pass!(Operators => [
788762
ABSURD_EXTREME_COMPARISONS,
789763
ARITHMETIC_SIDE_EFFECTS,
790-
INTEGER_ARITHMETIC,
791764
FLOAT_ARITHMETIC,
792765
ASSIGN_OP_PATTERN,
793766
MISREFACTORED_ASSIGN_OP,

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

+6-39
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use super::{FLOAT_ARITHMETIC, INTEGER_ARITHMETIC};
1+
use super::FLOAT_ARITHMETIC;
22
use clippy_utils::consts::constant_simple;
33
use clippy_utils::diagnostics::span_lint;
4-
use clippy_utils::is_from_proc_macro;
5-
use clippy_utils::is_integer_literal;
64
use rustc_hir as hir;
75
use rustc_lint::LateContext;
86
use rustc_span::source_map::Span;
@@ -45,31 +43,8 @@ impl Context {
4543
_ => (),
4644
}
4745

48-
let (l_ty, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r));
49-
if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() {
50-
if is_from_proc_macro(cx, expr) {
51-
return;
52-
}
53-
match op {
54-
hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind {
55-
hir::ExprKind::Lit(_lit) => (),
56-
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
57-
if is_integer_literal(expr, 1) {
58-
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
59-
self.expr_id = Some(expr.hir_id);
60-
}
61-
},
62-
_ => {
63-
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
64-
self.expr_id = Some(expr.hir_id);
65-
},
66-
},
67-
_ => {
68-
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
69-
self.expr_id = Some(expr.hir_id);
70-
},
71-
}
72-
} else if r_ty.peel_refs().is_floating_point() && r_ty.peel_refs().is_floating_point() {
46+
let (_, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r));
47+
if r_ty.peel_refs().is_floating_point() && r_ty.peel_refs().is_floating_point() {
7348
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
7449
self.expr_id = Some(expr.hir_id);
7550
}
@@ -80,17 +55,9 @@ impl Context {
8055
return;
8156
}
8257
let ty = cx.typeck_results().expr_ty(arg);
83-
if constant_simple(cx, cx.typeck_results(), expr).is_none() {
84-
if ty.is_integral() {
85-
if is_from_proc_macro(cx, expr) {
86-
return;
87-
}
88-
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
89-
self.expr_id = Some(expr.hir_id);
90-
} else if ty.is_floating_point() {
91-
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
92-
self.expr_id = Some(expr.hir_id);
93-
}
58+
if constant_simple(cx, cx.typeck_results(), expr).is_none() && ty.is_floating_point() {
59+
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
60+
self.expr_id = Some(expr.hir_id);
9461
}
9562
}
9663

Diff for: clippy_lints/src/renamed_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
1515
("clippy::eval_order_dependence", "clippy::mixed_read_write_in_expression"),
1616
("clippy::identity_conversion", "clippy::useless_conversion"),
1717
("clippy::if_let_some_result", "clippy::match_result_ok"),
18+
("clippy::integer_arithmetic", "clippy::arithmetic_side_effects"),
1819
("clippy::logic_bug", "clippy::overly_complex_bool_expr"),
1920
("clippy::new_without_default_derive", "clippy::new_without_default"),
2021
("clippy::option_and_then_some", "clippy::bind_instead_of_map"),

Diff for: tests/ui/float_arithmetic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
1+
#![warn(clippy::arithmetic_side_effects, clippy::float_arithmetic)]
22
#![allow(
33
unused,
44
clippy::shadow_reuse,

Diff for: tests/ui/integer_arithmetic.rs

-109
This file was deleted.

0 commit comments

Comments
 (0)