Skip to content

Commit 44e3fdc

Browse files
committed
Deprecate float_cmp_const
1 parent 23cd0ad commit 44e3fdc

File tree

6 files changed

+24
-67
lines changed

6 files changed

+24
-67
lines changed

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
570570
crate::operators::ERASING_OP_INFO,
571571
crate::operators::FLOAT_ARITHMETIC_INFO,
572572
crate::operators::FLOAT_CMP_INFO,
573-
crate::operators::FLOAT_CMP_CONST_INFO,
574573
crate::operators::FLOAT_EQUALITY_WITHOUT_ABS_INFO,
575574
crate::operators::IDENTITY_OP_INFO,
576575
crate::operators::IMPOSSIBLE_COMPARISONS_INFO,

clippy_lints/src/deprecated_lints.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,14 @@ declare_deprecated_lint! {
241241
pub MISMATCHED_TARGET_OS,
242242
"this lint has been replaced by `unexpected_cfgs`"
243243
}
244+
245+
declare_deprecated_lint! {
246+
/// ### What it does
247+
/// Nothing. This lint has been deprecated.
248+
///
249+
/// ### Deprecation reason
250+
/// `float_cmp` handles this via config options
251+
#[clippy::version = "1.76.0"]
252+
pub FLOAT_CMP_CONST,
253+
"`float_cmp` handles this via config options"
254+
}

clippy_lints/src/lib.deprecated.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,8 @@
7575
"clippy::mismatched_target_os",
7676
"this lint has been replaced by `unexpected_cfgs`",
7777
);
78+
store.register_removed(
79+
"clippy::float_cmp_const",
80+
"`float_cmp` handles this via config options",
81+
);
7882
}

clippy_lints/src/operators/mod.rs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -633,70 +633,7 @@ declare_clippy_lint! {
633633

634634
declare_clippy_lint! {
635635
/// ### What it does
636-
/// Checks for (in-)equality comparisons on constant floating-point
637-
/// values (apart from zero), except in functions called `*eq*` (which probably
638-
/// implement equality for a type involving floats).
639-
///
640-
/// ### Why restrict this?
641-
/// Floating point calculations are usually imprecise, so asking if two values are *exactly*
642-
/// equal is asking for trouble because arriving at the same logical result via different
643-
/// routes (e.g. calculation versus constant) may yield different values.
644-
///
645-
/// ### Example
646-
///
647-
/// ```no_run
648-
/// let a: f64 = 1000.1;
649-
/// let b: f64 = 0.2;
650-
/// let x = a + b;
651-
/// const Y: f64 = 1000.3; // Expected value.
652-
///
653-
/// // Actual value: 1000.3000000000001
654-
/// println!("{x}");
655-
///
656-
/// let are_equal = x == Y;
657-
/// println!("{are_equal}"); // false
658-
/// ```
659-
///
660-
/// The correct way to compare floating point numbers is to define an allowed error margin. This
661-
/// may be challenging if there is no "natural" error margin to permit. Broadly speaking, there
662-
/// are two cases:
663-
///
664-
/// 1. If your values are in a known range and you can define a threshold for "close enough to
665-
/// be equal", it may be appropriate to define an absolute error margin. For example, if your
666-
/// data is "length of vehicle in centimeters", you may consider 0.1 cm to be "close enough".
667-
/// 1. If your code is more general and you do not know the range of values, you should use a
668-
/// relative error margin, accepting e.g. 0.1% of error regardless of specific values.
669-
///
670-
/// For the scenario where you can define a meaningful absolute error margin, consider using:
671-
///
672-
/// ```no_run
673-
/// let a: f64 = 1000.1;
674-
/// let b: f64 = 0.2;
675-
/// let x = a + b;
676-
/// const Y: f64 = 1000.3; // Expected value.
677-
///
678-
/// const ALLOWED_ERROR_VEHICLE_LENGTH_CM: f64 = 0.1;
679-
/// let within_tolerance = (x - Y).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM;
680-
/// println!("{within_tolerance}"); // true
681-
/// ```
682-
///
683-
/// NB! Do not use `f64::EPSILON` - while the error margin is often called "epsilon", this is
684-
/// a different use of the term that is not suitable for floating point equality comparison.
685-
/// Indeed, for the example above using `f64::EPSILON` as the allowed error would return `false`.
686-
///
687-
/// For the scenario where no meaningful absolute error can be defined, refer to
688-
/// [the floating point guide](https://www.floating-point-gui.de/errors/comparison)
689-
/// for a reference implementation of relative error based comparison of floating point values.
690-
/// `MIN_NORMAL` in the reference implementation is equivalent to `MIN_POSITIVE` in Rust.
691-
#[clippy::version = "pre 1.29.0"]
692-
pub FLOAT_CMP_CONST,
693-
restriction,
694-
"using `==` or `!=` on float constants instead of comparing difference with an allowed error"
695-
}
696-
697-
declare_clippy_lint! {
698-
/// ### What it does
699-
/// Checks for getting the remainder of integer division by one or minus
636+
/// Checks for getting the remainder of a division by one or minus
700637
/// one.
701638
///
702639
/// ### Why is this bad?
@@ -884,7 +821,6 @@ impl_lint_pass!(Operators => [
884821
INTEGER_DIVISION,
885822
CMP_OWNED,
886823
FLOAT_CMP,
887-
FLOAT_CMP_CONST,
888824
MODULO_ONE,
889825
MODULO_ARITHMETIC,
890826
NEEDLESS_BITWISE_BOOL,

tests/ui/deprecated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
#![warn(clippy::wrong_pub_self_convention)]
2121
#![warn(clippy::maybe_misused_cfg)]
2222
#![warn(clippy::mismatched_target_os)]
23+
#![warn(clippy::float_cmp_const)]
2324

2425
fn main() {}

tests/ui/deprecated.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,11 @@ error: lint `clippy::mismatched_target_os` has been removed: this lint has been
109109
LL | #![warn(clippy::mismatched_target_os)]
110110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111111

112-
error: aborting due to 18 previous errors
112+
error: lint `clippy::float_cmp_const` has been removed: `float_cmp` handles this via config options
113+
--> tests/ui/deprecated.rs:23:9
114+
|
115+
LL | #![warn(clippy::float_cmp_const)]
116+
| ^^^^^^^^^^^^^^^^^^^^^^^
117+
118+
error: aborting due to 19 previous errors
113119

0 commit comments

Comments
 (0)