diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 38fdabaaf7a2..2c47a93911fd 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -489,7 +489,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) { diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index 207c1bcbbc67..ff3b94c0cef1 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -77,6 +77,13 @@ fn main() { assert_eq!(a, b); // no errors + let a1: [f32; 1] = [0.0]; + let a2: [f32; 1] = [1.1]; + + assert_eq!(a1[0], a2[0]); + + assert_eq!(&a1[0], &a2[0]); + // no errors - comparing signums is ok let x32 = 3.21f32; 1.23f32.signum() == x32.signum(); diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index 116e3e90e637..a60fa743fadb 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -35,5 +35,31 @@ note: std::f32::EPSILON and std::f64::EPSILON are available. LL | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:83:5 + | +LL | assert_eq!(a1[0], a2[0]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:83:5 + | +LL | assert_eq!(a1[0], a2[0]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:85:5 + | +LL | assert_eq!(&a1[0], &a2[0]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:85:5 + | +LL | assert_eq!(&a1[0], &a2[0]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: aborting due to 5 previous errors