@@ -343,8 +343,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
343
343
ExprKind :: Binary ( ref cmp, ref left, ref right) => {
344
344
let op = cmp. node ;
345
345
if op. is_comparison ( ) {
346
- check_nan ( cx, left, expr. span ) ;
347
- check_nan ( cx, right, expr. span ) ;
346
+ check_nan ( cx, left, expr) ;
347
+ check_nan ( cx, right, expr) ;
348
348
check_to_owned ( cx, left, right) ;
349
349
check_to_owned ( cx, right, left) ;
350
350
}
@@ -440,21 +440,25 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
440
440
}
441
441
}
442
442
443
- fn check_nan ( cx : & LateContext < ' _ , ' _ > , expr : & Expr , cmp_span : Span ) {
444
- if let Some ( ( value, _) ) = constant ( cx, cx. tables , expr) {
445
- let needs_lint = match value {
446
- Constant :: F32 ( num) => num. is_nan ( ) ,
447
- Constant :: F64 ( num) => num. is_nan ( ) ,
448
- _ => false ,
449
- } ;
443
+ fn check_nan ( cx : & LateContext < ' _ , ' _ > , expr : & Expr , cmp_expr : & Expr ) {
444
+ if_chain ! {
445
+ if !in_constant( cx, cmp_expr. hir_id) ;
446
+ if let Some ( ( value, _) ) = constant( cx, cx. tables, expr) ;
447
+ then {
448
+ let needs_lint = match value {
449
+ Constant :: F32 ( num) => num. is_nan( ) ,
450
+ Constant :: F64 ( num) => num. is_nan( ) ,
451
+ _ => false ,
452
+ } ;
450
453
451
- if needs_lint {
452
- span_lint (
453
- cx,
454
- CMP_NAN ,
455
- cmp_span,
456
- "doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead" ,
457
- ) ;
454
+ if needs_lint {
455
+ span_lint(
456
+ cx,
457
+ CMP_NAN ,
458
+ cmp_expr. span,
459
+ "doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead" ,
460
+ ) ;
461
+ }
458
462
}
459
463
}
460
464
}
0 commit comments