@@ -572,32 +572,35 @@ fn lint_nan<'tcx>(
572
572
}
573
573
574
574
fn eq_ne (
575
+ cx : & LateContext < ' _ > ,
575
576
e : & hir:: Expr < ' _ > ,
576
577
l : & hir:: Expr < ' _ > ,
577
578
r : & hir:: Expr < ' _ > ,
578
579
f : impl FnOnce ( Span , Span ) -> InvalidNanComparisonsSuggestion ,
579
580
) -> InvalidNanComparisons {
580
- let suggestion =
581
+ let suggestion = ( !cx . tcx . hir ( ) . is_inside_const_context ( e . hir_id ) ) . then ( || {
581
582
if let Some ( l_span) = l. span . find_ancestor_inside ( e. span ) &&
582
- let Some ( r_span) = r. span . find_ancestor_inside ( e. span ) {
583
+ let Some ( r_span) = r. span . find_ancestor_inside ( e. span )
584
+ {
583
585
f ( l_span, r_span)
584
586
} else {
585
587
InvalidNanComparisonsSuggestion :: Spanless
586
- } ;
588
+ }
589
+ } ) ;
587
590
588
591
InvalidNanComparisons :: EqNe { suggestion }
589
592
}
590
593
591
594
let lint = match binop. node {
592
595
hir:: BinOpKind :: Eq | hir:: BinOpKind :: Ne if is_nan ( cx, l) => {
593
- eq_ne ( e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion :: Spanful {
596
+ eq_ne ( cx , e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion :: Spanful {
594
597
nan_plus_binop : l_span. until ( r_span) ,
595
598
float : r_span. shrink_to_hi ( ) ,
596
599
neg : ( binop. node == hir:: BinOpKind :: Ne ) . then ( || r_span. shrink_to_lo ( ) ) ,
597
600
} )
598
601
}
599
602
hir:: BinOpKind :: Eq | hir:: BinOpKind :: Ne if is_nan ( cx, r) => {
600
- eq_ne ( e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion :: Spanful {
603
+ eq_ne ( cx , e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion :: Spanful {
601
604
nan_plus_binop : l_span. shrink_to_hi ( ) . to ( r_span) ,
602
605
float : l_span. shrink_to_hi ( ) ,
603
606
neg : ( binop. node == hir:: BinOpKind :: Ne ) . then ( || l_span. shrink_to_lo ( ) ) ,
0 commit comments