Skip to content

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

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

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 already FCP'd 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 (FCP now completed)

@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 2 times, most recently 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
@zachs18
zachs18 force-pushed the randomize-layout-zst-note branch from 78ea28b to bec5d88 Compare July 8, 2026 01:57
@zachs18

zachs18 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

FCP completed in rust-lang/reference#2293 (comment) , so marking this ready for review

@zachs18
zachs18 marked this pull request as ready for review July 19, 2026 13:21
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 19, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 19, 2026
@rustbot

rustbot commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 17 candidates

@davidtwco

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit bec5d88 has been approved by davidtwco

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 23, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
… r=davidtwco

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

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 already FCP'd 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 (FCP now completed)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
… r=davidtwco

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

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 already FCP'd 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 (FCP now completed)
rust-bors Bot pushed a commit that referenced this pull request Jul 23, 2026
Rollup of 18 pull requests

Successful merges:

 - #138618 (Support using const pointers in asm `const` operand)
 - #150161 (Remove 'static requirement on try_as_dyn)
 - #158362 (trait solver: account for universes from replace_bound_vars)
 - #159173 (Add allowed list check on EII implementations attributes)
 - #159466 (cmse: clear variant-dependent padding in `enum`s)
 - #159718 (Make `DocLinkResMap` an `FxIndexMap`)
 - #155795 (constify `vec![1, 2, 3]` macro)
 - #157776 (ci: Enable autodiff tests on x86_64 linux)
 - #157905 (Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs)
 - #159041 (Reorganize `tests/ui/issues` [22/N])
 - #159108 (Reorganize `tests/ui/issues` [23/N])
 - #159138 (doc: document wasm import symbol mangling)
 - #159531 (Reorganize `tests/ui/issues` [28/N])
 - #159608 (early_otherwise: Don't hoist dereferences when the otherwise branch is reachable)
 - #159612 (Reorganize `tests/ui/issues` [29/N])
 - #159653 (run `tests/assembly-llvm/asm/aarch64-types.rs` for `aarch64_be`)
 - #159759 (rustc-dev-guide subtree update)
 - #159761 (Remove outdated comment for resolve_vars_with_obligations)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
… r=davidtwco

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

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 already FCP'd 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 (FCP now completed)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
… r=davidtwco

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

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 already FCP'd 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 (FCP now completed)
rust-bors Bot pushed a commit that referenced this pull request Jul 23, 2026
Rollup of 19 pull requests

Successful merges:

 - #150161 (Remove 'static requirement on try_as_dyn)
 - #158362 (trait solver: account for universes from replace_bound_vars)
 - #159173 (Add allowed list check on EII implementations attributes)
 - #159466 (cmse: clear variant-dependent padding in `enum`s)
 - #159718 (Make `DocLinkResMap` an `FxIndexMap`)
 - #155795 (constify `vec![1, 2, 3]` macro)
 - #157776 (ci: Enable autodiff tests on x86_64 linux)
 - #157905 (Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs)
 - #158766 (Promote riscv64-unknown-linux-musl to tier 2 with host tools)
 - #159041 (Reorganize `tests/ui/issues` [22/N])
 - #159108 (Reorganize `tests/ui/issues` [23/N])
 - #159138 (doc: document wasm import symbol mangling)
 - #159531 (Reorganize `tests/ui/issues` [28/N])
 - #159608 (early_otherwise: Don't hoist dereferences when the otherwise branch is reachable)
 - #159612 (Reorganize `tests/ui/issues` [29/N])
 - #159653 (run `tests/assembly-llvm/asm/aarch64-types.rs` for `aarch64_be`)
 - #159667 (Make some parser structured suggestions verbose and tweak their wording)
 - #159759 (rustc-dev-guide subtree update)
 - #159761 (Remove outdated comment for resolve_vars_with_obligations)
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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