about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2022-06-26 10:07:48 -0400
committerCaleb Zulawski <caleb.zulawski@gmail.com>2022-10-29 11:55:01 -0400
commit8a5a5732a1527fbdffbc825ae630d911fc130e2e (patch)
treebeb013b2159ce1dde8b671fdc457a6e4889d871f
parente7cc021189f1d18974057d60223bdbb5abd4dc15 (diff)
downloadrust-8a5a5732a1527fbdffbc825ae630d911fc130e2e.tar.gz
rust-8a5a5732a1527fbdffbc825ae630d911fc130e2e.zip
Clarify addr and with_addr implementations
-rw-r--r--crates/core_simd/src/elements/const_ptr.rs14
-rw-r--r--crates/core_simd/src/elements/mut_ptr.rs14
2 files changed, 18 insertions, 10 deletions
diff --git a/crates/core_simd/src/elements/const_ptr.rs b/crates/core_simd/src/elements/const_ptr.rs
index 5a5faad23c8..3485d31e44d 100644
--- a/crates/core_simd/src/elements/const_ptr.rs
+++ b/crates/core_simd/src/elements/const_ptr.rs
@@ -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()
diff --git a/crates/core_simd/src/elements/mut_ptr.rs b/crates/core_simd/src/elements/mut_ptr.rs
index d7b05af0eac..39fe9f35621 100644
--- a/crates/core_simd/src/elements/mut_ptr.rs
+++ b/crates/core_simd/src/elements/mut_ptr.rs
@@ -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()