-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-ZSTArea: Zero-sized types (ZSTs).Area: Zero-sized types (ZSTs).A-layoutArea: Memory layout of typesArea: Memory layout of typesC-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
#[repr(transparent)]
struct X(()); // ERROR: needs exactly one non-zero-sized field, but has 0
But
#[repr(transparent)]
struct X<T>(T);
println!("{}", mem::align_of_val(&X(()))); // 1
println!("{}", mem::size_of_val(&X(()))); // 0
The reference says
The transparent representation can only be used on a struct or an enum with a single variant that has:
- a single field with non-zero size, and
- any number of fields with size 0 and alignment 1 (e.g. PhantomData).
I do not see a reason for this restriction. Maybe simply replace "a single" by "at most one" and remove the check.
Metadata
Metadata
Assignees
Labels
A-ZSTArea: Zero-sized types (ZSTs).Area: Zero-sized types (ZSTs).A-layoutArea: Memory layout of typesArea: Memory layout of typesC-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.