From cf0c8a6aabbd0c5248d7cf86e5f7dcc256f1c286 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Tue, 5 Dec 2023 23:29:47 +0000 Subject: [PATCH 1/2] Actually check alignment BlobVec test aligned_zst --- crates/bevy_ecs/src/storage/blob_vec.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/storage/blob_vec.rs b/crates/bevy_ecs/src/storage/blob_vec.rs index 416ce2d964c5f..c496f4bf85a92 100644 --- a/crates/bevy_ecs/src/storage/blob_vec.rs +++ b/crates/bevy_ecs/src/storage/blob_vec.rs @@ -472,7 +472,7 @@ mod tests { use crate::{component::Component, ptr::OwningPtr, world::World}; use super::BlobVec; - use std::{alloc::Layout, cell::RefCell, rc::Rc}; + use std::{alloc::Layout, cell::RefCell, mem, rc::Rc}; // SAFETY: The pointer points to a valid value of type `T` and it is safe to drop this value. unsafe fn drop_ptr(x: OwningPtr<'_>) { @@ -626,7 +626,8 @@ mod tests { let mut count = 0; let mut q = world.query::<&Zst>(); - for &Zst in q.iter(&world) { + for zst in q.iter(&world) { + assert_eq!(zst as *const Zst as usize % mem::align_of::(), 0); count += 1; } From d43b896523a800174db97e223d77ddeeceb4a5a7 Mon Sep 17 00:00:00 2001 From: James Liu Date: Tue, 12 Dec 2023 18:20:01 -0800 Subject: [PATCH 2/2] Add a documenting comment to the test. --- crates/bevy_ecs/src/storage/blob_vec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_ecs/src/storage/blob_vec.rs b/crates/bevy_ecs/src/storage/blob_vec.rs index c496f4bf85a92..a63c314fd9aa8 100644 --- a/crates/bevy_ecs/src/storage/blob_vec.rs +++ b/crates/bevy_ecs/src/storage/blob_vec.rs @@ -627,6 +627,7 @@ mod tests { let mut q = world.query::<&Zst>(); for zst in q.iter(&world) { + // Ensure that the references returned are properly aligned. assert_eq!(zst as *const Zst as usize % mem::align_of::(), 0); count += 1; }