Skip to content

Conversation

@jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Nov 2, 2025

Or worded differently, explicitly remark non-stable-guarantee of TypeId layout and size.

This PR makes no additional guarantees or non-guarantees, it only emphasizes that TypeId's size and layout are unstable like any other #[repr(Rust)] types.

This was discussed during #t-compiler/meetings > [weekly] 2025-10-30 @ 💬, where the compiler team discussed a request #148265 to have the standard library (and language) commit to TypeId guaranteeing a size upper bound of 16 bytes. In the meeting, the consensus was:

  • We were sympathetic to the use case discussed in the request PR, however we feel like this stability guarantee is premature, given that there are unresolved questions surrounding the intended purpose of TypeId, and concerns surrounding its collision-resistance properties Collisions in type_id #10389 and type_id is not sufficiently collision-resistant #129014. We would prefer not making any of such guarantee until the collision-resistance concerns are resolved.
  • Committing to a stability guarantee on the size upper bound now would close the door to making TypeId larger (even if unlikely for perf reasons).

Given that we have previously broken people who asserted the size of TypeId is 8 bytes, it was also discussed in the meeting that we should explicitly note that the size and layout of TypeId is not a stable guarantee, and is subject to changes between Rust releases, and thus cannot be relied upon -- if breakage in people's code is due to that assumption, it will be considered a won't-fix.

  • So even if #[repr(Rust)] types have unstable size and layout, this PR makes it explicit for TypeId since this type can feel "special" and users can be lead into thinking its size and layout is something they can rely upon.

r? @scottmcm (or libs/libs-api/lang)

Or worded differently, explicitly remark non-stable-guarantee of
`TypeId` layout and size.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 2, 2025
@Noratrieb
Copy link
Member

let's wait for #148265 (comment)

@Urgau
Copy link
Member

Urgau commented Nov 2, 2025

Happy to see this merge while we figure out if we want to commit some guarantees.

@scottmcm
Copy link
Member

scottmcm commented Nov 3, 2025

Since we've changed the size in the past, and this text is explicitly not making a promise, I'm happy to merge this for now.

We can always remove or change the text in the future as people and teams make further decisions. (In particular, if 148265 changes it even right after this merges, that's fine too.)

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 3, 2025

📌 Commit 625b6f5 has been approved by scottmcm

It is now in the queue for this repository.

@bors bors 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 Nov 3, 2025
bors added a commit that referenced this pull request Nov 3, 2025
Rollup of 3 pull requests

Successful merges:

 - #146260 (add SliceIndex wrapper types Last and Clamp<Idx>)
 - #148394 (Make explicit that `TypeId`'s layout and size are unstable)
 - #148402 (stdarch subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4104f80 into rust-lang:master Nov 3, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 3, 2025
rust-timer added a commit that referenced this pull request Nov 3, 2025
Rollup merge of #148394 - jieyouxu:remark-typeid-no-layout-guarantees, r=scottmcm

Make explicit that `TypeId`'s layout and size are unstable

Or worded differently, explicitly remark non-stable-guarantee of `TypeId` layout and size.

This PR makes no *additional* guarantees or non-guarantees, it only emphasizes that `TypeId`'s size and layout are unstable like any other `#[repr(Rust)]` types.

This was discussed during [#t-compiler/meetings > &#91;weekly&#93; 2025-10-30 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202025-10-30/near/547949347), where the compiler team discussed a request #148265 to have the standard library (and language) commit to `TypeId` guaranteeing a size upper bound of 16 bytes. In the meeting, the consensus was:

- We were sympathetic to the use case discussed in the request PR, however we feel like this stability guarantee is premature, given that there are unresolved questions surrounding the intended purpose of `TypeId`, and concerns surrounding its collision-resistance properties #10389 and #129014. We would prefer not making any of such guarantee until the collision-resistance concerns are resolved.
- Committing to a stability guarantee on the size upper bound now would close the door to making `TypeId` larger (even if unlikely for perf reasons).

Given that we have previously broken people who asserted the size of `TypeId` is 8 bytes, it was also discussed in the meeting that we should *explicitly* note that the size and layout of `TypeId` is not a stable guarantee, and is subject to changes between Rust releases, and thus cannot be relied upon -- if breakage in people's code is due to that assumption, it will be considered a won't-fix.

- So even if `#[repr(Rust)]` types have unstable size and layout, this PR makes it explicit for `TypeId` since this type can feel "special" and users can be lead into thinking its size and layout is something they can rely upon.

r? `@scottmcm` (or libs/libs-api/lang)
@jieyouxu jieyouxu deleted the remark-typeid-no-layout-guarantees branch November 3, 2025 10:56
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Nov 4, 2025
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#146260 (add SliceIndex wrapper types Last and Clamp<Idx>)
 - rust-lang/rust#148394 (Make explicit that `TypeId`'s layout and size are unstable)
 - rust-lang/rust#148402 (stdarch subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants