]> git.lizzy.rs Git - rust.git/commitdiff
Added sign check on Constant f64 PartialEq implementation
authorTaylor Cramer <cramertaylorj@gmail.com>
Wed, 13 Jul 2016 07:43:33 +0000 (00:43 -0700)
committerTaylor Cramer <cramertaylorj@gmail.com>
Wed, 13 Jul 2016 07:43:33 +0000 (00:43 -0700)
clippy_lints/src/consts.rs
tests/compile-fail/copies.rs

index b4c8521a0a9fa8accc1ebbdd5aa4b066d5191da7..d4ee76590561666cb73fd873248d1bce0c46c5e7 100644 (file)
@@ -92,7 +92,8 @@ fn eq(&self, other: &Constant) -> bool {
                 // we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
                 // `Fw32 == Fw64` so don’t compare them
                 match (ls.parse::<f64>(), rs.parse::<f64>()) {
-                    (Ok(l), Ok(r)) => l.eq(&r),
+                    (Ok(l), Ok(r)) => l.eq(&r) &&
+                        (l.is_sign_positive() == r.is_sign_positive()), // needed for 0.0 != -0.0
                     _ => false,
                 }
             }
index a8d7157629b4bfc9ed55bc8227f1046be7a20c00..66452048df4ff37cc111c3bb8e2adef8b777c64f 100644 (file)
@@ -229,6 +229,31 @@ fn if_same_then_else() -> Result<&'static str, ()> {
         _ => 0,
     };
 
+    let _ = if true {
+        //~^NOTE same as this
+        0.0
+    } else { //~ERROR this `if` has identical blocks
+        0.0
+    };
+
+    let _ = if true {
+        //~^NOTE same as this
+        -0.0
+    } else { //~ERROR this `if` has identical blocks
+        -0.0
+    };
+
+    let _ = if true {
+        0.0
+    } else {
+        -0.0
+    };
+
+    let _ = match Some(()) {
+        Some(()) => 0.0,
+        None => -0.0
+    };
+
     match (Some(42), Some("")) {
         (Some(a), None) => bar(a),
         (None, Some(a)) => bar(a), // bindings have different types