-
Notifications
You must be signed in to change notification settings - Fork 508
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
Primitive bit validity and padding guarantees #1292
Changes from all commits
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -53,9 +53,25 @@ target platform. For example, on a 32 bit target, this is 4 bytes and on a 64 | |||||||||||||||
bit target, this is 8 bytes. | ||||||||||||||||
|
||||||||||||||||
Most primitives are generally aligned to their size, although this is | ||||||||||||||||
platform-specific behavior. In particular, on x86 u64 and f64 are only | ||||||||||||||||
platform-specific behavior. In particular, on x86, `u64` and `f64` are only | ||||||||||||||||
aligned to 32 bits. | ||||||||||||||||
|
||||||||||||||||
### Primitive Bit Validity and Padding | ||||||||||||||||
|
||||||||||||||||
For each primitive type, `T`, in the preceding table other than `char`, any | ||||||||||||||||
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.
Suggested change
|
||||||||||||||||
sequence of `size_of::<T>()` bytes is a valid instance of `T`. In other words, | ||||||||||||||||
`transmute::<[u8; size_of::<T>()], T>(...)` is guaranteed to be sound. | ||||||||||||||||
|
||||||||||||||||
Similarly, for each primitive type, `T`, in the preceding table (including | ||||||||||||||||
`char`), `T` contains no padding or otherwise uninitialized bytes. In other | ||||||||||||||||
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.
Suggested change
|
||||||||||||||||
words, `transmute::<T, [u8; size_of::<T>()]>(...)` is guaranteed to be sound. | ||||||||||||||||
|
||||||||||||||||
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.
Suggested change
|
||||||||||||||||
#### `char` Bit Validity | ||||||||||||||||
|
||||||||||||||||
A `char`'s numerical value is guaranteed to be in the range 0 to 0x10FFFF, | ||||||||||||||||
inclusive. It is undefined behavior to construct a `char` with a value outside | ||||||||||||||||
this range. See the [`char` docs][char-docs] for more information. | ||||||||||||||||
|
||||||||||||||||
## Pointers and References Layout | ||||||||||||||||
|
||||||||||||||||
Pointers and references have the same layout. Mutability of the pointer or | ||||||||||||||||
|
@@ -583,6 +599,7 @@ used with any other representation. | |||||||||||||||
[`Sized`]: ../std/marker/trait.Sized.html | ||||||||||||||||
[`Copy`]: ../std/marker/trait.Copy.html | ||||||||||||||||
[dynamically sized types]: dynamically-sized-types.md | ||||||||||||||||
[char-docs]: ../std/primitive.char.html | ||||||||||||||||
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.
Suggested change
|
||||||||||||||||
[field-less enums]: items/enumerations.md#custom-discriminant-values-for-fieldless-enumerations | ||||||||||||||||
[enumerations]: items/enumerations.md | ||||||||||||||||
[zero-variant enums]: items/enumerations.md#zero-variant-enums | ||||||||||||||||
|
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.
Hm, this phrasing struck me as potentially confusing, since "x86" is often used as a shorthand to refer to "x86-64". (I did a brief double take, at least.) Per Wikipedia's chronology, "IA-32" might be a more appropriate term:
...but I think you're referring to
target_arch
value "x86" (which is distinct fromx86_64
). Rust inherits this shorthand from LLVM:...so you could instead disambiguate this by writing: