-
Notifications
You must be signed in to change notification settings - Fork 534
Specify bit validity and padding of some types #1392
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 all commits
510e75c
e2385f9
d1850ea
2e43046
2f82b7f
61c6349
bbc8063
d3a66eb
5795f3a
80ec146
8f92a7d
746a359
ea1110b
13b5af8
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 |
---|---|---|
|
@@ -50,6 +50,16 @@ Raw pointers can be created directly using [`core::ptr::addr_of!`] for `*const` | |
|
||
The standard library contains additional 'smart pointer' types beyond references and raw pointers. | ||
|
||
## Bit validity | ||
|
||
Despite pointers and references being similar to `usize`s in the machine code emitted on most platforms, | ||
the semantics of transmuting a reference or pointer type to a non-pointer type is currently undecided. | ||
Thus, it may not be valid to transmute a pointer or reference type, `P`, to a `[u8; size_of::<P>()]`. | ||
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. @RalfJung For my own edification, how does this interact with pointer-to-integer
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. The current working model is that
In contrast:
Here, "transmute" refers to All of these operations are safe and sound, but as their docs show, they behave quite differently and that can affect the soundness of later code that uses the values they produce. Note that this is a prototype model, which has some unresolved problems and which is very much not stabilized. 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. Okay that all makes sense, thanks!
I always assume that of everything in this space unless documented otherwise :) |
||
|
||
For thin raw pointers (i.e., for `P = *const T` or `P = *mut T` for `T: Sized`), | ||
the inverse direction (transmuting from an integer or array of integers to `P`) is always valid. | ||
However, the pointer produced via such a transmutation may not be dereferenced (not even if `T` has size zero). | ||
|
||
[`core::ptr::addr_of!`]: ../../core/ptr/macro.addr_of.html | ||
[`core::ptr::addr_of_mut!`]: ../../core/ptr/macro.addr_of_mut.html | ||
[Interior mutability]: ../interior-mutability.md | ||
|
Uh oh!
There was an error while loading. Please reload this page.