Distinguish repr(C) ZSTs from others in ABI compatibility rules#157973
Open
Jules-Bertholet wants to merge 1 commit into
Open
Distinguish repr(C) ZSTs from others in ABI compatibility rules#157973Jules-Bertholet wants to merge 1 commit into
repr(C) ZSTs from others in ABI compatibility rules#157973Jules-Bertholet wants to merge 1 commit into
Conversation
Collaborator
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Jules-Bertholet
commented
Jun 16, 2026
Comment on lines
+1844
to
+1849
| /// - Any two types fulfilling all the following conditions are ABI-compatible; | ||
| /// such types are said to have "trivial ABI": | ||
| /// - Size 0 | ||
| /// - Alignment 1 | ||
| /// - Not `repr(C)` | ||
| /// - Not a `repr(transparent)` wrapper around a type that fails to satisfy these conditions |
Contributor
Author
There was a problem hiding this comment.
One question is whether we also wish to exclude arrays of size 0. E.g., should [SomeReprCStruct; 0] be guaranteed to have trivial ABI? (C currently can't pass arrays by value, but maybe some day they will fix that)
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.
(Split out from compiler implementation in #156112)
Some C ABIs pass and return ZSTs by pointer. But
()should never be returned by pointer, as it must matchvoid. To account for this, we have to weaken the present guarantee of "any two types with size 0 and alignment 1 are ABI-compatible" to excluderepr(C).Fixes rust-lang/unsafe-code-guidelines#552; see also #78586, #155299.
@rustbot label T-lang A-ABI needs-fcp