Skip to content

Commit 2d74528

Browse files
committed
caution against ptr-to-int transmutes
1 parent df20355 commit 2d74528

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/core/src/intrinsics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,12 @@ extern "rust-intrinsic" {
991991
/// let ptr_num_cast = ptr as *const i32 as usize;
992992
/// ```
993993
///
994+
/// Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined
995+
/// 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.
999+
///
9941000
/// Turning a `*mut T` into an `&mut T`:
9951001
///
9961002
/// ```

0 commit comments

Comments
 (0)