Glossary: add new entry documenting zero-sized types#2203
Glossary: add new entry documenting zero-sized types#2203DanielEScherzer wants to merge 2 commits intorust-lang:masterfrom
Conversation
62a9187 to
399f597
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
1e87ac7 to
a46e8fa
Compare
a46e8fa to
2fb38fc
Compare
13ef3ed to
6164e1f
Compare
6164e1f to
410a44e
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
f3db8e1 to
be0b57a
Compare
be0b57a to
dc4cf65
Compare
| # use core::mem::{size_of, size_of_val}; | ||
| fn f() {} | ||
| struct S(u8); | ||
| enum E{ V(u8) } |
There was a problem hiding this comment.
Please add the missing space here.
| - The constructors of tuple-like structs (see [type.fn-item.intro]). | ||
| - The constructors of tuple-like enum variants (see [type.fn-item.intro]). |
There was a problem hiding this comment.
Please link "tuple-like structs" and "tuple-like enum variants".
| - `#[repr(C)]` structs with no fields ([unit-like structs]) or where all fields are zero-sized (see [layout.repr.c.struct.size-field-offset]). | ||
| - `#[repr(transparent)]` structs with no fields ([unit-like structs]) or where all fields are zero-sized (see [layout.repr.transparent.layout-abi]). |
There was a problem hiding this comment.
In prose, we'd just say "repr(C) struct" rather than giving the attribute syntax.
| assert_eq!(0, size_of_val(&f)); | ||
| // Note that here we are checking the size of the constructors, *not* the | ||
| // underlying type, for `S` and `E::V`. The constructors just have the same | ||
| // names as the types. |
There was a problem hiding this comment.
This could use some rewording. This is value position, so it's syntactically clear the name doesn't refer here to a type. Also, E::V isn't a type, so it's not correct to say that the constructors have the same name as the types.
Since the corresponding values couldn't be constructed in this way (due to needing arguments), it might be OK to just drop this comment.
| [zero-sized]: glossary.zst | ||
| [Tuples]: types/tuple.md | ||
| [Type parameters]: types/parameters.md | ||
| [variance]: subtyping.md#variance |
There was a problem hiding this comment.
The Reference isn't perfecly consistent about this, but in this case, the sorting is insensitive to case.
| [zero-sized]: glossary.zst | ||
| [zero-sized type]: glossary.zst | ||
| [zero-sized types]: glossary.zst | ||
| [zero-sized structs]: glossary.zst |
There was a problem hiding this comment.
"zero-sized structs" would sort before "zero-sized type".
No description provided.