@@ -372,30 +372,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
372
372
}
373
373
}
374
374
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
+ ) ;
394
379
span_lint_and_then ( cx, lint, expr. span , msg, |db| {
395
380
let lhs = Sugg :: hir ( cx, left, ".." ) ;
396
381
let rhs = Sugg :: hir ( cx, right, ".." ) ;
397
382
398
- if !is_comparing_arrays {
383
+ if is_comparing_arrays {
384
+ db. note ( "`std::f32::EPSILON` and `std::f64::EPSILON` are available." ) ;
385
+ } else {
399
386
db. span_suggestion (
400
387
expr. span ,
401
388
"consider comparing them within some error" ,
@@ -407,8 +394,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
407
394
Applicability :: HasPlaceholders , // snippet
408
395
) ;
409
396
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." ) ;
412
397
}
413
398
} ) ;
414
399
} else if op == BinOpKind :: Rem && is_integer_const ( cx, right, 1 ) {
@@ -461,6 +446,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
461
446
}
462
447
}
463
448
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
+
464
474
fn check_nan ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > , cmp_expr : & Expr < ' _ > ) {
465
475
if_chain ! {
466
476
if !in_constant( cx, cmp_expr. hir_id) ;
0 commit comments