From f4cd024c2b6e8598911c614d2ed652486d7d09df Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sun, 5 Oct 2025 21:07:00 +0200 Subject: [PATCH] Also add align check to projection macro. --- src/macros.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 569e35907a..4261077f65 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -361,13 +361,18 @@ macro_rules! out_project { // - the case where there are unaligned fields where it would be UB to call ptr::write to // them (requiring packed structs) { - fn ensure_type(_t: &$crate::out::Out) {} - ensure_type::<$crate::out::Out<$struct>, $struct>(&$src); + fn ensure_type(_t: &$crate::out::Out) {} + ensure_type::<$struct>(&$src); } // Verify there are no duplicate struct fields. This is not strictly necessary as Out lacks // the noalias requirement, but forbidding the same field to occur multiple times would // allow both cases. The compiler will reject any struct that reuses the same identifier. const _: () = { + $( + if ::core::mem::offset_of!($struct, $field) % ::core::mem::align_of::<$fieldty>() != 0 { + panic!(concat!("unaligned field ", stringify!($field), " of struct ", stringify!($struct), ".")); + } + )* struct S { $( $field: $fieldty