about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarcin Serwin <toxyxer@gmail.com>2020-04-06 09:06:50 +0200
committerMarcin Serwin <toxyxer@gmail.com>2020-04-09 08:10:14 +0200
commitf637c45f8b375606fc077b4a90ef4cb35758d219 (patch)
treec753c2647c407074f2be8d3ce1fc0db26c880fc5
parent84ae3d8bc85453601066bbebba3c372df763773f (diff)
downloadrust-f637c45f8b375606fc077b4a90ef4cb35758d219.tar.gz
rust-f637c45f8b375606fc077b4a90ef4cb35758d219.zip
Indicate when arrays are compared in error message
-rw-r--r--clippy_lints/src/misc.rs21
-rw-r--r--tests/ui/float_cmp.stderr2
-rw-r--r--tests/ui/float_cmp_const.stderr2
3 files changed, 20 insertions, 5 deletions
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs
index 491cebc96ab..672fbd360d5 100644
--- a/clippy_lints/src/misc.rs
+++ b/clippy_lints/src/misc.rs
@@ -369,16 +369,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
                             return;
                         }
                     }
+                    let is_comparing_arrays = is_array(cx, left) || is_array(cx, right);
                     let (lint, msg) = if is_named_constant(cx, left) || is_named_constant(cx, right) {
-                        (FLOAT_CMP_CONST, "strict comparison of `f32` or `f64` constant")
+                        (
+                            FLOAT_CMP_CONST,
+                            if is_comparing_arrays {
+                                "strict comparison of `f32` or `f64` constant arrays"
+                            } else {
+                                "strict comparison of `f32` or `f64` constant"
+                            },
+                        )
                     } else {
-                        (FLOAT_CMP, "strict comparison of `f32` or `f64`")
+                        (
+                            FLOAT_CMP,
+                            if is_comparing_arrays {
+                                "strict comparison of `f32` or `f64` arrays"
+                            } else {
+                                "strict comparison of `f32` or `f64`"
+                            },
+                        )
                     };
                     span_lint_and_then(cx, lint, expr.span, msg, |db| {
                         let lhs = Sugg::hir(cx, left, "..");
                         let rhs = Sugg::hir(cx, right, "..");
 
-                        if !(is_array(cx, left) || is_array(cx, right)) {
+                        if !is_comparing_arrays {
                             db.span_suggestion(
                                 expr.span,
                                 "consider comparing them within some error",
diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr
index 8952caa0676..8718cd83027 100644
--- a/tests/ui/float_cmp.stderr
+++ b/tests/ui/float_cmp.stderr
@@ -47,7 +47,7 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
 LL |     NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: strict comparison of `f32` or `f64`
+error: strict comparison of `f32` or `f64` arrays
   --> $DIR/float_cmp.rs:98:5
    |
 LL |     a1 == a2;
diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr
index f93ee310785..5cdbc1d0013 100644
--- a/tests/ui/float_cmp_const.stderr
+++ b/tests/ui/float_cmp_const.stderr
@@ -83,7 +83,7 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
 LL |     v != ONE;
    |     ^^^^^^^^
 
-error: strict comparison of `f32` or `f64` constant
+error: strict comparison of `f32` or `f64` constant arrays
   --> $DIR/float_cmp_const.rs:61:5
    |
 LL |     NON_ZERO_ARRAY == NON_ZERO_ARRAY2;