-   Notifications  You must be signed in to change notification settings 
- Fork 13.9k
 library: core: document layout guarantee of TypeId #148265 
 New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| rustbot has assigned @Mark-Simulacrum. Use  | 
| Cc: @Darksonn | 
| 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>
| /// | ||
| /// # Layout | ||
| /// | ||
| /// The size of `TypeId` is guaranteed not to exceed 16 bytes. | 
There was a problem hiding this comment.
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. | 
There was a problem hiding this comment.
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.
Document the layout guarantee of
TypeIdnot to exceed 16 bytes.This is useful for FFI use-cases where a
TypeIdmay 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