Skip to content

Commit dd85a76

Browse files
committed
refine wording and describe alternatives
1 parent 2d74528 commit dd85a76

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

library/core/src/intrinsics.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,13 @@ extern "rust-intrinsic" {
993993
///
994994
/// Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined
995995
/// behavior][ub] in `const` contexts. Also outside of consts, this operation might not behave
996-
/// as expected -- this is touching on many unspecified aspects of the Rust memory model. To
997-
/// make sure your code is well-defined, the conversion of pointers to integers and back should
998-
/// always be done explicitly via casts.
996+
/// as expected -- this is touching on many unspecified aspects of the Rust memory model.
997+
/// Depending on what the code is doing, the following alternatives are preferrable to
998+
/// pointer-to-integer transmutation:
999+
/// - If the code just wants to store data of arbitrary type in some buffer and needs to pick a
1000+
/// type for that buffer, it can use [`MaybeUninit`][mem::MaybeUninit].
1001+
/// - If the code actually wants to work on the address the pointer points to, it can use `as`
1002+
/// casts or [`ptr.addr()`][pointer::addr].
9991003
///
10001004
/// Turning a `*mut T` into an `&mut T`:
10011005
///

0 commit comments

Comments
 (0)