Skip to content

Commit c39ae56

Browse files
committed
Revert "Avoid invalid NaN lint machine-applicable suggestion in const context"
Reverts PR #114486 (commit 1305a43)
1 parent e3c822d commit c39ae56

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

compiler/rustc_lint/src/lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ pub(crate) enum InvalidNanComparisons {
17391739
#[diag(lint_invalid_nan_comparisons_eq_ne)]
17401740
EqNe {
17411741
#[subdiagnostic]
1742-
suggestion: Option<InvalidNanComparisonsSuggestion>,
1742+
suggestion: InvalidNanComparisonsSuggestion,
17431743
},
17441744
#[diag(lint_invalid_nan_comparisons_lt_le_gt_ge)]
17451745
LtLeGtGe,

compiler/rustc_lint/src/types.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -605,36 +605,32 @@ fn lint_nan<'tcx>(
605605
}
606606

607607
fn eq_ne(
608-
cx: &LateContext<'_>,
609608
e: &hir::Expr<'_>,
610609
l: &hir::Expr<'_>,
611610
r: &hir::Expr<'_>,
612611
f: impl FnOnce(Span, Span) -> InvalidNanComparisonsSuggestion,
613612
) -> InvalidNanComparisons {
614-
// FIXME(#72505): This suggestion can be restored if `f{32,64}::is_nan` is made const.
615-
let suggestion = (!cx.tcx.hir().is_inside_const_context(e.hir_id)).then(|| {
616-
if let Some(l_span) = l.span.find_ancestor_inside(e.span)
617-
&& let Some(r_span) = r.span.find_ancestor_inside(e.span)
618-
{
619-
f(l_span, r_span)
620-
} else {
621-
InvalidNanComparisonsSuggestion::Spanless
622-
}
623-
});
613+
let suggestion = if let Some(l_span) = l.span.find_ancestor_inside(e.span)
614+
&& let Some(r_span) = r.span.find_ancestor_inside(e.span)
615+
{
616+
f(l_span, r_span)
617+
} else {
618+
InvalidNanComparisonsSuggestion::Spanless
619+
};
624620

625621
InvalidNanComparisons::EqNe { suggestion }
626622
}
627623

628624
let lint = match binop.node {
629625
hir::BinOpKind::Eq | hir::BinOpKind::Ne if is_nan(cx, l) => {
630-
eq_ne(cx, e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion::Spanful {
626+
eq_ne(e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion::Spanful {
631627
nan_plus_binop: l_span.until(r_span),
632628
float: r_span.shrink_to_hi(),
633629
neg: (binop.node == hir::BinOpKind::Ne).then(|| r_span.shrink_to_lo()),
634630
})
635631
}
636632
hir::BinOpKind::Eq | hir::BinOpKind::Ne if is_nan(cx, r) => {
637-
eq_ne(cx, e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion::Spanful {
633+
eq_ne(e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion::Spanful {
638634
nan_plus_binop: l_span.shrink_to_hi().to(r_span),
639635
float: l_span.shrink_to_hi(),
640636
neg: (binop.node == hir::BinOpKind::Ne).then(|| l_span.shrink_to_lo()),

tests/ui/float/classify-runtime-const.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#![feature(f16_const)]
88
#![feature(f128_const)]
9-
#![feature(const_float_classify)]
109

1110
use std::hint::black_box;
1211
use std::num::FpCategory::*;

tests/ui/float/conv-bits-runtime-const.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
// This tests the float classification functions, for regular runtime code and for const evaluation.
55

6-
#![feature(const_float_classify)]
76
#![feature(f16)]
87
#![feature(f128)]
98
#![feature(f16_const)]

tests/ui/lint/invalid-nan-comparison.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | const TEST: bool = 5f32 == f32::NAN;
55
| ^^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(invalid_nan_comparisons)]` on by default
8+
help: use `f32::is_nan()` or `f64::is_nan()` instead
9+
|
10+
LL - const TEST: bool = 5f32 == f32::NAN;
11+
LL + const TEST: bool = 5f32.is_nan();
12+
|
813

914
warning: incorrect NaN comparison, NaN cannot be directly compared to itself
1015
--> $DIR/invalid-nan-comparison.rs:14:5

0 commit comments

Comments
 (0)