-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Docs for size_of::<#[repr(C)]> items. #44897
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
Conversation
Most of this info comes from camlorn's blog post on optimizing struct layout and the Rustonomicon.
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
(Why do I always forget this?) |
src/libcore/mem.rs
Outdated
@@ -209,6 +209,35 @@ pub fn forget<T>(t: T) { | |||
/// The mutability of a pointer does not change its size. As such, `&T` and `&mut T` | |||
/// have the same size. Likewise for `*const T` and `*mut T`. | |||
/// | |||
/// # Size of #[repr(C)] items |
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.
Put #[repr(C)]
inside backticks `…`
.
src/libcore/mem.rs
Outdated
/// Enums that carry no data other than the descriminant have the same size as C enums | ||
/// on the platform they are compiled for. | ||
/// | ||
/// ## Unions |
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.
I don't know what's wrong with linkchecker, but it seems this title is not acceptable.
[01:09:19] std/mem/index.html:32: broken link fragment `#unions` pointing to `std/mem/index.html`
[01:09:25] core/mem/index.html:32: broken link fragment `#unions` pointing to `core/mem/index.html`
[01:09:28] thread 'main' panicked at 'found some broken links', /checkout/src/tools/linkchecker/main.rs:49:8
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.
@Havvy Ok the problem is that ManuallyDrop
is a union, so there's already a "Unions" section in the documentation (check https://doc.rust-lang.org/std/mem/index.html). The linkchecker error message should say something like "duplicated link ID".
Could we workaround by saying "Size of Structs"/"Size of Enums"/"Size of Unions"?
@bors: r+ rollup thanks! ❤️ |
📌 Commit 0ece48e has been approved by |
Docs for size_of::<#[repr(C)]> items. Most of this info comes from camlorn's blog post on optimizing struct layout and the Rustonomicon. I don't really like my wording in the first paragraph. I also cannot find a definition of what `#[repr(C)]` does for enums that have variants with fields. They're allowed, unlike `#[repr(C)] enum`s with no variants.
☀️ Test successful - status-appveyor, status-travis |
Most of this info comes from camlorn's blog post on optimizing struct layout and the Rustonomicon.
I don't really like my wording in the first paragraph.
I also cannot find a definition of what
#[repr(C)]
does for enums that have variants with fields. They're allowed, unlike#[repr(C)] enum
s with no variants.