Skip to content

Commit 4e01ca3

Browse files
committed
Split check_fn function
1 parent f637c45 commit 4e01ca3

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

clippy_lints/src/misc.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -370,30 +370,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
370370
}
371371
}
372372
let is_comparing_arrays = is_array(cx, left) || is_array(cx, right);
373-
let (lint, msg) = if is_named_constant(cx, left) || is_named_constant(cx, right) {
374-
(
375-
FLOAT_CMP_CONST,
376-
if is_comparing_arrays {
377-
"strict comparison of `f32` or `f64` constant arrays"
378-
} else {
379-
"strict comparison of `f32` or `f64` constant"
380-
},
381-
)
382-
} else {
383-
(
384-
FLOAT_CMP,
385-
if is_comparing_arrays {
386-
"strict comparison of `f32` or `f64` arrays"
387-
} else {
388-
"strict comparison of `f32` or `f64`"
389-
},
390-
)
391-
};
373+
let (lint, msg) = get_lint_and_message(
374+
is_named_constant(cx, left) || is_named_constant(cx, right),
375+
is_comparing_arrays,
376+
);
392377
span_lint_and_then(cx, lint, expr.span, msg, |db| {
393378
let lhs = Sugg::hir(cx, left, "..");
394379
let rhs = Sugg::hir(cx, right, "..");
395380

396-
if !is_comparing_arrays {
381+
if is_comparing_arrays {
382+
db.note("`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
383+
} else {
397384
db.span_suggestion(
398385
expr.span,
399386
"consider comparing them within some error",
@@ -405,8 +392,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
405392
Applicability::HasPlaceholders, // snippet
406393
);
407394
db.span_note(expr.span, "`f32::EPSILON` and `f64::EPSILON` are available.");
408-
} else {
409-
db.note("`f32::EPSILON` and `f64::EPSILON` are available.");
410395
}
411396
});
412397
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
@@ -459,6 +444,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
459444
}
460445
}
461446

447+
fn get_lint_and_message(
448+
is_comparing_constants: bool,
449+
is_comparing_arrays: bool,
450+
) -> (&'static rustc_lint::Lint, &'static str) {
451+
if is_comparing_constants {
452+
(
453+
FLOAT_CMP_CONST,
454+
if is_comparing_arrays {
455+
"strict comparison of `f32` or `f64` constant arrays"
456+
} else {
457+
"strict comparison of `f32` or `f64` constant"
458+
},
459+
)
460+
} else {
461+
(
462+
FLOAT_CMP,
463+
if is_comparing_arrays {
464+
"strict comparison of `f32` or `f64` arrays"
465+
} else {
466+
"strict comparison of `f32` or `f64`"
467+
},
468+
)
469+
}
470+
}
471+
462472
fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) {
463473
if_chain! {
464474
if !in_constant(cx, cmp_expr.hir_id);

0 commit comments

Comments
 (0)