diff options
| author | Ralf Jung <post@ralfj.de> | 2022-06-03 16:45:35 -0400 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-06-03 16:45:35 -0400 |
| commit | 4291332175d12e79e6061cdc3f5dccac2e28b969 (patch) | |
| tree | 2ea3814602b8f2ff68af95105cd40f1f326c751f | |
| parent | 5e6bb83268518dcd74c96b5504f485b71e604e4c (diff) | |
| download | rust-4291332175d12e79e6061cdc3f5dccac2e28b969.tar.gz rust-4291332175d12e79e6061cdc3f5dccac2e28b969.zip | |
implement ptr.addr() via transmute
| -rw-r--r-- | library/core/src/ptr/const_ptr.rs | 4 | ||||
| -rw-r--r-- | library/core/src/ptr/mut_ptr.rs | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index f26fdc74ce1..490d7594bb8 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -180,7 +180,9 @@ impl<T: ?Sized> *const T { T: Sized, { // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic. - self as usize + // SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the + // provenance). + unsafe { mem::transmute(self) } } /// Gets the "address" portion of the pointer, and 'exposes' the "provenance" part for future diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 1fbf592c232..5846c855e8f 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -184,7 +184,9 @@ impl<T: ?Sized> *mut T { T: Sized, { // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic. - self as usize + // SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the + // provenance). + unsafe { mem::transmute(self) } } /// Gets the "address" portion of the pointer, and 'exposes' the "provenance" part for future |
