Skip to content

Commit 384ea3f

Browse files
committed
rename implicit_saturating_{add,sub} and inverted_saturating_sub
1 parent 8a5dc7c commit 384ea3f

19 files changed

+172
-157
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5947,6 +5947,7 @@ Released 2018-09-13
59475947
[`allow_attributes_without_reason`]: https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason
59485948
[`almost_complete_letter_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_letter_range
59495949
[`almost_complete_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range
5950+
[`almost_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_saturating_sub
59505951
[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
59515952
[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
59525953
[`arbitrary_source_item_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering
@@ -6323,7 +6324,9 @@ Released 2018-09-13
63236324
[`manual_repeat_n`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_repeat_n
63246325
[`manual_retain`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain
63256326
[`manual_rotate`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_rotate
6327+
[`manual_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_add
63266328
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
6329+
[`manual_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_sub
63276330
[`manual_slice_fill`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_fill
63286331
[`manual_slice_size_calculation`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_size_calculation
63296332
[`manual_split_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once

clippy_lints/src/declared_lints.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
208208
crate::impl_hash_with_borrow_str_and_bytes::IMPL_HASH_BORROW_WITH_STR_AND_BYTES_INFO,
209209
crate::implicit_hasher::IMPLICIT_HASHER_INFO,
210210
crate::implicit_return::IMPLICIT_RETURN_INFO,
211-
crate::implicit_saturating_add::IMPLICIT_SATURATING_ADD_INFO,
212-
crate::implicit_saturating_sub::IMPLICIT_SATURATING_SUB_INFO,
213-
crate::implicit_saturating_sub::INVERTED_SATURATING_SUB_INFO,
214211
crate::implied_bounds_in_impls::IMPLIED_BOUNDS_IN_IMPLS_INFO,
215212
crate::incompatible_msrv::INCOMPATIBLE_MSRV_INFO,
216213
crate::inconsistent_struct_constructor::INCONSISTENT_STRUCT_CONSTRUCTOR_INFO,
@@ -315,6 +312,9 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
315312
crate::manual_rem_euclid::MANUAL_REM_EUCLID_INFO,
316313
crate::manual_retain::MANUAL_RETAIN_INFO,
317314
crate::manual_rotate::MANUAL_ROTATE_INFO,
315+
crate::manual_saturating_add::MANUAL_SATURATING_ADD_INFO,
316+
crate::manual_saturating_sub::ALMOST_SATURATING_SUB_INFO,
317+
crate::manual_saturating_sub::MANUAL_SATURATING_SUB_INFO,
318318
crate::manual_slice_size_calculation::MANUAL_SLICE_SIZE_CALCULATION_INFO,
319319
crate::manual_string_new::MANUAL_STRING_NEW_INFO,
320320
crate::manual_strip::MANUAL_STRIP_INFO,

clippy_lints/src/deprecated_lints.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ declare_with_version! { RENAMED(RENAMED_VERSION) = [
112112
("clippy::if_let_redundant_pattern_matching", "clippy::redundant_pattern_matching"),
113113
#[clippy::version = ""]
114114
("clippy::if_let_some_result", "clippy::match_result_ok"),
115+
#[clippy::version = "1.91.0"]
116+
("clippy::implicit_saturating_add", "clippy::manual_saturating_add"),
117+
#[clippy::version = "1.91.0"]
118+
("clippy::implicit_saturating_sub", "clippy::manual_saturating_sub"),
115119
#[clippy::version = ""]
116120
("clippy::incorrect_clone_impl_on_copy_type", "clippy::non_canonical_clone_impl"),
117121
#[clippy::version = ""]
@@ -128,6 +132,8 @@ declare_with_version! { RENAMED(RENAMED_VERSION) = [
128132
("clippy::invalid_ref", "invalid_value"),
129133
#[clippy::version = ""]
130134
("clippy::invalid_utf8_in_unchecked", "invalid_from_utf8_unchecked"),
135+
#[clippy::version = "1.91.0"]
136+
("clippy::inverted_saturating_sub", "clippy::almost_saturating_sub"),
131137
#[clippy::version = ""]
132138
("clippy::let_underscore_drop", "let_underscore_drop"),
133139
#[clippy::version = ""]

clippy_lints/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ mod ignored_unit_patterns;
162162
mod impl_hash_with_borrow_str_and_bytes;
163163
mod implicit_hasher;
164164
mod implicit_return;
165-
mod implicit_saturating_add;
166-
mod implicit_saturating_sub;
167165
mod implied_bounds_in_impls;
168166
mod incompatible_msrv;
169167
mod inconsistent_struct_constructor;
@@ -224,6 +222,8 @@ mod manual_range_patterns;
224222
mod manual_rem_euclid;
225223
mod manual_retain;
226224
mod manual_rotate;
225+
mod manual_saturating_add;
226+
mod manual_saturating_sub;
227227
mod manual_slice_size_calculation;
228228
mod manual_string_new;
229229
mod manual_strip;
@@ -493,7 +493,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
493493
store.register_late_pass(|_| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd));
494494
store.register_late_pass(|_| Box::new(strings::StringAdd));
495495
store.register_late_pass(|_| Box::new(implicit_return::ImplicitReturn));
496-
store.register_late_pass(move |_| Box::new(implicit_saturating_sub::ImplicitSaturatingSub::new(conf)));
496+
store.register_late_pass(move |_| Box::new(manual_saturating_sub::ManualSaturatingSub::new(conf)));
497497
store.register_late_pass(|_| Box::new(default_numeric_fallback::DefaultNumericFallback));
498498
store.register_late_pass(move |_| {
499499
Box::new(inconsistent_struct_constructor::InconsistentStructConstructor::new(
@@ -727,7 +727,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
727727
store.register_early_pass(|| Box::new(multi_assignments::MultiAssignments));
728728
store.register_late_pass(|_| Box::new(bool_to_int_with_if::BoolToIntWithIf));
729729
store.register_late_pass(|_| Box::new(box_default::BoxDefault));
730-
store.register_late_pass(|_| Box::new(implicit_saturating_add::ImplicitSaturatingAdd));
730+
store.register_late_pass(|_| Box::new(manual_saturating_add::ManualSaturatingAdd));
731731
store.register_early_pass(|| Box::new(partial_pub_fields::PartialPubFields));
732732
store.register_late_pass(|_| Box::new(missing_trait_methods::MissingTraitMethods));
733733
store.register_late_pass(|_| Box::new(from_raw_with_void_ptr::FromRawWithVoidPtr));

clippy_lints/src/implicit_saturating_add.rs renamed to clippy_lints/src/manual_saturating_add.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ declare_clippy_lint! {
3232
/// u = u.saturating_add(1);
3333
/// ```
3434
#[clippy::version = "1.66.0"]
35-
pub IMPLICIT_SATURATING_ADD,
35+
pub MANUAL_SATURATING_ADD,
3636
style,
3737
"Perform saturating addition instead of implicitly checking max bound of data type"
3838
}
39-
declare_lint_pass!(ImplicitSaturatingAdd => [IMPLICIT_SATURATING_ADD]);
39+
declare_lint_pass!(ManualSaturatingAdd => [MANUAL_SATURATING_ADD]);
4040

41-
impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
41+
impl<'tcx> LateLintPass<'tcx> for ManualSaturatingAdd {
4242
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
4343
if let ExprKind::If(cond, then, None) = expr.kind
4444
&& let Some((c, op_node, l)) = get_const(cx, cond)
@@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
8484
};
8585
span_lint_and_sugg(
8686
cx,
87-
IMPLICIT_SATURATING_ADD,
87+
MANUAL_SATURATING_ADD,
8888
expr.span,
8989
"manual saturating add detected",
9090
"use instead",

clippy_lints/src/implicit_saturating_sub.rs renamed to clippy_lints/src/manual_saturating_sub.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ declare_clippy_lint! {
4040
/// i = i.saturating_sub(1);
4141
/// ```
4242
#[clippy::version = "1.44.0"]
43-
pub IMPLICIT_SATURATING_SUB,
43+
pub MANUAL_SATURATING_SUB,
4444
style,
4545
"Perform saturating subtraction instead of implicitly checking lower bound of data type"
4646
}
@@ -70,24 +70,24 @@ declare_clippy_lint! {
7070
/// let result = a.saturating_sub(b);
7171
/// ```
7272
#[clippy::version = "1.83.0"]
73-
pub INVERTED_SATURATING_SUB,
73+
pub ALMOST_SATURATING_SUB,
7474
correctness,
7575
"Check if a variable is smaller than another one and still subtract from it even if smaller"
7676
}
7777

78-
pub struct ImplicitSaturatingSub {
78+
pub struct ManualSaturatingSub {
7979
msrv: Msrv,
8080
}
8181

82-
impl_lint_pass!(ImplicitSaturatingSub => [IMPLICIT_SATURATING_SUB, INVERTED_SATURATING_SUB]);
82+
impl_lint_pass!(ManualSaturatingSub => [MANUAL_SATURATING_SUB, ALMOST_SATURATING_SUB]);
8383

84-
impl ImplicitSaturatingSub {
84+
impl ManualSaturatingSub {
8585
pub fn new(conf: &'static Conf) -> Self {
8686
Self { msrv: conf.msrv }
8787
}
8888
}
8989

90-
impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
90+
impl<'tcx> LateLintPass<'tcx> for ManualSaturatingSub {
9191
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
9292
if expr.span.from_expansion() {
9393
return;
@@ -249,7 +249,7 @@ fn check_subtraction(
249249
);
250250
span_lint_and_sugg(
251251
cx,
252-
IMPLICIT_SATURATING_SUB,
252+
MANUAL_SATURATING_SUB,
253253
expr_span,
254254
"manual arithmetic check found",
255255
"replace it with",
@@ -265,7 +265,7 @@ fn check_subtraction(
265265
let sugg = make_binop(BinOpKind::Sub, &big_expr_sugg, &little_expr_sugg);
266266
span_lint_and_then(
267267
cx,
268-
INVERTED_SATURATING_SUB,
268+
ALMOST_SATURATING_SUB,
269269
condition_span,
270270
"inverted arithmetic check before subtraction",
271271
|diag| {
@@ -386,7 +386,7 @@ fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a Exp
386386
fn print_lint_and_sugg(cx: &LateContext<'_>, var_name: Symbol, expr: &Expr<'_>) {
387387
span_lint_and_sugg(
388388
cx,
389-
IMPLICIT_SATURATING_SUB,
389+
MANUAL_SATURATING_SUB,
390390
expr.span,
391391
"implicitly performing saturating subtraction",
392392
"try",

tests/ui/manual_abs_diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn fixme() {
8585
}
8686
}
8787

88-
#[allow(clippy::implicit_saturating_sub)]
88+
#[allow(clippy::manual_saturating_sub)]
8989
let _ = if a > b {
9090
a - b
9191
} else if a < b {

tests/ui/manual_arithmetic_check-2.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
//@no-rustfix
2-
#![warn(clippy::implicit_saturating_sub)]
2+
#![warn(clippy::manual_saturating_sub)]
33
#![allow(arithmetic_overflow)]
44

55
fn main() {
66
let a = 12u32;
77
let b = 13u32;
88

99
let result = if a > b { b - a } else { 0 };
10-
//~^ inverted_saturating_sub
10+
//~^ almost_saturating_sub
1111

1212
let result = if b < a { b - a } else { 0 };
13-
//~^ inverted_saturating_sub
13+
//~^ almost_saturating_sub
1414

1515
let result = if a > b { 0 } else { a - b };
16-
//~^ inverted_saturating_sub
16+
//~^ almost_saturating_sub
1717

1818
let result = if a >= b { 0 } else { a - b };
19-
//~^ inverted_saturating_sub
19+
//~^ almost_saturating_sub
2020

2121
let result = if b < a { 0 } else { a - b };
22-
//~^ inverted_saturating_sub
22+
//~^ almost_saturating_sub
2323

2424
let result = if b <= a { 0 } else { a - b };
25-
//~^ inverted_saturating_sub
25+
//~^ almost_saturating_sub
2626

2727
let result = if b * 2 <= a { 0 } else { a - b * 2 };
28-
//~^ inverted_saturating_sub
28+
//~^ almost_saturating_sub
2929

3030
let result = if b <= a * 2 { 0 } else { a * 2 - b };
31-
//~^ inverted_saturating_sub
31+
//~^ almost_saturating_sub
3232

3333
let result = if b + 3 <= a + 2 { 0 } else { (a + 2) - (b + 3) };
34-
//~^ inverted_saturating_sub
34+
//~^ almost_saturating_sub
3535

3636
let af = 12f32;
3737
let bf = 13f32;

tests/ui/manual_arithmetic_check-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: this subtraction underflows when `b < a`
99
|
1010
LL | let result = if a > b { b - a } else { 0 };
1111
| ^^^^^
12-
= note: `#[deny(clippy::inverted_saturating_sub)]` on by default
12+
= note: `#[deny(clippy::almost_saturating_sub)]` on by default
1313

1414
error: inverted arithmetic check before subtraction
1515
--> tests/ui/manual_arithmetic_check-2.rs:12:23

tests/ui/manual_arithmetic_check.fixed

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::implicit_saturating_sub, clippy::inverted_saturating_sub)]
1+
#![warn(clippy::manual_saturating_sub, clippy::almost_saturating_sub)]
22
#![allow(clippy::if_same_then_else)]
33

44
fn main() {
@@ -7,16 +7,16 @@ fn main() {
77
let c = 8u32;
88

99
let result = a.saturating_sub(b);
10-
//~^ implicit_saturating_sub
10+
//~^ manual_saturating_sub
1111

1212
let result = a.saturating_sub(b);
13-
//~^ implicit_saturating_sub
13+
//~^ manual_saturating_sub
1414

1515
let result = a.saturating_sub(b);
16-
//~^ implicit_saturating_sub
16+
//~^ manual_saturating_sub
1717

1818
let result = a.saturating_sub(b);
19-
//~^ implicit_saturating_sub
19+
//~^ manual_saturating_sub
2020

2121
// Should not warn!
2222
let result = if a > b { a - b } else { a - c };

0 commit comments

Comments
 (0)