Skip to content

Commit d440935

Browse files
briankabiromarcin-serwin
authored andcommitted
Add lint when comparing floats in an array
Finishes rust-lang#4277
1 parent c25f26d commit d440935

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
@@ -498,8 +498,14 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
498498
false
499499
}
500500

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

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

0 commit comments

Comments
 (0)