about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2023-05-07 08:16:05 -0400
committerGitHub <noreply@github.com>2023-05-07 08:16:05 -0400
commit45413e468d511195ab7b420a01415be008b49195 (patch)
treec3636551e097da598a4805450a0fff776449b79a
parent195d4cad50c5b8a544de608295e7fdc369f99d9a (diff)
parentb246e454387ef2d80078db36975d2df5d957f9fa (diff)
downloadrust-45413e468d511195ab7b420a01415be008b49195.tar.gz
rust-45413e468d511195ab7b420a01415be008b49195.zip
Merge pull request #346 from Sp00ph/update_safety
Fix inaccurate safety comments
-rw-r--r--crates/core_simd/src/vector.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs
index 92984f55e45..ff761fc900f 100644
--- a/crates/core_simd/src/vector.rs
+++ b/crates/core_simd/src/vector.rs
@@ -156,9 +156,9 @@ where
     /// assert_eq!(v.as_array(), &[0, 1, 2, 3]);
     /// ```
     pub const fn as_array(&self) -> &[T; N] {
-        // SAFETY: Transmuting between `Simd<T, N>` and `[T; N]`
-        // is always valid and `Simd<T, N>` never has a lower alignment
-        // than `[T; N]`.
+        // SAFETY: `Simd<T, N>` is just an overaligned `[T; N]` with
+        // potential padding at the end, so pointer casting to a
+        // `&[T; N]` is safe.
         //
         // NOTE: This deliberately doesn't just use `&self.0`, see the comment
         // on the struct definition for details.
@@ -167,9 +167,9 @@ where
 
     /// Returns a mutable array reference containing the entire SIMD vector.
     pub fn as_mut_array(&mut self) -> &mut [T; N] {
-        // SAFETY: Transmuting between `Simd<T, N>` and `[T; N]`
-        // is always valid and `Simd<T, N>` never has a lower alignment
-        // than `[T; N]`.
+        // SAFETY: `Simd<T, N>` is just an overaligned `[T; N]` with
+        // potential padding at the end, so pointer casting to a
+        // `&mut [T; N]` is safe.
         //
         // NOTE: This deliberately doesn't just use `&mut self.0`, see the comment
         // on the struct definition for details.