Skip to content

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

Merged
merged 3 commits into from
Oct 1, 2017
Merged

Conversation

Havvy
Copy link
Contributor

@Havvy Havvy commented Sep 28, 2017

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)] enums with no variants.

Most of this info comes from camlorn's blog post on optimizing
struct layout and the Rustonomicon.
@rust-highfive
Copy link
Contributor

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@Havvy
Copy link
Contributor Author

Havvy commented Sep 28, 2017

r? @steveklabnik

(Why do I always forget this?)

@rust-highfive rust-highfive assigned steveklabnik and unassigned aturon Sep 28, 2017
@@ -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
Copy link
Member

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 `…`.

/// Enums that carry no data other than the descriminant have the same size as C enums
/// on the platform they are compiled for.
///
/// ## Unions
Copy link
Member

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

Copy link
Member

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"?

@alexcrichton alexcrichton added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2017
@steveklabnik
Copy link
Member

@bors: r+ rollup

thanks! ❤️

@bors
Copy link
Collaborator

bors commented Oct 1, 2017

📌 Commit 0ece48e has been approved by steveklabnik

@bors
Copy link
Collaborator

bors commented Oct 1, 2017

⌛ Testing commit 0ece48e with merge cef4a3e...

bors added a commit that referenced this pull request Oct 1, 2017
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.
@bors
Copy link
Collaborator

bors commented Oct 1, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: steveklabnik
Pushing cef4a3e to master...

@bors bors merged commit 0ece48e into rust-lang:master Oct 1, 2017
@Havvy Havvy deleted the doc-size_of branch October 2, 2017 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants