implement ptr.addr() via transmute

This commit is contained in:
Ralf Jung 2022-06-03 16:45:35 -04:00
parent 5e6bb83268
commit 4291332175
2 changed files with 6 additions and 2 deletions

View file

@ -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

View file

@ -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