Add static assertions to bevy_utils for compile-time checks (#11182)

# Objective

- We want to use `static_assertions` to perform precise compile time
checks at testing time. In this PR, we add those checks to make sure
that `EntityHashMap` and `PreHashMap` are `Clone` (and we replace the
more clumsy previous tests)
- Fixes #11181 

(will need to be rebased once
https://github.com/bevyengine/bevy/pull/11178 is merged)

---------

Co-authored-by: Charles Bournhonesque <cbournhonesque@snapchat.com>
This commit is contained in:
Charles Bournhonesque 2024-01-02 17:08:30 -05:00 committed by GitHub
parent dd14f3a477
commit 02755086e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 13 deletions

View file

@ -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"] }

View file

@ -419,18 +419,9 @@ 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::<u64, usize>::default();
// This should compile
let _ = map.clone();
}
#[test]
fn test_clone_pre_hash_map() {
let map = PreHashMap::<u64, usize>::default();
// This should compile
let _ = map.clone();
}
// Check that the HashMaps are Clone if the key/values are Clone
assert_impl_all!(EntityHashMap::<u64, usize>: Clone);
assert_impl_all!(PreHashMap::<u64, usize>: Clone);
}