Skip to content

Commit 51b0416

Browse files
committed
Use cast_array in core
1 parent 7ead576 commit 51b0416

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

library/core/src/slice/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl<T> [T] {
330330
} else {
331331
// SAFETY: We explicitly check for the correct number of elements,
332332
// and do not let the reference outlive the slice.
333-
Some(unsafe { &*(self.as_ptr().cast::<[T; N]>()) })
333+
Some(unsafe { &*(self.as_ptr().cast_array()) })
334334
}
335335
}
336336

@@ -361,7 +361,7 @@ impl<T> [T] {
361361
// SAFETY: We explicitly check for the correct number of elements,
362362
// do not let the reference outlive the slice,
363363
// and require exclusive access to the entire slice to mutate the chunk.
364-
Some(unsafe { &mut *(self.as_mut_ptr().cast::<[T; N]>()) })
364+
Some(unsafe { &mut *(self.as_mut_ptr().cast_array()) })
365365
}
366366
}
367367

@@ -389,7 +389,7 @@ impl<T> [T] {
389389

390390
// SAFETY: We explicitly check for the correct number of elements,
391391
// and do not let the references outlive the slice.
392-
Some((unsafe { &*(first.as_ptr().cast::<[T; N]>()) }, tail))
392+
Some((unsafe { &*(first.as_ptr().cast_array()) }, tail))
393393
}
394394

395395
/// Returns a mutable array reference to the first `N` items in the slice and the remaining
@@ -422,7 +422,7 @@ impl<T> [T] {
422422
// SAFETY: We explicitly check for the correct number of elements,
423423
// do not let the reference outlive the slice,
424424
// and enforce exclusive mutability of the chunk by the split.
425-
Some((unsafe { &mut *(first.as_mut_ptr().cast::<[T; N]>()) }, tail))
425+
Some((unsafe { &mut *(first.as_mut_ptr().cast_array()) }, tail))
426426
}
427427

428428
/// Returns an array reference to the last `N` items in the slice and the remaining slice.
@@ -450,7 +450,7 @@ impl<T> [T] {
450450

451451
// SAFETY: We explicitly check for the correct number of elements,
452452
// and do not let the references outlive the slice.
453-
Some((init, unsafe { &*(last.as_ptr().cast::<[T; N]>()) }))
453+
Some((init, unsafe { &*(last.as_ptr().cast_array()) }))
454454
}
455455

456456
/// Returns a mutable array reference to the last `N` items in the slice and the remaining
@@ -484,7 +484,7 @@ impl<T> [T] {
484484
// SAFETY: We explicitly check for the correct number of elements,
485485
// do not let the reference outlive the slice,
486486
// and enforce exclusive mutability of the chunk by the split.
487-
Some((init, unsafe { &mut *(last.as_mut_ptr().cast::<[T; N]>()) }))
487+
Some((init, unsafe { &mut *(last.as_mut_ptr().cast_array()) }))
488488
}
489489

490490
/// Returns an array reference to the last `N` items in the slice.
@@ -513,7 +513,7 @@ impl<T> [T] {
513513

514514
// SAFETY: We explicitly check for the correct number of elements,
515515
// and do not let the references outlive the slice.
516-
Some(unsafe { &*(last.as_ptr().cast::<[T; N]>()) })
516+
Some(unsafe { &*(last.as_ptr().cast_array()) })
517517
}
518518

519519
/// Returns a mutable array reference to the last `N` items in the slice.
@@ -544,7 +544,7 @@ impl<T> [T] {
544544
// SAFETY: We explicitly check for the correct number of elements,
545545
// do not let the reference outlive the slice,
546546
// and require exclusive access to the entire slice to mutate the chunk.
547-
Some(unsafe { &mut *(last.as_mut_ptr().cast::<[T; N]>()) })
547+
Some(unsafe { &mut *(last.as_mut_ptr().cast_array()) })
548548
}
549549

550550
/// Returns a reference to an element or subslice depending on the type of
@@ -848,7 +848,7 @@ impl<T> [T] {
848848
#[must_use]
849849
pub const fn as_array<const N: usize>(&self) -> Option<&[T; N]> {
850850
if self.len() == N {
851-
let ptr = self.as_ptr() as *const [T; N];
851+
let ptr = self.as_ptr().cast_array();
852852

853853
// SAFETY: The underlying array of a slice can be reinterpreted as an actual array `[T; N]` if `N` is not greater than the slice's length.
854854
let me = unsafe { &*ptr };
@@ -866,7 +866,7 @@ impl<T> [T] {
866866
#[must_use]
867867
pub const fn as_mut_array<const N: usize>(&mut self) -> Option<&mut [T; N]> {
868868
if self.len() == N {
869-
let ptr = self.as_mut_ptr() as *mut [T; N];
869+
let ptr = self.as_mut_ptr().cast_array();
870870

871871
// SAFETY: The underlying array of a slice can be reinterpreted as an actual array `[T; N]` if `N` is not greater than the slice's length.
872872
let me = unsafe { &mut *ptr };

0 commit comments

Comments
 (0)