Skip to content

Fix considering [u8; 0] to have trivial ABI in layout - #166232

Open
beetrees wants to merge 1 commit into
rust-lang:mainfrom
beetrees:fix-trivial-abi-layout
Open

beetrees wants to merge 1 commit into
rust-lang:mainfrom
beetrees:fix-trivial-abi-layout

Conversation

@beetrees

@beetrees beetrees commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The ABI layout handling of trivial ABI currently only checks that the type is a 1-ZST and doesn't contain any repr(C) types: however the documentation for trivial ABIs states that any array with a non-trivial element type is itself non-trivial. This means that the current ABI code considers types like [u8; 0] to be trivial even though they are not - this PR fixes it to match the documentation. This isn't particularly important for arguments/returns as C doesn't allow plain arrays in the argument/return positions, but it is important in other places. Found by @chenx97 in #164628. Split out from #166170.

r? @bjorn3

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 20, 2026
@rust-log-analyzer

This comment has been minimized.

@beetrees
beetrees force-pushed the fix-trivial-abi-layout branch from 329f4c1 to 90d6dd8 Compare November 20, 2026 03:18
@RalfJung

Copy link
Copy Markdown
Member

This means that the current ABI code considers types like [u8; 0] to be trivial even though they are not - this PR fixes it to match the documentation.

So this is basically fixing a bug in #156112. @Jules-Bertholet does this look reasonable?

@beetrees could you add a test for the case that was buggy?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants