mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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:
parent
dd14f3a477
commit
02755086e8
2 changed files with 7 additions and 13 deletions
|
@ -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"] }
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue