Skip to content

Commit 9a874a4

Browse files
committed
Deprecate integer_arithmetic
1 parent c976ad0 commit 9a874a4

13 files changed

+47
-360
lines changed

clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
486486
crate::operators::FLOAT_EQUALITY_WITHOUT_ABS_INFO,
487487
crate::operators::IDENTITY_OP_INFO,
488488
crate::operators::INEFFECTIVE_BIT_MASK_INFO,
489-
crate::operators::INTEGER_ARITHMETIC_INFO,
490489
crate::operators::INTEGER_DIVISION_INFO,
491490
crate::operators::MISREFACTORED_ASSIGN_OP_INFO,
492491
crate::operators::MODULO_ARITHMETIC_INFO,

clippy_lints/src/deprecated_lints.rs

+11
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,14 @@ declare_deprecated_lint! {
215215
pub WRONG_PUB_SELF_CONVENTION,
216216
"set the `avoid-breaking-exported-api` config option to `false` to enable the `wrong_self_convention` lint for public items"
217217
}
218+
219+
declare_deprecated_lint! {
220+
/// ### What it does
221+
/// Nothing. This lint has been deprecated.
222+
///
223+
/// ### Deprecation reason
224+
/// Among other things, `n.wrapping_div(0)`, detection of arbitrary types or operations with references are not supported
225+
#[clippy::version = "1.70.0"]
226+
pub INTEGER_ARITHMETIC,
227+
"use the `arithmetic_side_effects` lint instead"
228+
}

clippy_lints/src/lib.deprecated.rs

+4
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@
6767
"clippy::wrong_pub_self_convention",
6868
"set the `avoid-breaking-exported-api` config option to `false` to enable the `wrong_self_convention` lint for public items",
6969
);
70+
store.register_removed(
71+
"clippy::integer_arithmetic",
72+
"use the `arithmetic_side_effects` lint instead",
73+
);
7074
}

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,

clippy_lints/src/operators/numeric_arithmetic.rs

+4-35
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
}
@@ -81,13 +56,7 @@ impl Context {
8156
}
8257
let ty = cx.typeck_results().expr_ty(arg);
8358
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() {
59+
if ty.is_floating_point() {
9160
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
9261
self.expr_id = Some(expr.hir_id);
9362
}

tests/ui/deprecated.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
#![warn(clippy::filter_map)]
1919
#![warn(clippy::pub_enum_variant_names)]
2020
#![warn(clippy::wrong_pub_self_convention)]
21+
#![warn(clippy::integer_arithmetic)]
2122

2223
fn main() {}

tests/ui/deprecated.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,11 @@ error: lint `clippy::wrong_pub_self_convention` has been removed: set the `avoid
9696
LL | #![warn(clippy::wrong_pub_self_convention)]
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9898

99-
error: aborting due to 16 previous errors
99+
error: lint `clippy::integer_arithmetic` has been removed: use the `arithmetic_side_effects` lint instead
100+
--> $DIR/deprecated.rs:21:9
101+
|
102+
LL | #![warn(clippy::integer_arithmetic)]
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
104+
105+
error: aborting due to 17 previous errors
100106

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::float_arithmetic)]
22
#![allow(
33
unused,
44
clippy::shadow_reuse,

tests/ui/integer_arithmetic.rs

-109
This file was deleted.

0 commit comments

Comments
 (0)