Skip to content

Commit 1b1530d

Browse files
committed
Auto merge of #111818 - Urgau:uplift_cmp_nan, r=cjgillot
Uplift `clippy::cmp_nan` lint This PR aims at uplifting the `clippy::cmp_nan` lint into rustc. ## `invalid_nan_comparisons` ~~(deny-by-default)~~ (warn-by-default) The `invalid_nan_comparisons` lint checks comparison with `f32::NAN` or `f64::NAN` as one of the operand. ### Example ```rust,compile_fail let a = 2.3f32; if a == f32::NAN {} ``` ### Explanation NaN does not compare meaningfully to anything – not even itself – so those comparisons are always false. ----- Mostly followed the instructions for uplifting a clippy lint described here: rust-lang/rust#99696 (review) `@rustbot` label: +I-lang-nominated r? compiler
2 parents a786491 + 6c13e3b commit 1b1530d

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

core/src/num/f32.rs

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ impl f32 {
403403
/// and the stability of its representation over Rust versions
404404
/// and target platforms isn't guaranteed.
405405
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
406+
#[rustc_diagnostic_item = "f32_nan"]
406407
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
407408
/// Infinity (∞).
408409
#[stable(feature = "assoc_int_consts", since = "1.43.0")]

core/src/num/f64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ impl f64 {
401401
/// This constant isn't guaranteed to equal to any specific NaN bitpattern,
402402
/// and the stability of its representation over Rust versions
403403
/// and target platforms isn't guaranteed.
404+
#[rustc_diagnostic_item = "f64_nan"]
404405
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
405406
pub const NAN: f64 = 0.0_f64 / 0.0_f64;
406407
/// Infinity (∞).

0 commit comments

Comments
 (0)