]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/float_cmp_const.rs
iterate List by value
[rust.git] / tests / ui / float_cmp_const.rs
index 7cca1df65aedb36af10342842fdf2494f8207ffd..dfc025558a2f430b35b1624b6cd37c5263dc76c4 100644 (file)
@@ -1,15 +1,4 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-
-
+// does not test any rustfixable lints
 
 #![warn(clippy::float_cmp_const)]
 #![allow(clippy::float_cmp)]
@@ -19,7 +8,11 @@
 const TWO: f32 = 2.0;
 
 fn eq_one(x: f32) -> bool {
-    if x.is_nan() { false } else { x == ONE } // no error, inside "eq" fn
+    if x.is_nan() {
+        false
+    } else {
+        x == ONE
+    } // no error, inside "eq" fn
 }
 
 fn main() {
@@ -28,7 +21,8 @@ fn main() {
     TWO == ONE;
     TWO != ONE;
     ONE + ONE == TWO;
-    1 as f32 == ONE;
+    let x = 1;
+    x as f32 == ONE;
 
     let v = 0.9;
     v == ONE;
@@ -43,8 +37,8 @@ fn main() {
     // no errors, zero and infinity values
     ONE != 0f32;
     TWO == 0f32;
-    ONE != ::std::f32::INFINITY;
-    ONE == ::std::f32::NEG_INFINITY;
+    ONE != f32::INFINITY;
+    ONE == f32::NEG_INFINITY;
 
     // no errors, but will warn clippy::float_cmp if '#![allow(float_cmp)]' above is removed
     let w = 1.1;
@@ -52,4 +46,17 @@ fn main() {
     v != w;
     v == 1.0;
     v != 1.0;
+
+    const ZERO_ARRAY: [f32; 3] = [0.0, 0.0, 0.0];
+    const ZERO_INF_ARRAY: [f32; 3] = [0.0, ::std::f32::INFINITY, ::std::f32::NEG_INFINITY];
+    const NON_ZERO_ARRAY: [f32; 3] = [0.0, 0.1, 0.2];
+    const NON_ZERO_ARRAY2: [f32; 3] = [0.2, 0.1, 0.0];
+
+    // no errors, zero and infinity values
+    NON_ZERO_ARRAY[0] == NON_ZERO_ARRAY2[1]; // lhs is 0.0
+    ZERO_ARRAY == NON_ZERO_ARRAY; // lhs is all zeros
+    ZERO_INF_ARRAY == NON_ZERO_ARRAY; // lhs is all zeros or infinities
+
+    // has errors
+    NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
 }