From 8907cbc0b864c6c4dca3534bf494d25a038fa7f0 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Wed, 13 Jul 2016 00:43:33 -0700 Subject: [PATCH] Added sign check on Constant f64 PartialEq implementation --- clippy_lints/src/consts.rs | 3 ++- tests/compile-fail/copies.rs | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index b4c8521a0a9f..d4ee76590561 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -92,7 +92,8 @@ impl PartialEq for Constant { // we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have // `Fw32 == Fw64` so don’t compare them match (ls.parse::(), rs.parse::()) { - (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, } } diff --git a/tests/compile-fail/copies.rs b/tests/compile-fail/copies.rs index a8d7157629b4..66452048df4f 100644 --- a/tests/compile-fail/copies.rs +++ b/tests/compile-fail/copies.rs @@ -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