mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 13:06:28 +03:00
implement ptr.addr() via transmute
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user