Skip to content

Commit acf1e55

Browse files
authored
Output test derive(IntoBytes) on structs with trailing slices (#2678)
Makes progress towards #1112
1 parent 3f8a5a7 commit acf1e55

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

zerocopy-derive/src/output_tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,50 @@ fn test_into_bytes_struct() {
484484
}
485485
} no_build
486486
}
487+
488+
test! {
489+
IntoBytes {
490+
#[repr(C)]
491+
struct Foo {
492+
a: u8,
493+
b: [Trailing],
494+
}
495+
} expands to {
496+
#[allow(deprecated)]
497+
#[automatically_derived]
498+
unsafe impl ::zerocopy::IntoBytes for Foo
499+
where
500+
u8: ::zerocopy::IntoBytes,
501+
[Trailing]: ::zerocopy::IntoBytes,
502+
(): ::zerocopy::util::macro_util::PaddingFree<
503+
Self,
504+
{ ::zerocopy::struct_has_padding!(Self, [u8, [Trailing]]) },
505+
>,
506+
{
507+
fn only_derive_is_allowed_to_implement_this_trait() {}
508+
}
509+
} no_build
510+
}
511+
512+
test! {
513+
IntoBytes {
514+
#[repr(C)]
515+
struct Foo<Trailing> {
516+
a: u8,
517+
b: [Trailing],
518+
}
519+
} expands to {
520+
#[allow(deprecated)]
521+
#[automatically_derived]
522+
unsafe impl<Trailing> ::zerocopy::IntoBytes for Foo<Trailing>
523+
where
524+
u8: ::zerocopy::IntoBytes + ::zerocopy::Unaligned,
525+
[Trailing]: ::zerocopy::IntoBytes + ::zerocopy::Unaligned,
526+
{
527+
fn only_derive_is_allowed_to_implement_this_trait() {}
528+
}
529+
} no_build
530+
}
487531
}
488532

489533
#[test]

0 commit comments

Comments
 (0)