Skip to content

Update comments and add tests for -Zrandomize-layout for some guaranteed ZSTs#157905

Draft
zachs18 wants to merge 2 commits into
rust-lang:mainfrom
zachs18:randomize-layout-zst-note
Draft

Update comments and add tests for -Zrandomize-layout for some guaranteed ZSTs#157905
zachs18 wants to merge 2 commits into
rust-lang:mainfrom
zachs18:randomize-layout-zst-note

Conversation

@zachs18

@zachs18 zachs18 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized repr(Rust) structs and enums, that changes to -Zrandomize-layout could theoretically break in the future. This PR adds comments to -Zrandomize-layout's implementation and tests to tests/ui/layout/randomize.rs to prevent breaking those guarantees.

First commit is the guarantees that T-lang is currently FCP'ing in rust-lang/reference#2262 .
Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 15, 2026
@zachs18 zachs18 changed the title Randomize layout zst note Update comments for -Zrandomize-layout for some guaranteed ZSTs Jun 15, 2026
@DanielEScherzer

Copy link
Copy Markdown
Contributor

@rustbot label +A-ZST "+-Zrandomize-layout"

@rustbot rustbot added -Zrandomize-layout Unstable option: Randomize the layout of types. A-ZST Area: Zero-sized types (ZSTs). labels Jun 16, 2026
@traviscross

Copy link
Copy Markdown
Contributor

Would it make sense to add tests for this?

@zachs18 zachs18 force-pushed the randomize-layout-zst-note branch from 6c36967 to 63e9672 Compare June 17, 2026 09:27
…d ZST struct/enums.

Also add tests for the guaranteed types.
@zachs18 zachs18 force-pushed the randomize-layout-zst-note branch from 63e9672 to 57b4ab5 Compare June 17, 2026 09:28
@zachs18 zachs18 changed the title Update comments for -Zrandomize-layout for some guaranteed ZSTs Update comments and add tests for -Zrandomize-layout for some guaranteed ZSTs Jun 17, 2026
@zachs18 zachs18 force-pushed the randomize-layout-zst-note branch from 57b4ab5 to 78ea28b Compare June 17, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

-Zrandomize-layout Unstable option: Randomize the layout of types. A-ZST Area: Zero-sized types (ZSTs). S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

4 participants