From cd3106d99fd95390a870622e22eef0cedbefaac9 Mon Sep 17 00:00:00 2001 From: clippered Date: Mon, 6 Nov 2017 20:02:42 +1100 Subject: [PATCH] add more negative tests --- tests/ui/float_cmp_const.rs | 13 +++++++++ tests/ui/float_cmp_const.stderr | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index 12ffb5b3301..fe69eeeed0a 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -28,4 +28,17 @@ fn main() { v > ONE; v <= ONE; v >= ONE; + + // has float_cmp warns (as expected), no float constants + let w = 1.1; + v == w; + v != w; + v == 1.0; + v != 1.0; + + // no errors, zero and infinity values + ONE != 0f32; + TWO == 0f32; + ONE != ::std::f32::INFINITY; + ONE == ::std::f32::NEG_INFINITY; } diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index 0bdbb6770dc..f8933938ed8 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -83,3 +83,52 @@ note: std::f32::EPSILON and std::f64::EPSILON are available. 24 | v != ONE; | ^^^^^^^^ +error: strict comparison of f32 or f64 + --> $DIR/float_cmp_const.rs:34:5 + | +34 | v == w; + | ^^^^^^ help: consider comparing them within some error: `(v - w).abs() < error` + | + = note: `-D float-cmp` implied by `-D warnings` +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp_const.rs:34:5 + | +34 | v == w; + | ^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp_const.rs:35:5 + | +35 | v != w; + | ^^^^^^ help: consider comparing them within some error: `(v - w).abs() < error` + | +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp_const.rs:35:5 + | +35 | v != w; + | ^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp_const.rs:36:5 + | +36 | v == 1.0; + | ^^^^^^^^ help: consider comparing them within some error: `(v - 1.0).abs() < error` + | +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp_const.rs:36:5 + | +36 | v == 1.0; + | ^^^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp_const.rs:37:5 + | +37 | v != 1.0; + | ^^^^^^^^ help: consider comparing them within some error: `(v - 1.0).abs() < error` + | +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp_const.rs:37:5 + | +37 | v != 1.0; + | ^^^^^^^^ +