about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/float_literal.rs2
-rw-r--r--clippy_lints/src/lib.rs3
-rw-r--r--clippy_lints/src/misc.rs2
-rw-r--r--tests/ui/excessive_precision.fixed10
-rw-r--r--tests/ui/excessive_precision.stderr32
5 files changed, 9 insertions, 40 deletions
diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs
index a3d70f31f00..1e8a5bd7d34 100644
--- a/clippy_lints/src/float_literal.rs
+++ b/clippy_lints/src/float_literal.rs
@@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
                             Applicability::MachineApplicable,
                         );
                     }
-                } else if digits > max as usize && sym_str != float_str {
+                } else if digits > max as usize && float_str.len() < sym_str.len() {
                     span_lint_and_sugg(
                         cx,
                         EXCESSIVE_PRECISION,
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"
 }
 
diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed
index bf0325fec79..90376620a9f 100644
--- a/tests/ui/excessive_precision.fixed
+++ b/tests/ui/excessive_precision.fixed
@@ -17,8 +17,8 @@ fn main() {
     const BAD32_3: f32 = 0.1;
     const BAD32_EDGE: f32 = 1.000_001;
 
-    const BAD64_1: f64 = 0.123_456_789_012_345_66_f64;
-    const BAD64_2: f64 = 0.123_456_789_012_345_66;
+    const BAD64_1: f64 = 0.123_456_789_012_345_67f64;
+    const BAD64_2: f64 = 0.123_456_789_012_345_67;
     const BAD64_3: f64 = 0.1;
 
     // Literal as param
@@ -37,9 +37,9 @@ fn main() {
     let bad32_suf: f32 = 1.123_456_8_f32;
     let bad32_inf = 1.123_456_8_f32;
 
-    let bad64: f64 = 0.123_456_789_012_345_66;
-    let bad64_suf: f64 = 0.123_456_789_012_345_66_f64;
-    let bad64_inf = 0.123_456_789_012_345_66;
+    let bad64: f64 = 0.123_456_789_012_345_67;
+    let bad64_suf: f64 = 0.123_456_789_012_345_67f64;
+    let bad64_inf = 0.123_456_789_012_345_67;
 
     // Vectors
     let good_vec32: Vec<f32> = vec![0.123_456];
diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr
index 599773f2f70..e59c20c30b4 100644
--- a/tests/ui/excessive_precision.stderr
+++ b/tests/ui/excessive_precision.stderr
@@ -25,18 +25,6 @@ LL |     const BAD32_EDGE: f32 = 1.000_000_9;
    |                             ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001`
 
 error: float has excessive precision
-  --> $DIR/excessive_precision.rs:20:26
-   |
-LL |     const BAD64_1: f64 = 0.123_456_789_012_345_67f64;
-   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66_f64`
-
-error: float has excessive precision
-  --> $DIR/excessive_precision.rs:21:26
-   |
-LL |     const BAD64_2: f64 = 0.123_456_789_012_345_67;
-   |                          ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
-
-error: float has excessive precision
   --> $DIR/excessive_precision.rs:22:26
    |
 LL |     const BAD64_3: f64 = 0.100_000_000_000_000_000_1;
@@ -67,24 +55,6 @@ LL |     let bad32_inf = 1.123_456_789_f32;
    |                     ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32`
 
 error: float has excessive precision
-  --> $DIR/excessive_precision.rs:40:22
-   |
-LL |     let bad64: f64 = 0.123_456_789_012_345_67;
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
-
-error: float has excessive precision
-  --> $DIR/excessive_precision.rs:41:26
-   |
-LL |     let bad64_suf: f64 = 0.123_456_789_012_345_67f64;
-   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66_f64`
-
-error: float has excessive precision
-  --> $DIR/excessive_precision.rs:42:21
-   |
-LL |     let bad64_inf = 0.123_456_789_012_345_67;
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
-
-error: float has excessive precision
   --> $DIR/excessive_precision.rs:48:36
    |
 LL |     let bad_vec32: Vec<f32> = vec![0.123_456_789];
@@ -108,5 +78,5 @@ error: float has excessive precision
 LL |     let bad_bige32: f32 = 1.123_456_788_888E-10;
    |                           ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10`
 
-error: aborting due to 18 previous errors
+error: aborting due to 13 previous errors