about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/core_simd/src/cast.rs16
-rw-r--r--crates/core_simd/src/lib.rs3
-rw-r--r--crates/core_simd/src/vector.rs23
3 files changed, 32 insertions, 10 deletions
diff --git a/crates/core_simd/src/cast.rs b/crates/core_simd/src/cast.rs
index 33878581e0b..65a3f845ffc 100644
--- a/crates/core_simd/src/cast.rs
+++ b/crates/core_simd/src/cast.rs
@@ -37,9 +37,19 @@ unsafe impl SimdCast for f64 {}
 /// # Safety
 /// Implementing this trait asserts that the type is a valid vector element for the `simd_cast_ptr`
 /// intrinsic.
-pub unsafe trait SimdCastPtr: SimdElement {}
+pub unsafe trait SimdCastPtr<T> {}
 
 // Safety: pointers can be cast to other pointer types
-unsafe impl<T> SimdCastPtr for *const T {}
+unsafe impl<T, U> SimdCastPtr<T> for *const U
+where
+    U: core::ptr::Pointee,
+    T: core::ptr::Pointee<Metadata = U::Metadata>,
+{
+}
 // Safety: pointers can be cast to other pointer types
-unsafe impl<T> SimdCastPtr for *mut T {}
+unsafe impl<T, U> SimdCastPtr<T> for *mut U
+where
+    U: core::ptr::Pointee,
+    T: core::ptr::Pointee<Metadata = U::Metadata>,
+{
+}
diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs
index 05ac3e9338b..82873162969 100644
--- a/crates/core_simd/src/lib.rs
+++ b/crates/core_simd/src/lib.rs
@@ -8,7 +8,8 @@
     simd_ffi,
     staged_api,
     stdsimd,
-    strict_provenance
+    strict_provenance,
+    ptr_metadata
 )]
 #![cfg_attr(feature = "generic_const_exprs", feature(generic_const_exprs))]
 #![cfg_attr(feature = "generic_const_exprs", allow(incomplete_features))]
diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs
index 3c435c4c805..c5d68f1b921 100644
--- a/crates/core_simd/src/vector.rs
+++ b/crates/core_simd/src/vector.rs
@@ -220,9 +220,10 @@ where
     /// Lanewise casts pointers to another pointer type.
     #[must_use]
     #[inline]
-    pub fn cast_ptr<U: SimdCastPtr>(self) -> Simd<U, LANES>
+    pub fn cast_ptr<U>(self) -> Simd<U, LANES>
     where
-        T: SimdCastPtr,
+        T: SimdCastPtr<U>,
+        U: SimdElement,
     {
         // Safety: supported types are guaranteed by SimdCastPtr
         unsafe { intrinsics::simd_cast_ptr(self) }
@@ -753,14 +754,24 @@ unsafe impl SimdElement for f64 {
 
 impl<T> Sealed for *const T {}
 
-// Safety: const pointers are valid SIMD element types, and are supported by this API
-unsafe impl<T> SimdElement for *const T {
+// Safety: (thin) const pointers are valid SIMD element types, and are supported by this API
+//
+// Fat pointers may be supported in the future.
+unsafe impl<T> SimdElement for *const T
+where
+    T: core::ptr::Pointee<Metadata = ()>,
+{
     type Mask = isize;
 }
 
 impl<T> Sealed for *mut T {}
 
-// Safety: mut pointers are valid SIMD element types, and are supported by this API
-unsafe impl<T> SimdElement for *mut T {
+// Safety: (thin) mut pointers are valid SIMD element types, and are supported by this API
+//
+// Fat pointers may be supported in the future.
+unsafe impl<T> SimdElement for *mut T
+where
+    T: core::ptr::Pointee<Metadata = ()>,
+{
     type Mask = isize;
 }