Skip to content

Commit

Permalink
Auto merge of #9443 - c410-f3r:arith, r=flip1995
Browse files Browse the repository at this point in the history
Rename the arithmetic lint

changelog: Rename the `arithmetic` lint
  • Loading branch information
bors committed Sep 8, 2022
2 parents b30c5c0 + 51d8b6c commit 1f92c9d
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3583,7 +3583,7 @@ Released 2018-09-13
[`almost_complete_letter_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_letter_range
[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
[`arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic
[`arithmetic_side_effects`]: https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects
[`as_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_conversions
[`as_underscore`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_underscore
[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ store.register_lints(&[
octal_escapes::OCTAL_ESCAPES,
only_used_in_recursion::ONLY_USED_IN_RECURSION,
operators::ABSURD_EXTREME_COMPARISONS,
operators::ARITHMETIC,
operators::ARITHMETIC_SIDE_EFFECTS,
operators::ASSIGN_OP_PATTERN,
operators::BAD_BIT_MASK,
operators::CMP_NAN,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_restriction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ store.register_group(true, "clippy::restriction", Some("clippy_restriction"), ve
LintId::of(mixed_read_write_in_expression::MIXED_READ_WRITE_IN_EXPRESSION),
LintId::of(module_style::MOD_MODULE_FILES),
LintId::of(module_style::SELF_NAMED_MODULE_FILES),
LintId::of(operators::ARITHMETIC),
LintId::of(operators::ARITHMETIC_SIDE_EFFECTS),
LintId::of(operators::FLOAT_ARITHMETIC),
LintId::of(operators::FLOAT_CMP_CONST),
LintId::of(operators::INTEGER_ARITHMETIC),
Expand Down
8 changes: 6 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,12 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| Box::new(utils::internal_lints::MsrvAttrImpl));
}

let arithmetic_allowed = conf.arithmetic_allowed.clone();
store.register_late_pass(move || Box::new(operators::arithmetic::Arithmetic::new(arithmetic_allowed.clone())));
let arithmetic_side_effects_allowed = conf.arithmetic_side_effects_allowed.clone();
store.register_late_pass(move || {
Box::new(operators::arithmetic_side_effects::ArithmeticSideEffects::new(
arithmetic_side_effects_allowed.clone(),
))
});
store.register_late_pass(|| Box::new(utils::dump_hir::DumpHir));
store.register_late_pass(|| Box::new(utils::author::Author));
let await_holding_invalid_types = conf.await_holding_invalid_types.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clippy::match_same_arms
)]

use super::ARITHMETIC;
use super::ARITHMETIC_SIDE_EFFECTS;
use clippy_utils::{consts::constant_simple, diagnostics::span_lint};
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashSet;
Expand All @@ -22,16 +22,16 @@ const HARD_CODED_ALLOWED: &[&str] = &[
];

#[derive(Debug)]
pub struct Arithmetic {
pub struct ArithmeticSideEffects {
allowed: FxHashSet<String>,
// Used to check whether expressions are constants, such as in enum discriminants and consts
const_span: Option<Span>,
expr_span: Option<Span>,
}

impl_lint_pass!(Arithmetic => [ARITHMETIC]);
impl_lint_pass!(ArithmeticSideEffects => [ARITHMETIC_SIDE_EFFECTS]);

impl Arithmetic {
impl ArithmeticSideEffects {
#[must_use]
pub fn new(mut allowed: FxHashSet<String>) -> Self {
allowed.extend(HARD_CODED_ALLOWED.iter().copied().map(String::from));
Expand Down Expand Up @@ -83,7 +83,7 @@ impl Arithmetic {
}

fn issue_lint(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
span_lint(cx, ARITHMETIC, expr.span, "arithmetic detected");
span_lint(cx, ARITHMETIC_SIDE_EFFECTS, expr.span, "arithmetic detected");
self.expr_span = Some(expr.span);
}

Expand Down Expand Up @@ -125,7 +125,7 @@ impl Arithmetic {
}
}

impl<'tcx> LateLintPass<'tcx> for Arithmetic {
impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
if self.expr_span.is_some() || self.const_span.map_or(false, |sp| sp.contains(expr.span)) {
return;
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/operators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod ptr_eq;
mod self_assignment;
mod verbose_bit_mask;

pub(crate) mod arithmetic;
pub(crate) mod arithmetic_side_effects;

use rustc_hir::{Body, Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -92,11 +92,11 @@ declare_clippy_lint! {
/// ```
///
/// ### Allowed types
/// Custom allowed types can be specified through the "arithmetic-allowed" filter.
/// Custom allowed types can be specified through the "arithmetic-side-effects-allowed" filter.
#[clippy::version = "1.64.0"]
pub ARITHMETIC,
pub ARITHMETIC_SIDE_EFFECTS,
restriction,
"any arithmetic expression that could overflow or panic"
"any arithmetic expression that can cause side effects like overflows or panics"
}

declare_clippy_lint! {
Expand Down Expand Up @@ -789,7 +789,7 @@ pub struct Operators {
}
impl_lint_pass!(Operators => [
ABSURD_EXTREME_COMPARISONS,
ARITHMETIC,
ARITHMETIC_SIDE_EFFECTS,
INTEGER_ARITHMETIC,
FLOAT_ARITHMETIC,
ASSIGN_OP_PATTERN,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ define_Conf! {
/// Lint: Arithmetic.
///
/// Suppress checking of the passed type names.
(arithmetic_allowed: rustc_data_structures::fx::FxHashSet<String> = <_>::default()),
(arithmetic_side_effects_allowed: rustc_data_structures::fx::FxHashSet<String> = <_>::default()),
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UNUSED_SELF, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX.
///
/// Suppress lints whenever the suggested change would cause breakage for other crates.
Expand Down
2 changes: 1 addition & 1 deletion src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ docs! {
"almost_complete_letter_range",
"almost_swapped",
"approx_constant",
"arithmetic",
"arithmetic_side_effects",
"as_conversions",
"as_underscore",
"assertions_on_constants",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ let _n = Decimal::MAX + Decimal::MAX;
```

### Allowed types
Custom allowed types can be specified through the "arithmetic-allowed" filter.
Custom allowed types can be specified through the "arithmetic-side-effects-allowed" filter.
1 change: 0 additions & 1 deletion tests/ui-toml/arithmetic_allowed/clippy.toml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![warn(clippy::arithmetic)]
#![warn(clippy::arithmetic_side_effects)]

use core::ops::Add;

Expand Down
1 change: 1 addition & 0 deletions tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
arithmetic-side-effects-allowed = ["Point"]
2 changes: 1 addition & 1 deletion tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie
allow-expect-in-tests
allow-unwrap-in-tests
allowed-scripts
arithmetic-allowed
arithmetic-side-effects-allowed
array-size-threshold
avoid-breaking-exported-api
await-holding-invalid-types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::assign_op_pattern, clippy::unnecessary_owned_empty_strings)]
#![feature(inline_const, saturating_int_impl)]
#![warn(clippy::arithmetic)]
#![warn(clippy::arithmetic_side_effects)]

use core::num::{Saturating, Wrapping};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error: arithmetic detected
--> $DIR/arithmetic.rs:50:21
--> $DIR/arithmetic_side_effects.rs:50:21
|
LL | let mut _a = 1; _a += 1;
| ^^^^^^^
|
= note: `-D clippy::arithmetic` implied by `-D warnings`
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`

error: arithmetic detected
--> $DIR/arithmetic.rs:52:26
--> $DIR/arithmetic_side_effects.rs:52:26
|
LL | let mut _b = 1; _b = _b + 1;
| ^^^^^^

error: arithmetic detected
--> $DIR/arithmetic.rs:54:26
--> $DIR/arithmetic_side_effects.rs:54:26
|
LL | let mut _c = 1; _c = 1 + _c;
| ^^^^^^
Expand Down

0 comments on commit 1f92c9d

Please sign in to comment.