Skip to content

Commit 5f1bb72

Browse files
briankabiromarcin-serwin
authored andcommitted
Add lint when comparing floats in an array
Finishes #4277
1 parent d8e6e4c commit 5f1bb72

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

clippy_lints/src/misc.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,14 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
500500
false
501501
}
502502

503-
fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
504-
matches!(walk_ptrs_ty(cx.tables.expr_ty(expr)).kind, ty::Float(_))
503+
fn is_float(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
504+
let value = &walk_ptrs_ty(cx.tables.expr_ty(expr)).sty;
505+
506+
if let ty::Array(arr_ty, _) = value {
507+
return matches!(arr_ty.sty, ty::Float(_));
508+
};
509+
510+
matches!(value, ty::Float(_))
505511
}
506512

507513
fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) {

0 commit comments

Comments
 (0)