fix HashEqLike for Box<T>

This commit is contained in:
gvozdvmozgu 2025-01-11 21:26:26 -08:00
parent 12459c0a9c
commit 567563e131
2 changed files with 17 additions and 2 deletions

View file

@ -392,7 +392,7 @@ where
} }
} }
impl<'a, T> HashEqLike<Box<T>> for &'a T impl<'a, T> HashEqLike<&'a T> for Box<T>
where where
T: ?Sized + Hash + Eq, T: ?Sized + Hash + Eq,
Box<T>: From<&'a T>, Box<T>: From<&'a T>,
@ -400,7 +400,7 @@ where
fn hash<H: Hasher>(&self, h: &mut H) { fn hash<H: Hasher>(&self, h: &mut H) {
Hash::hash(self, &mut *h) Hash::hash(self, &mut *h)
} }
fn eq(&self, data: &Box<T>) -> bool { fn eq(&self, data: &&T) -> bool {
**self == **data **self == **data
} }
} }

View file

@ -5,6 +5,11 @@ use expect_test::expect;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use test_log::test; use test_log::test;
#[salsa::interned]
struct InternedBoxed<'db> {
data: Box<str>,
}
#[salsa::interned] #[salsa::interned]
struct InternedString<'db> { struct InternedString<'db> {
data: String, data: String,
@ -73,6 +78,16 @@ fn interning_returns_equal_keys_for_equal_data_multi_field() {
assert_ne!(s1, new); assert_ne!(s1, new);
} }
#[test]
fn interning_boxed() {
let db = salsa::DatabaseImpl::new();
assert_eq!(
InternedBoxed::new(&db, "Hello"),
InternedBoxed::new(&db, Box::from("Hello"))
);
}
#[test] #[test]
fn interning_vec() { fn interning_vec() {
let db = salsa::DatabaseImpl::new(); let db = salsa::DatabaseImpl::new();