From 51d8b6c6643abb048987bd0befdeb6f46db0f6b5 Mon Sep 17 00:00:00 2001 From: Caio Date: Thu, 8 Sep 2022 12:04:55 -0300 Subject: [PATCH] Rename the `arithmetic` lint --- CHANGELOG.md | 2 +- clippy_lints/src/lib.register_lints.rs | 2 +- clippy_lints/src/lib.register_restriction.rs | 2 +- clippy_lints/src/lib.rs | 8 ++++++-- .../{arithmetic.rs => arithmetic_side_effects.rs} | 12 ++++++------ clippy_lints/src/operators/mod.rs | 10 +++++----- clippy_lints/src/utils/conf.rs | 2 +- src/docs.rs | 2 +- .../{arithmetic.txt => arithmetic_side_effects.txt} | 2 +- tests/ui-toml/arithmetic_allowed/clippy.toml | 1 - .../arithmetic_side_effects_allowed.rs} | 2 +- .../arithmetic_side_effects_allowed/clippy.toml | 1 + .../ui-toml/toml_unknown_key/conf_unknown_key.stderr | 2 +- .../ui/{arithmetic.rs => arithmetic_side_effects.rs} | 2 +- ...thmetic.stderr => arithmetic_side_effects.stderr} | 8 ++++---- 15 files changed, 31 insertions(+), 27 deletions(-) rename clippy_lints/src/operators/{arithmetic.rs => arithmetic_side_effects.rs} (95%) rename src/docs/{arithmetic.txt => arithmetic_side_effects.txt} (91%) delete mode 100644 tests/ui-toml/arithmetic_allowed/clippy.toml rename tests/ui-toml/{arithmetic_allowed/arithmetic_allowed.rs => arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs} (89%) create mode 100644 tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml rename tests/ui/{arithmetic.rs => arithmetic_side_effects.rs} (97%) rename tests/ui/{arithmetic.stderr => arithmetic_side_effects.stderr} (63%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 257add86b..d847e4c74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 13b573bee..962e67220 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -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, diff --git a/clippy_lints/src/lib.register_restriction.rs b/clippy_lints/src/lib.register_restriction.rs index dd1e1e1a8..6eb9b3d3b 100644 --- a/clippy_lints/src/lib.register_restriction.rs +++ b/clippy_lints/src/lib.register_restriction.rs @@ -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), diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index a26e129f0..7633bf347 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -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(); diff --git a/clippy_lints/src/operators/arithmetic.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs similarity index 95% rename from clippy_lints/src/operators/arithmetic.rs rename to clippy_lints/src/operators/arithmetic_side_effects.rs index 27eef92de..83b69fbb3 100644 --- a/clippy_lints/src/operators/arithmetic.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -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; @@ -22,16 +22,16 @@ const HARD_CODED_ALLOWED: &[&str] = &[ ]; #[derive(Debug)] -pub struct Arithmetic { +pub struct ArithmeticSideEffects { allowed: FxHashSet, // Used to check whether expressions are constants, such as in enum discriminants and consts const_span: Option, expr_span: Option, } -impl_lint_pass!(Arithmetic => [ARITHMETIC]); +impl_lint_pass!(ArithmeticSideEffects => [ARITHMETIC_SIDE_EFFECTS]); -impl Arithmetic { +impl ArithmeticSideEffects { #[must_use] pub fn new(mut allowed: FxHashSet) -> Self { allowed.extend(HARD_CODED_ALLOWED.iter().copied().map(String::from)); @@ -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); } @@ -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; diff --git a/clippy_lints/src/operators/mod.rs b/clippy_lints/src/operators/mod.rs index c7b0633b7..c32b4df4f 100644 --- a/clippy_lints/src/operators/mod.rs +++ b/clippy_lints/src/operators/mod.rs @@ -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}; @@ -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! { @@ -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, diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 84e65d5fa..a8500beb2 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -208,7 +208,7 @@ define_Conf! { /// Lint: Arithmetic. /// /// Suppress checking of the passed type names. - (arithmetic_allowed: rustc_data_structures::fx::FxHashSet = <_>::default()), + (arithmetic_side_effects_allowed: rustc_data_structures::fx::FxHashSet = <_>::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. diff --git a/src/docs.rs b/src/docs.rs index 69243bf4d..f3a5048e7 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -26,7 +26,7 @@ docs! { "almost_complete_letter_range", "almost_swapped", "approx_constant", - "arithmetic", + "arithmetic_side_effects", "as_conversions", "as_underscore", "assertions_on_constants", diff --git a/src/docs/arithmetic.txt b/src/docs/arithmetic_side_effects.txt similarity index 91% rename from src/docs/arithmetic.txt rename to src/docs/arithmetic_side_effects.txt index f04125060..6c7d51a49 100644 --- a/src/docs/arithmetic.txt +++ b/src/docs/arithmetic_side_effects.txt @@ -30,4 +30,4 @@ let _n = Decimal::MAX + Decimal::MAX; ``` ### Allowed types -Custom allowed types can be specified through the "arithmetic-allowed" filter. \ No newline at end of file +Custom allowed types can be specified through the "arithmetic-side-effects-allowed" filter. \ No newline at end of file diff --git a/tests/ui-toml/arithmetic_allowed/clippy.toml b/tests/ui-toml/arithmetic_allowed/clippy.toml deleted file mode 100644 index cc40570b1..000000000 --- a/tests/ui-toml/arithmetic_allowed/clippy.toml +++ /dev/null @@ -1 +0,0 @@ -arithmetic-allowed = ["Point"] diff --git a/tests/ui-toml/arithmetic_allowed/arithmetic_allowed.rs b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs similarity index 89% rename from tests/ui-toml/arithmetic_allowed/arithmetic_allowed.rs rename to tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs index 195fabdbf..1aed09b7c 100644 --- a/tests/ui-toml/arithmetic_allowed/arithmetic_allowed.rs +++ b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs @@ -1,4 +1,4 @@ -#![warn(clippy::arithmetic)] +#![warn(clippy::arithmetic_side_effects)] use core::ops::Add; diff --git a/tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml b/tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml new file mode 100644 index 000000000..e736256f2 --- /dev/null +++ b/tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml @@ -0,0 +1 @@ +arithmetic-side-effects-allowed = ["Point"] diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index a52a0b528..f27f78d15 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -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 diff --git a/tests/ui/arithmetic.rs b/tests/ui/arithmetic_side_effects.rs similarity index 97% rename from tests/ui/arithmetic.rs rename to tests/ui/arithmetic_side_effects.rs index a9ac46e9a..f5390c746 100644 --- a/tests/ui/arithmetic.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -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}; diff --git a/tests/ui/arithmetic.stderr b/tests/ui/arithmetic_side_effects.stderr similarity index 63% rename from tests/ui/arithmetic.stderr rename to tests/ui/arithmetic_side_effects.stderr index a51cf6ba6..6c4c8bdec 100644 --- a/tests/ui/arithmetic.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -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; | ^^^^^^