Skip to content

Commit 1461769

Browse files
committed
Apply #[rustc_panics_when_zero] to the relevant core functions
1 parent 4649f9b commit 1461769

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

library/core/src/slice/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,9 @@ impl<T> [T] {
13351335
#[inline]
13361336
#[must_use]
13371337
#[track_caller]
1338-
pub const unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]] {
1338+
pub const unsafe fn as_chunks_unchecked<#[rustc_panics_when_zero] const N: usize>(
1339+
&self,
1340+
) -> &[[T; N]] {
13391341
assert_unsafe_precondition!(
13401342
check_language_ub,
13411343
"slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks",
@@ -1393,7 +1395,7 @@ impl<T> [T] {
13931395
#[inline]
13941396
#[track_caller]
13951397
#[must_use]
1396-
pub const fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]) {
1398+
pub const fn as_chunks<#[rustc_panics_when_zero] const N: usize>(&self) -> (&[[T; N]], &[T]) {
13971399
assert!(N != 0, "chunk size must be non-zero");
13981400
let len_rounded_down = self.len() / N * N;
13991401
// SAFETY: The rounded-down value is always the same or smaller than the
@@ -1440,7 +1442,7 @@ impl<T> [T] {
14401442
#[inline]
14411443
#[track_caller]
14421444
#[must_use]
1443-
pub const fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]) {
1445+
pub const fn as_rchunks<#[rustc_panics_when_zero] const N: usize>(&self) -> (&[T], &[[T; N]]) {
14441446
assert!(N != 0, "chunk size must be non-zero");
14451447
let len = self.len() / N;
14461448
let (remainder, multiple_of_n) = self.split_at(self.len() - len * N);
@@ -1495,7 +1497,9 @@ impl<T> [T] {
14951497
#[inline]
14961498
#[must_use]
14971499
#[track_caller]
1498-
pub const unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]] {
1500+
pub const unsafe fn as_chunks_unchecked_mut<#[rustc_panics_when_zero] const N: usize>(
1501+
&mut self,
1502+
) -> &mut [[T; N]] {
14991503
assert_unsafe_precondition!(
15001504
check_language_ub,
15011505
"slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks",
@@ -1549,7 +1553,9 @@ impl<T> [T] {
15491553
#[inline]
15501554
#[track_caller]
15511555
#[must_use]
1552-
pub const fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]) {
1556+
pub const fn as_chunks_mut<#[rustc_panics_when_zero] const N: usize>(
1557+
&mut self,
1558+
) -> (&mut [[T; N]], &mut [T]) {
15531559
assert!(N != 0, "chunk size must be non-zero");
15541560
let len_rounded_down = self.len() / N * N;
15551561
// SAFETY: The rounded-down value is always the same or smaller than the
@@ -1602,7 +1608,9 @@ impl<T> [T] {
16021608
#[inline]
16031609
#[track_caller]
16041610
#[must_use]
1605-
pub const fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]) {
1611+
pub const fn as_rchunks_mut<#[rustc_panics_when_zero] const N: usize>(
1612+
&mut self,
1613+
) -> (&mut [T], &mut [[T; N]]) {
16061614
assert!(N != 0, "chunk size must be non-zero");
16071615
let len = self.len() / N;
16081616
let (remainder, multiple_of_n) = self.split_at_mut(self.len() - len * N);
@@ -1643,7 +1651,9 @@ impl<T> [T] {
16431651
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
16441652
#[inline]
16451653
#[track_caller]
1646-
pub const fn array_windows<const N: usize>(&self) -> ArrayWindows<'_, T, N> {
1654+
pub const fn array_windows<#[rustc_panics_when_zero] const N: usize>(
1655+
&self,
1656+
) -> ArrayWindows<'_, T, N> {
16471657
assert!(N != 0, "window size must be non-zero");
16481658
ArrayWindows::new(self)
16491659
}

0 commit comments

Comments
 (0)