Skip to content

Commit 16b4003

Browse files
committed
Split check_fn function
1 parent 7294acb commit 16b4003

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
@@ -372,30 +372,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
372372
}
373373
}
374374
let is_comparing_arrays = is_array(cx, left) || is_array(cx, right);
375-
let (lint, msg) = if is_named_constant(cx, left) || is_named_constant(cx, right) {
376-
(
377-
FLOAT_CMP_CONST,
378-
if is_comparing_arrays {
379-
"strict comparison of `f32` or `f64` constant arrays"
380-
} else {
381-
"strict comparison of `f32` or `f64` constant"
382-
},
383-
)
384-
} else {
385-
(
386-
FLOAT_CMP,
387-
if is_comparing_arrays {
388-
"strict comparison of `f32` or `f64` arrays"
389-
} else {
390-
"strict comparison of `f32` or `f64`"
391-
},
392-
)
393-
};
375+
let (lint, msg) = get_lint_and_message(
376+
is_named_constant(cx, left) || is_named_constant(cx, right),
377+
is_comparing_arrays,
378+
);
394379
span_lint_and_then(cx, lint, expr.span, msg, |db| {
395380
let lhs = Sugg::hir(cx, left, "..");
396381
let rhs = Sugg::hir(cx, right, "..");
397382

398-
if !is_comparing_arrays {
383+
if is_comparing_arrays {
384+
db.note("`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
385+
} else {
399386
db.span_suggestion(
400387
expr.span,
401388
"consider comparing them within some error",
@@ -407,8 +394,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
407394
Applicability::HasPlaceholders, // snippet
408395
);
409396
db.span_note(expr.span, "`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
410-
} else {
411-
db.note("`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
412397
}
413398
});
414399
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
@@ -461,6 +446,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
461446
}
462447
}
463448

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

0 commit comments

Comments
 (0)