@@ -370,30 +370,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
370
370
}
371
371
}
372
372
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
+ ) ;
392
377
span_lint_and_then ( cx, lint, expr. span , msg, |db| {
393
378
let lhs = Sugg :: hir ( cx, left, ".." ) ;
394
379
let rhs = Sugg :: hir ( cx, right, ".." ) ;
395
380
396
- if !is_comparing_arrays {
381
+ if is_comparing_arrays {
382
+ db. note ( "`std::f32::EPSILON` and `std::f64::EPSILON` are available." ) ;
383
+ } else {
397
384
db. span_suggestion (
398
385
expr. span ,
399
386
"consider comparing them within some error" ,
@@ -405,8 +392,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
405
392
Applicability :: HasPlaceholders , // snippet
406
393
) ;
407
394
db. span_note ( expr. span , "`f32::EPSILON` and `f64::EPSILON` are available." ) ;
408
- } else {
409
- db. note ( "`f32::EPSILON` and `f64::EPSILON` are available." ) ;
410
395
}
411
396
} ) ;
412
397
} else if op == BinOpKind :: Rem && is_integer_const ( cx, right, 1 ) {
@@ -459,6 +444,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
459
444
}
460
445
}
461
446
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
+
462
472
fn check_nan ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > , cmp_expr : & Expr < ' _ > ) {
463
473
if_chain ! {
464
474
if !in_constant( cx, cmp_expr. hir_id) ;
0 commit comments