From 85b65eefc3d2044805dcfb3974024e0075e9ec8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 31 Mar 2023 22:21:49 -0700 Subject: [PATCH] misc: clippy fixes --- src/value.rs | 41 +++++++++++++++++++++++++++++++++++++++-- tests/compliance.rs | 2 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/value.rs b/src/value.rs index b0eee6a..a155cf4 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,7 +1,7 @@ use std::fmt::Display; /// A specific [KDL Value](https://github.com/kdl-org/kdl/blob/main/SPEC.md#value). -#[derive(Debug, Clone, PartialEq, PartialOrd)] +#[derive(Debug, Clone, PartialOrd)] pub enum KdlValue { /// A [KDL Raw String](https://github.com/kdl-org/kdl/blob/main/SPEC.md#raw-string). RawString(String), @@ -43,9 +43,46 @@ pub enum KdlValue { impl Eq for KdlValue {} +impl PartialEq for KdlValue { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Self::RawString(l0), Self::RawString(r0)) => l0 == r0, + (Self::String(l0), Self::String(r0)) => l0 == r0, + (Self::Base2(l0), Self::Base2(r0)) => l0 == r0, + (Self::Base8(l0), Self::Base8(r0)) => l0 == r0, + (Self::Base10(l0), Self::Base10(r0)) => l0 == r0, + (Self::Base10Float(l0), Self::Base10Float(r0)) => { + let l0 = if l0 == &f64::INFINITY { + f64::MAX + } else if l0 == &f64::NEG_INFINITY { + -f64::MAX + } else if l0.is_nan() { + // We collapse NaN to 0.0 because we're evil like that. + 0.0 + } else { + *l0 + }; + let r0 = if r0 == &f64::INFINITY { + f64::MAX + } else if r0 == &f64::NEG_INFINITY { + -f64::MAX + } else if r0.is_nan() { + // We collapse NaN to 0.0 because we're evil like that. + 0.0 + } else { + *r0 + }; + l0 == r0 + } + (Self::Base16(l0), Self::Base16(r0)) => l0 == r0, + (Self::Bool(l0), Self::Bool(r0)) => l0 == r0, + _ => core::mem::discriminant(self) == core::mem::discriminant(other), + } + } +} + // NOTE: I know, I know. This is terrible and I shouldn't do it, but it's // better than not being able to hash KdlValue at all. -#[allow(clippy::derive_hash_xor_eq)] impl std::hash::Hash for KdlValue { fn hash(&self, state: &mut H) { match self { diff --git a/tests/compliance.rs b/tests/compliance.rs index 60eaddb..9012f22 100644 --- a/tests/compliance.rs +++ b/tests/compliance.rs @@ -36,7 +36,7 @@ fn validate_res(res: Result, path: &Path) -> miette::Resu .unwrap() .join("expected_kdl"); let expected_path = expected_dir.join(file_name); - let underscored = expected_dir.join(&format!("_{}", PathBuf::from(file_name).display())); + let underscored = expected_dir.join(format!("_{}", PathBuf::from(file_name).display())); if expected_path.exists() { let doc = res?; let expected =