From 2a0b9ae437e86be45a3f6446e32a3e19256f676e Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Tue, 2 Jan 2024 11:27:42 -0500 Subject: [PATCH 1/4] add clone to EntityHash and PassHash --- crates/bevy_utils/src/lib.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index 1689a1b849253..a4604dfcae84b 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -189,7 +189,7 @@ impl Clone for Hashed { impl Eq for Hashed {} /// A [`BuildHasher`] that results in a [`PassHasher`]. -#[derive(Default)] +#[derive(Default, Clone)] pub struct PassHash; impl BuildHasher for PassHash { @@ -251,7 +251,7 @@ impl PreHashMapExt for PreHashMap::default(); + // This should compile + let _ = map.clone(); + } + + #[test] + fn test_clone_pre_hash_map() { + let map = PreHashMap::::default(); + // This should compile + let _ = map.clone(); + } +} \ No newline at end of file From 384844b7612947a733d41b0db2d1b5a484f6a4cc Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Tue, 2 Jan 2024 11:38:35 -0500 Subject: [PATCH 2/4] format --- crates/bevy_utils/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index a4604dfcae84b..19d72ba57b245 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -416,7 +416,6 @@ macro_rules! detailed_trace { } } - #[cfg(test)] mod tests { use super::*; @@ -434,4 +433,4 @@ mod tests { // This should compile let _ = map.clone(); } -} \ No newline at end of file +} From 9fee3e5d2790ea382ffd6d53f37ddc975f88d4c4 Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Tue, 2 Jan 2024 13:14:59 -0500 Subject: [PATCH 3/4] add static assertions for type bound checks --- crates/bevy_utils/Cargo.toml | 3 +++ crates/bevy_utils/src/lib.rs | 15 ++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/crates/bevy_utils/Cargo.toml b/crates/bevy_utils/Cargo.toml index a946b76fc925e..bffdce617cc8a 100644 --- a/crates/bevy_utils/Cargo.toml +++ b/crates/bevy_utils/Cargo.toml @@ -23,6 +23,9 @@ thiserror = "1.0" nonmax = "0.5" smallvec = { version = "1.11", features = ["serde", "union", "const_generics"] } +[dev-dependencies] +static_assertions = "1.1.0" + [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.0", features = ["js"] } diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index 19d72ba57b245..453a4b5f64857 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -419,18 +419,11 @@ macro_rules! detailed_trace { #[cfg(test)] mod tests { use super::*; + use static_assertions::assert_impl_all; #[test] - fn test_clone_entity_hash_map() { - let map = EntityHashMap::::default(); - // This should compile - let _ = map.clone(); - } - - #[test] - fn test_clone_pre_hash_map() { - let map = PreHashMap::::default(); - // This should compile - let _ = map.clone(); + fn test_clone_bounds() { + assert_impl_all!(EntityHashMap::: Clone); + assert_impl_all!(PreHashMap::: Clone); } } From 4fe0ac7e785b312eb49fe2bfe1881f4a6f2359e0 Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Tue, 2 Jan 2024 14:45:33 -0500 Subject: [PATCH 4/4] address comment --- crates/bevy_utils/src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index 453a4b5f64857..aeef0b8918090 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -421,9 +421,7 @@ mod tests { use super::*; use static_assertions::assert_impl_all; - #[test] - fn test_clone_bounds() { - assert_impl_all!(EntityHashMap::: Clone); - assert_impl_all!(PreHashMap::: Clone); - } + // Check that the HashMaps are Clone if the key/values are Clone + assert_impl_all!(EntityHashMap::: Clone); + assert_impl_all!(PreHashMap::: Clone); }