Skip to content

Conversation

@dakr
Copy link

@dakr dakr commented Oct 29, 2025

Document the layout guarantee of TypeId not to exceed 16 bytes.

This is useful for FFI use-cases where a TypeId may be stored within a foreign data structure or buffer.

An example for such a use-case can be found in [1].

Link: https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/commit/?id=6f61a2637abe4f89877da3280775565baedb60e0 [1]
Suggested-by: Alice Ryhl aliceryhl@google.com

@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 Oct 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 29, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

@dakr
Copy link
Author

dakr commented Oct 29, 2025

Cc: @Darksonn

@scottmcm
Copy link
Member

Do you have a reference to a place where there was an agreement to commit to this? Or is this a new libs-api/libs/compiler request?

@scottmcm scottmcm added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Oct 29, 2025
@Darksonn
Copy link
Contributor

Do you have a reference to a place where there was an agreement to commit to this? Or is this a new libs-api/libs/compiler request?

This PR is a request for the stdlib to make this commitment. There is some prior discussion at #rust-for-linux > TypeId layout.

Document the layout guarantee of `TypeId` not to exceed 16 bytes. This is useful for FFI use-cases where a `TypeId` may be stored within a foreign data structure or buffer. An example for such a use-case can be found in [1]. Link: https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/commit/?id=6f61a2637abe4f89877da3280775565baedb60e0 [1] Suggested-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
@scottmcm scottmcm added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. I-compiler-nominated Nominated for discussion during a compiler team meeting. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 30, 2025
///
/// # Layout
///
/// The size of `TypeId` is guaranteed not to exceed 16 bytes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make it repr(C) to ensure there can't be additional padding if layout randomization improved?

I think that should be hidden from the docs by default now, but you should double-check that it's not shown, since that's not a guarantee.

///
/// # Layout
///
/// The size of `TypeId` is guaranteed not to exceed 16 bytes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please mention explicitly that these are the only guarantees, and that users must not make any assumptions about the contents.

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

Labels

I-compiler-nominated Nominated for discussion during a compiler team meeting. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. 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. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

6 participants