[derive] Use parent visibility for KnownLayout field helper structs - #3569
Closed
apasel422 wants to merge 1 commit into
Closed
[derive] Use parent visibility for KnownLayout field helper structs#3569apasel422 wants to merge 1 commit into
apasel422 wants to merge 1 commit into
Conversation
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
KnownLayoutderive 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
KnownLayouton a public struct containing one or more private fields, the helper structs were generated as private. This triggered theE0446 (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.