refine wording and describe alternatives
This commit is contained in:
parent
2d74528c21
commit
dd85a7682c
1 changed files with 7 additions and 3 deletions
|
@ -993,9 +993,13 @@ extern "rust-intrinsic" {
|
||||||
///
|
///
|
||||||
/// Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined
|
/// Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined
|
||||||
/// behavior][ub] in `const` contexts. Also outside of consts, this operation might not behave
|
/// behavior][ub] in `const` contexts. Also outside of consts, this operation might not behave
|
||||||
/// as expected -- this is touching on many unspecified aspects of the Rust memory model. To
|
/// as expected -- this is touching on many unspecified aspects of the Rust memory model.
|
||||||
/// make sure your code is well-defined, the conversion of pointers to integers and back should
|
/// Depending on what the code is doing, the following alternatives are preferrable to
|
||||||
/// always be done explicitly via casts.
|
/// pointer-to-integer transmutation:
|
||||||
|
/// - If the code just wants to store data of arbitrary type in some buffer and needs to pick a
|
||||||
|
/// type for that buffer, it can use [`MaybeUninit`][mem::MaybeUninit].
|
||||||
|
/// - If the code actually wants to work on the address the pointer points to, it can use `as`
|
||||||
|
/// casts or [`ptr.addr()`][pointer::addr].
|
||||||
///
|
///
|
||||||
/// Turning a `*mut T` into an `&mut T`:
|
/// Turning a `*mut T` into an `&mut T`:
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue