Skip to content

Commit f100159

Browse files
committed
Auto merge of #7692 - workingjubilee:float-cmp-not-wrong, r=giraffate
Demote float_cmp to pedantic See this issue: #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
2 parents 30fe4ba + 3ad3c51 commit f100159

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11341134
LintId::of(methods::INEFFICIENT_TO_STRING),
11351135
LintId::of(methods::MAP_FLATTEN),
11361136
LintId::of(methods::MAP_UNWRAP_OR),
1137+
LintId::of(misc::FLOAT_CMP),
11371138
LintId::of(misc::USED_UNDERSCORE_BINDING),
11381139
LintId::of(misc_early::UNSEPARATED_LITERAL_SUFFIX),
11391140
LintId::of(mut_mut::MUT_MUT),
@@ -1368,7 +1369,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13681369
LintId::of(minmax::MIN_MAX),
13691370
LintId::of(misc::CMP_NAN),
13701371
LintId::of(misc::CMP_OWNED),
1371-
LintId::of(misc::FLOAT_CMP),
13721372
LintId::of(misc::MODULO_ONE),
13731373
LintId::of(misc::SHORT_CIRCUIT_STATEMENT),
13741374
LintId::of(misc::TOPLEVEL_REF_ARG),
@@ -1733,7 +1733,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17331733
LintId::of(methods::ZST_OFFSET),
17341734
LintId::of(minmax::MIN_MAX),
17351735
LintId::of(misc::CMP_NAN),
1736-
LintId::of(misc::FLOAT_CMP),
17371736
LintId::of(misc::MODULO_ONE),
17381737
LintId::of(non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS),
17391738
LintId::of(open_options::NONSENSICAL_OPEN_OPTIONS),

clippy_lints/src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ declare_clippy_lint! {
113113
/// if (y - x).abs() > error_margin { }
114114
/// ```
115115
pub FLOAT_CMP,
116-
correctness,
116+
pedantic,
117117
"using `==` or `!=` on float values instead of comparing difference with an epsilon"
118118
}
119119

0 commit comments

Comments
 (0)