From 11197c507c8f64c267bcbb96f6d37af2278970b2 Mon Sep 17 00:00:00 2001 From: briankabiro Date: Wed, 31 Jul 2019 14:52:12 +0300 Subject: [PATCH] Add lint when comparing floats in an array Finishes #4277 --- clippy_lints/src/misc.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index d89f886a39b3..64aff1b5553b 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -519,7 +519,13 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { } fn is_float(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { - matches!(walk_ptrs_ty(cx.tables.expr_ty(expr)).sty, ty::Float(_)) + 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) {