diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 9ed37e70a01..aac9aa3e8ef 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -162,7 +162,11 @@ fn partial_cmp(&self, other: &Constant) -> Option { (&Constant::Int(l), &Constant::Int(r)) => Some(l.cmp(&r)), (&Constant::Float(ref ls, _), &Constant::Float(ref rs, _)) => { match (ls.parse::(), rs.parse::()) { - (Ok(ref l), Ok(ref r)) => l.partial_cmp(r), + (Ok(ref l), Ok(ref r)) => match (l.partial_cmp(r), l.is_sign_positive() == r.is_sign_positive()) { + // Check for comparison of -0.0 and 0.0 + (Some(Ordering::Equal), false) => None, + (x, _) => x + }, _ => None, } } diff --git a/tests/consts.rs b/tests/consts.rs index 773b889ebff..5f5f4cb47d0 100644 --- a/tests/consts.rs +++ b/tests/consts.rs @@ -82,6 +82,12 @@ fn test_ops() { let half_any = Constant::Float("0.5".into(), FloatWidth::Any); let half32 = Constant::Float("0.5".into(), FloatWidth::F32); let half64 = Constant::Float("0.5".into(), FloatWidth::F64); + let pos_zero = Constant::Float("0.0".into(), FloatWidth::F64); + let neg_zero = Constant::Float("-0.0".into(), FloatWidth::F64); + + assert_eq!(pos_zero, pos_zero); + assert_eq!(neg_zero, neg_zero); + assert_eq!(None, pos_zero.partial_cmp(&neg_zero)); assert_eq!(half_any, half32); assert_eq!(half_any, half64);