Clarify addr and with_addr implementations
This commit is contained in:
parent
e7cc021189
commit
8a5a5732a1
2 changed files with 18 additions and 10 deletions
|
|
@ -83,17 +83,21 @@ where
|
|||
|
||||
#[inline]
|
||||
fn addr(self) -> Self::Usize {
|
||||
// Safety: Since `addr` discards provenance, this is safe.
|
||||
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
|
||||
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
|
||||
// provenance).
|
||||
unsafe { core::mem::transmute_copy(&self) }
|
||||
|
||||
//TODO switch to casts when available
|
||||
//self.cast()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn with_addr(self, addr: Self::Usize) -> Self {
|
||||
fn with_addr(self, _addr: Self::Usize) -> Self {
|
||||
unimplemented!()
|
||||
/*
|
||||
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
|
||||
//
|
||||
// In the mean-time, this operation is defined to be "as if" it was
|
||||
// a wrapping_offset, so we can emulate it as such. This should properly
|
||||
// restore pointer provenance even under today's compiler.
|
||||
self.cast::<*const u8>()
|
||||
.wrapping_offset(addr.cast::<isize>() - self.addr().cast::<isize>())
|
||||
.cast()
|
||||
|
|
|
|||
|
|
@ -78,17 +78,21 @@ where
|
|||
|
||||
#[inline]
|
||||
fn addr(self) -> Self::Usize {
|
||||
// Safety: Since `addr` discards provenance, this is safe.
|
||||
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
|
||||
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
|
||||
// provenance).
|
||||
unsafe { core::mem::transmute_copy(&self) }
|
||||
|
||||
//TODO switch to casts when available
|
||||
//self.cast()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn with_addr(self, addr: Self::Usize) -> Self {
|
||||
fn with_addr(self, _addr: Self::Usize) -> Self {
|
||||
unimplemented!()
|
||||
/*
|
||||
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
|
||||
//
|
||||
// In the mean-time, this operation is defined to be "as if" it was
|
||||
// a wrapping_offset, so we can emulate it as such. This should properly
|
||||
// restore pointer provenance even under today's compiler.
|
||||
self.cast::<*mut u8>()
|
||||
.wrapping_offset(addr.cast::<isize>() - self.addr().cast::<isize>())
|
||||
.cast()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue