Skip to content

Collapse #[repr(transparent)] types#619

Open
Firestar99 wants to merge 3 commits into
mainfrom
collapse-repr-transparent
Open

Collapse #[repr(transparent)] types#619
Firestar99 wants to merge 3 commits into
mainfrom
collapse-repr-transparent

Conversation

@Firestar99

Copy link
Copy Markdown
Member

Supersedes #566

@LegNeato LegNeato left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks directionally good to me.

Insole_structural_newtype_field it talks about “one non-ZST field”, but repr(transparent) is more specific...ignored fields must be both size 0 and align 1. Looks like we are only checking is_zst()?

Also a few more projection tests might be good, something like:

#[repr(transparent)]
struct W(Inner);

and then use W through &W, &mut W, raw pointers, arrays/slices, function args/returns, and nested transparent wrappers. Mostly want to make sure that once the wrapper type gets collapsed, accessing .0 still becomes a no-op and we don't accidentally emit an invalid access chain.

Might worth adding a test for an over-aligned ZST too:

#[repr(align(8))]
struct Blah;

#[repr(transparent)]
struct W {
    inner: u32,
    marker: Blah,
}

marker is size 0 but it has alignment 8 so it can affect W’s layout.

Requesting changes, but feel free to put up again if you are merely extracting and don't want to change anything.

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.

3 participants