Skip to content

Commit 7047d97

Browse files
committed
Auto merge of rust-lang#111453 - scottmcm:constify-as-slice, r=Mark-Simulacrum
constify `slice_as_chunks` (unstable) Tracking issue: rust-lang#74985 Nothing complicated required; just adding `const` to the declarations.
2 parents 521f4da + 62fcebd commit 7047d97

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

library/core/src/slice/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ impl<T> [T] {
995995
#[unstable(feature = "slice_as_chunks", issue = "74985")]
996996
#[inline]
997997
#[must_use]
998-
pub unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]] {
998+
pub const unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]] {
999999
let this = self;
10001000
// SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length
10011001
let new_len = unsafe {
@@ -1043,7 +1043,7 @@ impl<T> [T] {
10431043
#[inline]
10441044
#[track_caller]
10451045
#[must_use]
1046-
pub fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]) {
1046+
pub const fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]) {
10471047
assert!(N != 0, "chunk size must be non-zero");
10481048
let len = self.len() / N;
10491049
let (multiple_of_n, remainder) = self.split_at(len * N);
@@ -1075,7 +1075,7 @@ impl<T> [T] {
10751075
#[inline]
10761076
#[track_caller]
10771077
#[must_use]
1078-
pub fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]) {
1078+
pub const fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]) {
10791079
assert!(N != 0, "chunk size must be non-zero");
10801080
let len = self.len() / N;
10811081
let (remainder, multiple_of_n) = self.split_at(self.len() - len * N);
@@ -1152,7 +1152,7 @@ impl<T> [T] {
11521152
#[unstable(feature = "slice_as_chunks", issue = "74985")]
11531153
#[inline]
11541154
#[must_use]
1155-
pub unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]] {
1155+
pub const unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]] {
11561156
let this = &*self;
11571157
// SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length
11581158
let new_len = unsafe {
@@ -1195,7 +1195,7 @@ impl<T> [T] {
11951195
#[inline]
11961196
#[track_caller]
11971197
#[must_use]
1198-
pub fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]) {
1198+
pub const fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]) {
11991199
assert!(N != 0, "chunk size must be non-zero");
12001200
let len = self.len() / N;
12011201
let (multiple_of_n, remainder) = self.split_at_mut(len * N);
@@ -1233,7 +1233,7 @@ impl<T> [T] {
12331233
#[inline]
12341234
#[track_caller]
12351235
#[must_use]
1236-
pub fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]) {
1236+
pub const fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]) {
12371237
assert!(N != 0, "chunk size must be non-zero");
12381238
let len = self.len() / N;
12391239
let (remainder, multiple_of_n) = self.split_at_mut(self.len() - len * N);

0 commit comments

Comments
 (0)