about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-09-27 09:00:31 +0000
committerbors <bors@rust-lang.org>2021-09-27 09:00:31 +0000
commitf100159f8cc4809e8820c85ca013ec8d061a02ca (patch)
treeb67aa8e75f1f6c1b299a4291a1138669581ff552
parent30fe4ba1fb58c5f929dcf0f637b400a1ceb77693 (diff)
parent3ad3c51cee1d36d01fd145d6a45e33cff2bc12a1 (diff)
downloadrust-f100159f8cc4809e8820c85ca013ec8d061a02ca.tar.gz
rust-f100159f8cc4809e8820c85ca013ec8d061a02ca.zip
Auto merge of #7692 - workingjubilee:float-cmp-not-wrong, r=giraffate
Demote float_cmp to pedantic

See this issue: https://github.com/rust-lang/rust-clippy/issues/7666

This is one of the most frequently suppressed lints. It is deny-by-default. It is not actually clearly wrong, as there are many instances where direct float comparison is actually desirable. It is only after operating on floats that they may lose precision, and that depends greatly on the operation. As most correctness lints have a much higher standard of error, being based on hard and fast binary logic, this should not be amongst them.

A linter is not a substitute for observing the math carefully and running tests, and doing the desirable thing is even more likely to lead one to want exact comparisons.

changelog: Demote [`float_cmp`] from correctness to pedantic lints
-rw-r--r--clippy_lints/src/lib.rs3
-rw-r--r--clippy_lints/src/misc.rs2
2 files changed, 2 insertions, 3 deletions
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index 1a69cf0dc88..1d24d02511b 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -1134,6 +1134,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
         LintId::of(methods::INEFFICIENT_TO_STRING),
         LintId::of(methods::MAP_FLATTEN),
         LintId::of(methods::MAP_UNWRAP_OR),
+        LintId::of(misc::FLOAT_CMP),
         LintId::of(misc::USED_UNDERSCORE_BINDING),
         LintId::of(misc_early::UNSEPARATED_LITERAL_SUFFIX),
         LintId::of(mut_mut::MUT_MUT),
@@ -1368,7 +1369,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
         LintId::of(minmax::MIN_MAX),
         LintId::of(misc::CMP_NAN),
         LintId::of(misc::CMP_OWNED),
-        LintId::of(misc::FLOAT_CMP),
         LintId::of(misc::MODULO_ONE),
         LintId::of(misc::SHORT_CIRCUIT_STATEMENT),
         LintId::of(misc::TOPLEVEL_REF_ARG),
@@ -1733,7 +1733,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
         LintId::of(methods::ZST_OFFSET),
         LintId::of(minmax::MIN_MAX),
         LintId::of(misc::CMP_NAN),
-        LintId::of(misc::FLOAT_CMP),
         LintId::of(misc::MODULO_ONE),
         LintId::of(non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS),
         LintId::of(open_options::NONSENSICAL_OPEN_OPTIONS),
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs
index 538fa4e1678..0f32cd9164e 100644
--- a/clippy_lints/src/misc.rs
+++ b/clippy_lints/src/misc.rs
@@ -113,7 +113,7 @@ declare_clippy_lint! {
     /// if (y - x).abs() > error_margin { }
     /// ```
     pub FLOAT_CMP,
-    correctness,
+    pedantic,
     "using `==` or `!=` on float values instead of comparing difference with an epsilon"
 }