-
Notifications
You must be signed in to change notification settings - Fork 60
Guarantee the layout of structs with a single non-zero-sized field #164
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
Changes from 4 commits
3056194
e6a2db1
8df48e4
bd8e2fe
eae3f3c
4442b41
51f0ec0
1883271
054361b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,22 @@ struct Zst2(Zst1, Zst0); | |
# } | ||
``` | ||
|
||
#### Structs with 1-ZST fields | ||
|
||
For the purposes of struct layout [1-ZST] fields are ignored. | ||
|
||
For example, | ||
|
||
```rust | ||
type Zst1 = (); | ||
struct S1(i32, Zst1); | ||
|
||
type Zst2 = [u16; 0]; | ||
struct S2(Zst2, Zst1); | ||
``` | ||
|
||
the layout of `S1` is the same as that of `i32` and the layout of `S2` as that of `Zst2`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is saying more than just "1-ZST fields are ignored". You are also assuming here that single-field structs have layout identical to their only field. That is a separate statement, and should IMO get a separate section. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This comment is still open.) |
||
|
||
#### Unresolved questions | ||
|
||
During the course of the discussion in [#11] and [#12], various | ||
|
@@ -150,15 +166,6 @@ issue has been opened for further discussion on the repository. This | |
section documents the questions and gives a few light details, but the | ||
reader is referred to the issues for further discussion. | ||
|
||
**Single-field structs ([#34]).** If you have a struct with single field | ||
(`struct Foo { x: T }`), should we guarantee that the memory layout of | ||
`Foo` is identical to the memory layout of `T` (note that ABI details | ||
around function calls may still draw a distinction, which is why | ||
`#[repr(transparent)]` is needed). What about zero-sized types like | ||
`PhantomData`? | ||
|
||
[#34]: https://github.com/rust-rfcs/unsafe-code-guidelines/issues/34 | ||
|
||
**Homogeneous structs ([#36]).** If you have homogeneous structs, where all | ||
the `N` fields are of a single type `T`, can we guarantee a mapping to | ||
the memory layout of `[T; N]`? How do we map between the field names | ||
|
@@ -400,3 +407,5 @@ proposal (and -- further -- it does not match our existing behavior): | |
thread](https://github.com/rust-rfcs/unsafe-code-guidelines/pull/31#discussion_r224955817)). | ||
- Many people would prefer the name ordering to be chosen for | ||
"readability" and not optimal layout. | ||
|
||
[1-ZST]: ../glossary.md#zero-sized-type--zst |
Uh oh!
There was an error while loading. Please reload this page.