diff --git a/zerocopy-derive/tests/struct_no_cell.rs b/zerocopy-derive/tests/struct_no_cell.rs index 2b1857cced..22a8f70943 100644 --- a/zerocopy-derive/tests/struct_no_cell.rs +++ b/zerocopy-derive/tests/struct_no_cell.rs @@ -103,3 +103,31 @@ where T: 'a + 'b + imp::Immutable; util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::Immutable); + +// Regression test for #2445: Fuchsia has `repr(C)` packet types with a large +// computed array field, and they should still be `Immutable`. +const FX_LOG_MAX_DATAGRAM_LEN: usize = 2032; + +#[derive(imp::Immutable)] +#[zerocopy(crate = "zerocopy_renamed")] +#[repr(C)] +struct FxLogMetadata { + pid: u64, + tid: u64, + time: i64, + severity: i32, + dropped_logs: u32, +} + +const FX_LOG_METADATA_SIZE: usize = imp::core::mem::size_of::(); + +#[derive(imp::Immutable)] +#[zerocopy(crate = "zerocopy_renamed")] +#[repr(C)] +struct FxLogPacket { + metadata: FxLogMetadata, + data: [u8; FX_LOG_MAX_DATAGRAM_LEN - FX_LOG_METADATA_SIZE], +} + +util_assert_impl_all!(FxLogMetadata: imp::Immutable); +util_assert_impl_all!(FxLogPacket: imp::Immutable); diff --git a/zerocopy-derive/tests/struct_to_bytes.rs b/zerocopy-derive/tests/struct_to_bytes.rs index 40fa2e5a91..eca3df1068 100644 --- a/zerocopy-derive/tests/struct_to_bytes.rs +++ b/zerocopy-derive/tests/struct_to_bytes.rs @@ -227,3 +227,31 @@ pub struct IndexEntry { util_assert_impl_all!(IndexEntry<0>: imp::IntoBytes); util_assert_impl_all!(IndexEntry<1>: imp::IntoBytes); + +// Regression test for #2445: Fuchsia has `repr(C)` packet types with a large +// computed array field, and they should still be serializable with zerocopy. +const FX_LOG_MAX_DATAGRAM_LEN: usize = 2032; + +#[derive(imp::IntoBytes)] +#[zerocopy(crate = "zerocopy_renamed")] +#[repr(C)] +struct FxLogMetadata { + pid: u64, + tid: u64, + time: i64, + severity: i32, + dropped_logs: u32, +} + +const FX_LOG_METADATA_SIZE: usize = imp::core::mem::size_of::(); + +#[derive(imp::IntoBytes)] +#[zerocopy(crate = "zerocopy_renamed")] +#[repr(C)] +struct FxLogPacket { + metadata: FxLogMetadata, + data: [u8; FX_LOG_MAX_DATAGRAM_LEN - FX_LOG_METADATA_SIZE], +} + +util_assert_impl_all!(FxLogMetadata: imp::IntoBytes); +util_assert_impl_all!(FxLogPacket: imp::IntoBytes);