about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2022-06-21 23:20:06 -0400
committerCaleb Zulawski <caleb.zulawski@gmail.com>2022-10-29 11:53:48 -0400
commit7e96f5dbea3fd2291f0e835a21ed0c41f6ef086e (patch)
tree32b25c6c2634ecc5dbd9b59cf7d29df9ff3ca917
parentd3cfd7c5c9dba01a8f31b10cef4a1985ae1dc53f (diff)
downloadrust-7e96f5dbea3fd2291f0e835a21ed0c41f6ef086e.tar.gz
rust-7e96f5dbea3fd2291f0e835a21ed0c41f6ef086e.zip
Use safe casts
-rw-r--r--crates/core_simd/src/elements/const_ptr.rs11
-rw-r--r--crates/core_simd/src/elements/mut_ptr.rs11
2 files changed, 8 insertions, 14 deletions
diff --git a/crates/core_simd/src/elements/const_ptr.rs b/crates/core_simd/src/elements/const_ptr.rs
index ab6b5b8b5f4..62365eace89 100644
--- a/crates/core_simd/src/elements/const_ptr.rs
+++ b/crates/core_simd/src/elements/const_ptr.rs
@@ -1,5 +1,5 @@
 use super::sealed::Sealed;
-use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdPartialEq, SupportedLaneCount};
+use crate::simd::{LaneCount, Mask, Simd, SimdPartialEq, SupportedLaneCount};
 
 /// Operations on SIMD vectors of constant pointers.
 pub trait SimdConstPtr: Copy + Sealed {
@@ -43,17 +43,14 @@ where
     }
 
     fn as_mut(self) -> Self::MutPtr {
-        // Converting between pointers is safe
-        unsafe { intrinsics::simd_as(self) }
+        self.cast()
     }
 
     fn to_bits(self) -> Self::Bits {
-        // Casting pointers to usize is safe
-        unsafe { intrinsics::simd_as(self) }
+        self.cast()
     }
 
     fn from_bits(bits: Self::Bits) -> Self {
-        // Casting usize to pointers is safe
-        unsafe { intrinsics::simd_as(bits) }
+        bits.cast()
     }
 }
diff --git a/crates/core_simd/src/elements/mut_ptr.rs b/crates/core_simd/src/elements/mut_ptr.rs
index b49f9fda7e4..8c68d42628f 100644
--- a/crates/core_simd/src/elements/mut_ptr.rs
+++ b/crates/core_simd/src/elements/mut_ptr.rs
@@ -1,5 +1,5 @@
 use super::sealed::Sealed;
-use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdPartialEq, SupportedLaneCount};
+use crate::simd::{LaneCount, Mask, Simd, SimdPartialEq, SupportedLaneCount};
 
 /// Operations on SIMD vectors of mutable pointers.
 pub trait SimdMutPtr: Copy + Sealed {
@@ -41,17 +41,14 @@ where
     }
 
     fn as_const(self) -> Self::ConstPtr {
-        // Converting between pointers is safe
-        unsafe { intrinsics::simd_as(self) }
+        self.cast()
     }
 
     fn to_bits(self) -> Self::Bits {
-        // Casting pointers to usize is safe
-        unsafe { intrinsics::simd_as(self) }
+        self.cast()
     }
 
     fn from_bits(bits: Self::Bits) -> Self {
-        // Casting usize to pointers is safe
-        unsafe { intrinsics::simd_as(bits) }
+        bits.cast()
     }
 }