@@ -572,32 +572,35 @@ fn lint_nan<'tcx>(
572572 }
573573
574574 fn eq_ne (
575+ cx : & LateContext < ' _ > ,
575576 e : & hir:: Expr < ' _ > ,
576577 l : & hir:: Expr < ' _ > ,
577578 r : & hir:: Expr < ' _ > ,
578579 f : impl FnOnce ( Span , Span ) -> InvalidNanComparisonsSuggestion ,
579580 ) -> InvalidNanComparisons {
580- let suggestion =
581+ let suggestion = ( !cx . tcx . hir ( ) . is_inside_const_context ( e . hir_id ) ) . then ( || {
581582 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+ {
583585 f ( l_span, r_span)
584586 } else {
585587 InvalidNanComparisonsSuggestion :: Spanless
586- } ;
588+ }
589+ } ) ;
587590
588591 InvalidNanComparisons :: EqNe { suggestion }
589592 }
590593
591594 let lint = match binop. node {
592595 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 {
594597 nan_plus_binop : l_span. until ( r_span) ,
595598 float : r_span. shrink_to_hi ( ) ,
596599 neg : ( binop. node == hir:: BinOpKind :: Ne ) . then ( || r_span. shrink_to_lo ( ) ) ,
597600 } )
598601 }
599602 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 {
601604 nan_plus_binop : l_span. shrink_to_hi ( ) . to ( r_span) ,
602605 float : l_span. shrink_to_hi ( ) ,
603606 neg : ( binop. node == hir:: BinOpKind :: Ne ) . then ( || l_span. shrink_to_lo ( ) ) ,
0 commit comments