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
+3 -1
View File
@@ -180,7 +180,9 @@ pub fn addr(self) -> usize
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
+3 -1
View File
@@ -184,7 +184,9 @@ pub fn addr(self) -> usize
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