Support #[derive(KnownLayout)] for unsized repr(transparent) structs#2841
Support #[derive(KnownLayout)] for unsized repr(transparent) structs#2841google-labs-jules[bot] wants to merge 1 commit intomainfrom
#[derive(KnownLayout)] for unsized repr(transparent) structs#2841Conversation
Previously, `#[derive(KnownLayout)]` only supported unsized types if they were `repr(C)`. `repr(transparent)` structs with unsized fields were not supported, even though they are valid if the single non-ZST field is unsized. This change updates the derive macro to include `repr(transparent)` structs in the "complex" layout logic path. It also ensures that the shadow struct generated for layout analysis is emitted as `#[repr(C)]` instead of `#[repr(transparent)]`. This avoids `E0690` errors (strict transparent alignment rules) when fields are wrapped in `MaybeUninit` or `ManuallyDrop`, while still guaranteeing the correct layout offsets. Tests have been added to `zerocopy-derive/tests/struct_known_layout.rs`.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more at jules.google/docs. |
Support
#[derive(KnownLayout)]for unsizedrepr(transparent)structs.Updates the
KnownLayoutderive macro to handlerepr(transparent)structs similarly torepr(C)structs, enabling support for unsized types. To ensure valid compilation of the generated shadow struct (used for layout analysis), the shadow struct is emitted with#[repr(C)]when the original struct is#[repr(transparent)]. This works around strictrepr(transparent)validation rules that can be triggered byMaybeUninitwrappers while maintaining layout correctness.Fixes an issue where
#[derive(KnownLayout)]would fail or fallback to requiringSizedfor valid unsizedrepr(transparent)structs.PR created automatically by Jules for task 13518082163380290330 started by @joshlf