about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2022-08-04 20:17:16 -0400
committerCaleb Zulawski <caleb.zulawski@gmail.com>2022-10-29 11:55:01 -0400
commit0fcc4069c12a4cffa69397388a0be42d45afdd49 (patch)
tree4efa6dc1f44b83f6ac98a9d8cb2686a6af8014e1
parente5db1ecc8209e90982cc4603514028ef2210e592 (diff)
downloadrust-0fcc4069c12a4cffa69397388a0be42d45afdd49.tar.gz
rust-0fcc4069c12a4cffa69397388a0be42d45afdd49.zip
Fix pointer mutability casts and safety lints
-rw-r--r--crates/core_simd/src/cast.rs22
-rw-r--r--crates/core_simd/src/elements/const_ptr.rs4
-rw-r--r--crates/core_simd/src/elements/mut_ptr.rs5
3 files changed, 28 insertions, 3 deletions
diff --git a/crates/core_simd/src/cast.rs b/crates/core_simd/src/cast.rs
index d14b0de5d5e..33878581e0b 100644
--- a/crates/core_simd/src/cast.rs
+++ b/crates/core_simd/src/cast.rs
@@ -1,23 +1,45 @@
 use crate::simd::SimdElement;
 
 /// Supporting trait for `Simd::cast`.  Typically doesn't need to be used directly.
+///
+/// # Safety
+/// Implementing this trait asserts that the type is a valid vector element for the `simd_cast` or
+/// `simd_as` intrinsics.
 pub unsafe trait SimdCast: SimdElement {}
 
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for i8 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for i16 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for i32 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for i64 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for isize {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for u8 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for u16 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for u32 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for u64 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for usize {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for f32 {}
+// Safety: primitive number types can be cast to other primitive number types
 unsafe impl SimdCast for f64 {}
 
 /// Supporting trait for `Simd::cast_ptr`.  Typically doesn't need to be used directly.
+///
+/// # Safety
+/// Implementing this trait asserts that the type is a valid vector element for the `simd_cast_ptr`
+/// intrinsic.
 pub unsafe trait SimdCastPtr: SimdElement {}
 
+// Safety: pointers can be cast to other pointer types
 unsafe impl<T> SimdCastPtr for *const T {}
+// Safety: pointers can be cast to other pointer types
 unsafe impl<T> SimdCastPtr for *mut T {}
diff --git a/crates/core_simd/src/elements/const_ptr.rs b/crates/core_simd/src/elements/const_ptr.rs
index 0a3d4ec4087..7c856fd4332 100644
--- a/crates/core_simd/src/elements/const_ptr.rs
+++ b/crates/core_simd/src/elements/const_ptr.rs
@@ -86,7 +86,7 @@ where
 
     #[inline]
     fn as_mut(self) -> Self::MutPtr {
-        unsafe { intrinsics::simd_cast_ptr(self) }
+        self.cast_ptr()
     }
 
     #[inline]
@@ -111,11 +111,13 @@ where
 
     #[inline]
     fn expose_addr(self) -> Self::Usize {
+        // Safety: `self` is a pointer vector
         unsafe { intrinsics::simd_expose_addr(self) }
     }
 
     #[inline]
     fn from_exposed_addr(addr: Self::Usize) -> Self {
+        // Safety: `self` is a pointer vector
         unsafe { intrinsics::simd_from_exposed_addr(addr) }
     }
 
diff --git a/crates/core_simd/src/elements/mut_ptr.rs b/crates/core_simd/src/elements/mut_ptr.rs
index e6aa9808f37..5e904d24a42 100644
--- a/crates/core_simd/src/elements/mut_ptr.rs
+++ b/crates/core_simd/src/elements/mut_ptr.rs
@@ -81,8 +81,7 @@ where
 
     #[inline]
     fn as_const(self) -> Self::ConstPtr {
-        unimplemented!()
-        //self.cast()
+        self.cast_ptr()
     }
 
     #[inline]
@@ -107,11 +106,13 @@ where
 
     #[inline]
     fn expose_addr(self) -> Self::Usize {
+        // Safety: `self` is a pointer vector
         unsafe { intrinsics::simd_expose_addr(self) }
     }
 
     #[inline]
     fn from_exposed_addr(addr: Self::Usize) -> Self {
+        // Safety: `self` is a pointer vector
         unsafe { intrinsics::simd_from_exposed_addr(addr) }
     }