Skip to content

Commit

Permalink
implement ptr.addr() via transmute
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jun 3, 2022
1 parent 5e6bb83 commit 4291332
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4291332

Please sign in to comment.