rust/tests/ui/lint/invalid-nan-comparison.rs
Trevor Gross 3afbe4f9c7 Add f16 and f128 to invalid_nan_comparison
Currently `f32_nan` and `f64_nan` are used to provide the
`invalid_nan_comparison` lint. Since we have `f16_nan` and `f128_nan`,
hook these up so the new float types get the same lints.
2024-10-31 21:26:36 -05:00

98 lines
2.4 KiB
Rust

//@ check-pass
#![feature(f16, f128)]
fn main() {
f16();
f32();
f64();
f128();
}
const TEST: bool = 5f32 == f32::NAN;
//~^ WARN incorrect NaN comparison
fn f16() {
macro_rules! number { () => { 5f16 }; }
let x = number!();
x == f16::NAN;
//~^ WARN incorrect NaN comparison
x != f16::NAN;
//~^ WARN incorrect NaN comparison
x < f16::NAN;
//~^ WARN incorrect NaN comparison
x > f16::NAN;
//~^ WARN incorrect NaN comparison
x <= f16::NAN;
//~^ WARN incorrect NaN comparison
x >= f16::NAN;
//~^ WARN incorrect NaN comparison
number!() == f16::NAN;
//~^ WARN incorrect NaN comparison
f16::NAN != number!();
//~^ WARN incorrect NaN comparison
}
fn f32() {
macro_rules! number { () => { 5f32 }; }
let x = number!();
x == f32::NAN;
//~^ WARN incorrect NaN comparison
x != f32::NAN;
//~^ WARN incorrect NaN comparison
x < f32::NAN;
//~^ WARN incorrect NaN comparison
x > f32::NAN;
//~^ WARN incorrect NaN comparison
x <= f32::NAN;
//~^ WARN incorrect NaN comparison
x >= f32::NAN;
//~^ WARN incorrect NaN comparison
number!() == f32::NAN;
//~^ WARN incorrect NaN comparison
f32::NAN != number!();
//~^ WARN incorrect NaN comparison
}
fn f64() {
macro_rules! number { () => { 5f64 }; }
let x = number!();
x == f64::NAN;
//~^ WARN incorrect NaN comparison
x != f64::NAN;
//~^ WARN incorrect NaN comparison
x < f64::NAN;
//~^ WARN incorrect NaN comparison
x > f64::NAN;
//~^ WARN incorrect NaN comparison
x <= f64::NAN;
//~^ WARN incorrect NaN comparison
x >= f64::NAN;
//~^ WARN incorrect NaN comparison
number!() == f64::NAN;
//~^ WARN incorrect NaN comparison
f64::NAN != number!();
//~^ WARN incorrect NaN comparison
}
fn f128() {
macro_rules! number { () => { 5f128 }; }
let x = number!();
x == f128::NAN;
//~^ WARN incorrect NaN comparison
x != f128::NAN;
//~^ WARN incorrect NaN comparison
x < f128::NAN;
//~^ WARN incorrect NaN comparison
x > f128::NAN;
//~^ WARN incorrect NaN comparison
x <= f128::NAN;
//~^ WARN incorrect NaN comparison
x >= f128::NAN;
//~^ WARN incorrect NaN comparison
number!() == f128::NAN;
//~^ WARN incorrect NaN comparison
f128::NAN != number!();
//~^ WARN incorrect NaN comparison
}