Skip to content

[derive] Use parent visibility for KnownLayout field helper structs - #3569

Closed
apasel422 wants to merge 1 commit into
google:mainfrom
apasel422:fix-knownlayout-field-visibility
Closed

[derive] Use parent visibility for KnownLayout field helper structs#3569
apasel422 wants to merge 1 commit into
google:mainfrom
apasel422:fix-knownlayout-field-visibility

Conversation

@apasel422

@apasel422 apasel422 commented Aug 24, 2026

Copy link
Copy Markdown

The KnownLayout derive macro generates type-level field handle helper structs (__Zerocopy_Field_0, etc.) to track field types. Previously, these helper structs were declared with the visibility of the individual field.

When deriving KnownLayout on a public struct containing one or more private fields, the helper structs were generated as private. This triggered the E0446 (private type in public interface) compiler error because a public type (Foo) was implementing a public trait (Field<__Zerocopy_Field_0>) using the private helper struct.

This commit resolves the issue by declaring the helper structs using the visibility of the parent struct rather than the fields. This ensures that the helper structs are always exactly as visible as the type implementing the trait.

Add a regression test to verify compiling a public struct with a private field inside a macro under strict deny-by-default warnings.

This is a preliminary fix before #3568.

The `KnownLayout` derive macro generates type-level field handle helper
structs (`__Zerocopy_Field_0`, etc.) to track field types. Previously,
these helper structs were declared with the visibility of the individual
field.

When deriving `KnownLayout` on a public struct containing one or more
private fields, the helper structs were generated as private. This
triggered the `E0446 (private type in public interface)` compiler error
because a public type (`Foo`) was implementing a public trait
(`Field<__Zerocopy_Field_0>`) using the private helper struct.

This commit resolves the issue by declaring the helper structs using the
visibility of the parent struct rather than the fields. This ensures
that the helper structs are always exactly as visible as the type
implementing the trait.

Add a regression test to verify compiling a public struct with a private
field inside a macro under strict deny-by-default warnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant