about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbriankabiro <briankigondu@gmail.com>2019-07-31 14:52:12 +0300
committerMarcin Serwin <toxyxer@gmail.com>2020-04-09 08:05:51 +0200
commitd4409350dc38a4ee22f86ff39f5613b37a2c5771 (patch)
treec7bb4e46a8e6322cfe5ab92cec98b7fdb800fcfb
parentc25f26d4ca8d194fd1edfda643f2c96170a85a77 (diff)
downloadrust-d4409350dc38a4ee22f86ff39f5613b37a2c5771.tar.gz
rust-d4409350dc38a4ee22f86ff39f5613b37a2c5771.zip
Add lint when comparing floats in an array
Finishes #4277
-rw-r--r--clippy_lints/src/misc.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs
index cedd15e8daf..2c451526023 100644
--- a/clippy_lints/src/misc.rs
+++ b/clippy_lints/src/misc.rs
@@ -498,8 +498,14 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
     false
 }
 
-fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
-    matches!(walk_ptrs_ty(cx.tables.expr_ty(expr)).kind, ty::Float(_))
+fn is_float(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
+    let value = &walk_ptrs_ty(cx.tables.expr_ty(expr)).sty;
+
+    if let ty::Array(arr_ty, _) = value {
+        return matches!(arr_ty.sty, ty::Float(_));
+    };
+
+    matches!(value, ty::Float(_))
 }
 
 fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) {