Skip to content

Commit f607195

Browse files
committed
implement ptr.addr() via transmute
1 parent d64b8cd commit f607195

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

core/src/ptr/const_ptr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ impl<T: ?Sized> *const T {
180180
T: Sized,
181181
{
182182
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
183-
self as usize
183+
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
184+
// provenance).
185+
unsafe { mem::transmute(self) }
184186
}
185187

186188
/// Gets the "address" portion of the pointer, and 'exposes' the "provenance" part for future

core/src/ptr/mut_ptr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ impl<T: ?Sized> *mut T {
184184
T: Sized,
185185
{
186186
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
187-
self as usize
187+
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
188+
// provenance).
189+
unsafe { mem::transmute(self) }
188190
}
189191

190192
/// Gets the "address" portion of the pointer, and 'exposes' the "provenance" part for future

0 commit comments

Comments
 (0)