diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 8ad4317c145ac..4a98b480c9d16 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -991,6 +991,16 @@ extern "rust-intrinsic" { /// let ptr_num_cast = ptr as *const i32 as usize; /// ``` /// + /// 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 + /// as expected -- this is touching on many unspecified aspects of the Rust memory model. + /// Depending on what the code is doing, the following alternatives are preferrable to + /// 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`: /// /// ```