Skip to content

Commit

Permalink
fix HashEqLike for Box<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
gvozdvmozgu committed Jan 12, 2025
1 parent 12459c0 commit 567563e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,15 @@ where
}
}

impl<'a, T> HashEqLike<Box<T>> for &'a T
impl<'a, T> HashEqLike<&'a T> for Box<T>
where
T: ?Sized + Hash + Eq,
Box<T>: From<&'a T>,
{
fn hash<H: Hasher>(&self, h: &mut H) {
Hash::hash(self, &mut *h)
}
fn eq(&self, data: &Box<T>) -> bool {
fn eq(&self, data: &&T) -> bool {
**self == **data
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/interned-structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use expect_test::expect;
use std::path::{Path, PathBuf};
use test_log::test;

#[salsa::interned]
struct InternedBoxed<'db> {
data: Box<str>,
}

#[salsa::interned]
struct InternedString<'db> {
data: String,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 567563e

Please sign in to comment.