diff --git a/crates/oxc_span/src/atom.rs b/crates/oxc_span/src/atom.rs index 9d6ba3f15e628..40e5f42ec5e6a 100644 --- a/crates/oxc_span/src/atom.rs +++ b/crates/oxc_span/src/atom.rs @@ -297,6 +297,18 @@ impl PartialEq for &str { } } +impl PartialEq for str { + fn eq(&self, other: &CompactStr) -> bool { + self == other.as_str() + } +} + +impl PartialEq for CompactStr { + fn eq(&self, other: &str) -> bool { + self.as_str() == other + } +} + impl Index for CompactStr { type Output = str; @@ -332,3 +344,17 @@ impl Serialize for CompactStr { serializer.serialize_str(self.as_str()) } } + +#[cfg(test)] +mod test { + use super::CompactStr; + + #[test] + fn test_compactstr_eq() { + let foo = CompactStr::new("foo"); + assert_eq!(foo, "foo"); + assert_eq!(&foo, "foo"); + assert_eq!("foo", foo); + assert_eq!("foo", &foo); + } +}