diff --git a/src/interned.rs b/src/interned.rs index 2396e0ef..b1c04aa1 100644 --- a/src/interned.rs +++ b/src/interned.rs @@ -392,7 +392,7 @@ where } } -impl<'a, T> HashEqLike> for &'a T +impl<'a, T> HashEqLike<&'a T> for Box where T: ?Sized + Hash + Eq, Box: From<&'a T>, @@ -400,7 +400,7 @@ where fn hash(&self, h: &mut H) { Hash::hash(self, &mut *h) } - fn eq(&self, data: &Box) -> bool { + fn eq(&self, data: &&T) -> bool { **self == **data } } diff --git a/tests/interned-structs.rs b/tests/interned-structs.rs index 70dbc263..a8263ce3 100644 --- a/tests/interned-structs.rs +++ b/tests/interned-structs.rs @@ -5,6 +5,11 @@ use expect_test::expect; use std::path::{Path, PathBuf}; use test_log::test; +#[salsa::interned] +struct InternedBoxed<'db> { + data: Box, +} + #[salsa::interned] struct InternedString<'db> { data: String, @@ -73,6 +78,16 @@ fn interning_returns_equal_keys_for_equal_data_multi_field() { 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] fn interning_vec() { let db = salsa::DatabaseImpl::new();