Also add align check to projection macro.

This commit is contained in:
4lDO2
2025-10-05 21:07:00 +02:00
parent 24cf96393c
commit f4cd024c2b
+7 -2
View File
@@ -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, U: $crate::out::OutProject>(_t: &$crate::out::Out<U>) {}
ensure_type::<$crate::out::Out<$struct>, $struct>(&$src);
fn ensure_type<U: $crate::out::OutProject>(_t: &$crate::out::Out<U>) {}
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