@@ -96,9 +96,9 @@ unsafe impl<T: Sync> Send for Iter<'_, T> {}
96
96
97
97
impl < ' a , T > Iter < ' a , T > {
98
98
#[ inline]
99
- pub ( super ) fn new ( slice : & ' a [ T ] ) -> Self {
99
+ pub ( super ) const fn new ( slice : & ' a [ T ] ) -> Self {
100
100
let len = slice. len ( ) ;
101
- let ptr: NonNull < T > = NonNull :: from ( slice) . cast ( ) ;
101
+ let ptr: NonNull < T > = NonNull :: from_ref ( slice) . cast ( ) ;
102
102
// SAFETY: Similar to `IterMut::new`.
103
103
unsafe {
104
104
let end_or_len =
@@ -270,9 +270,9 @@ unsafe impl<T: Send> Send for IterMut<'_, T> {}
270
270
271
271
impl < ' a , T > IterMut < ' a , T > {
272
272
#[ inline]
273
- pub ( super ) fn new ( slice : & ' a mut [ T ] ) -> Self {
273
+ pub ( super ) const fn new ( slice : & ' a mut [ T ] ) -> Self {
274
274
let len = slice. len ( ) ;
275
- let ptr: NonNull < T > = NonNull :: from ( slice) . cast ( ) ;
275
+ let ptr: NonNull < T > = NonNull :: from_mut ( slice) . cast ( ) ;
276
276
// SAFETY: There are several things here:
277
277
//
278
278
// `ptr` has been obtained by `slice.as_ptr()` where `slice` is a valid
@@ -1387,7 +1387,7 @@ pub struct Windows<'a, T: 'a> {
1387
1387
1388
1388
impl < ' a , T : ' a > Windows < ' a , T > {
1389
1389
#[ inline]
1390
- pub ( super ) fn new ( slice : & ' a [ T ] , size : NonZero < usize > ) -> Self {
1390
+ pub ( super ) const fn new ( slice : & ' a [ T ] , size : NonZero < usize > ) -> Self {
1391
1391
Self { v : slice, size }
1392
1392
}
1393
1393
}
@@ -1539,7 +1539,7 @@ pub struct Chunks<'a, T: 'a> {
1539
1539
1540
1540
impl < ' a , T : ' a > Chunks < ' a , T > {
1541
1541
#[ inline]
1542
- pub ( super ) fn new ( slice : & ' a [ T ] , size : usize ) -> Self {
1542
+ pub ( super ) const fn new ( slice : & ' a [ T ] , size : usize ) -> Self {
1543
1543
Self { v : slice, chunk_size : size }
1544
1544
}
1545
1545
}
@@ -1729,7 +1729,7 @@ pub struct ChunksMut<'a, T: 'a> {
1729
1729
1730
1730
impl < ' a , T : ' a > ChunksMut < ' a , T > {
1731
1731
#[ inline]
1732
- pub ( super ) fn new ( slice : & ' a mut [ T ] , size : usize ) -> Self {
1732
+ pub ( super ) const fn new ( slice : & ' a mut [ T ] , size : usize ) -> Self {
1733
1733
Self { v : slice, chunk_size : size, _marker : PhantomData }
1734
1734
}
1735
1735
}
@@ -1915,7 +1915,7 @@ pub struct ChunksExact<'a, T: 'a> {
1915
1915
1916
1916
impl < ' a , T > ChunksExact < ' a , T > {
1917
1917
#[ inline]
1918
- pub ( super ) fn new ( slice : & ' a [ T ] , chunk_size : usize ) -> Self {
1918
+ pub ( super ) const fn new ( slice : & ' a [ T ] , chunk_size : usize ) -> Self {
1919
1919
let rem = slice. len ( ) % chunk_size;
1920
1920
let fst_len = slice. len ( ) - rem;
1921
1921
// SAFETY: 0 <= fst_len <= slice.len() by construction above
@@ -2095,7 +2095,7 @@ pub struct ChunksExactMut<'a, T: 'a> {
2095
2095
2096
2096
impl < ' a , T > ChunksExactMut < ' a , T > {
2097
2097
#[ inline]
2098
- pub ( super ) fn new ( slice : & ' a mut [ T ] , chunk_size : usize ) -> Self {
2098
+ pub ( super ) const fn new ( slice : & ' a mut [ T ] , chunk_size : usize ) -> Self {
2099
2099
let rem = slice. len ( ) % chunk_size;
2100
2100
let fst_len = slice. len ( ) - rem;
2101
2101
// SAFETY: 0 <= fst_len <= slice.len() by construction above
@@ -2262,7 +2262,7 @@ pub struct ArrayWindows<'a, T: 'a, const N: usize> {
2262
2262
2263
2263
impl < ' a , T : ' a , const N : usize > ArrayWindows < ' a , T , N > {
2264
2264
#[ inline]
2265
- pub ( super ) fn new ( slice : & ' a [ T ] ) -> Self {
2265
+ pub ( super ) const fn new ( slice : & ' a [ T ] ) -> Self {
2266
2266
let num_windows = slice. len ( ) . saturating_sub ( N - 1 ) ;
2267
2267
Self { slice_head : slice. as_ptr ( ) , num : num_windows, marker : PhantomData }
2268
2268
}
@@ -2386,8 +2386,10 @@ pub struct ArrayChunks<'a, T: 'a, const N: usize> {
2386
2386
}
2387
2387
2388
2388
impl < ' a , T , const N : usize > ArrayChunks < ' a , T , N > {
2389
+ #[ rustc_const_unstable( feature = "const_slice_make_iter" , issue = "137737" ) ]
2390
+ // #[rustc_const_unstable(feature = "slice_as_chunks", issue = "74985")]
2389
2391
#[ inline]
2390
- pub ( super ) fn new ( slice : & ' a [ T ] ) -> Self {
2392
+ pub ( super ) const fn new ( slice : & ' a [ T ] ) -> Self {
2391
2393
let ( array_slice, rem) = slice. as_chunks ( ) ;
2392
2394
Self { iter : array_slice. iter ( ) , rem }
2393
2395
}
@@ -2512,8 +2514,9 @@ pub struct ArrayChunksMut<'a, T: 'a, const N: usize> {
2512
2514
}
2513
2515
2514
2516
impl < ' a , T , const N : usize > ArrayChunksMut < ' a , T , N > {
2517
+ #[ rustc_const_unstable( feature = "const_slice_make_iter" , issue = "137737" ) ]
2515
2518
#[ inline]
2516
- pub ( super ) fn new ( slice : & ' a mut [ T ] ) -> Self {
2519
+ pub ( super ) const fn new ( slice : & ' a mut [ T ] ) -> Self {
2517
2520
let ( array_slice, rem) = slice. as_chunks_mut ( ) ;
2518
2521
Self { iter : array_slice. iter_mut ( ) , rem }
2519
2522
}
@@ -2631,7 +2634,7 @@ pub struct RChunks<'a, T: 'a> {
2631
2634
2632
2635
impl < ' a , T : ' a > RChunks < ' a , T > {
2633
2636
#[ inline]
2634
- pub ( super ) fn new ( slice : & ' a [ T ] , size : usize ) -> Self {
2637
+ pub ( super ) const fn new ( slice : & ' a [ T ] , size : usize ) -> Self {
2635
2638
Self { v : slice, chunk_size : size }
2636
2639
}
2637
2640
}
@@ -2811,7 +2814,7 @@ pub struct RChunksMut<'a, T: 'a> {
2811
2814
2812
2815
impl < ' a , T : ' a > RChunksMut < ' a , T > {
2813
2816
#[ inline]
2814
- pub ( super ) fn new ( slice : & ' a mut [ T ] , size : usize ) -> Self {
2817
+ pub ( super ) const fn new ( slice : & ' a mut [ T ] , size : usize ) -> Self {
2815
2818
Self { v : slice, chunk_size : size, _marker : PhantomData }
2816
2819
}
2817
2820
}
@@ -3002,7 +3005,7 @@ pub struct RChunksExact<'a, T: 'a> {
3002
3005
3003
3006
impl < ' a , T > RChunksExact < ' a , T > {
3004
3007
#[ inline]
3005
- pub ( super ) fn new ( slice : & ' a [ T ] , chunk_size : usize ) -> Self {
3008
+ pub ( super ) const fn new ( slice : & ' a [ T ] , chunk_size : usize ) -> Self {
3006
3009
let rem = slice. len ( ) % chunk_size;
3007
3010
// SAFETY: 0 <= rem <= slice.len() by construction above
3008
3011
let ( fst, snd) = unsafe { slice. split_at_unchecked ( rem) } ;
@@ -3028,7 +3031,8 @@ impl<'a, T> RChunksExact<'a, T> {
3028
3031
/// ```
3029
3032
#[ must_use]
3030
3033
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
3031
- pub fn remainder ( & self ) -> & ' a [ T ] {
3034
+ #[ rustc_const_unstable( feature = "const_slice_make_iter" , issue = "137737" ) ]
3035
+ pub const fn remainder ( & self ) -> & ' a [ T ] {
3032
3036
self . rem
3033
3037
}
3034
3038
}
@@ -3184,7 +3188,7 @@ pub struct RChunksExactMut<'a, T: 'a> {
3184
3188
3185
3189
impl < ' a , T > RChunksExactMut < ' a , T > {
3186
3190
#[ inline]
3187
- pub ( super ) fn new ( slice : & ' a mut [ T ] , chunk_size : usize ) -> Self {
3191
+ pub ( super ) const fn new ( slice : & ' a mut [ T ] , chunk_size : usize ) -> Self {
3188
3192
let rem = slice. len ( ) % chunk_size;
3189
3193
// SAFETY: 0 <= rem <= slice.len() by construction above
3190
3194
let ( fst, snd) = unsafe { slice. split_at_mut_unchecked ( rem) } ;
@@ -3196,7 +3200,8 @@ impl<'a, T> RChunksExactMut<'a, T> {
3196
3200
/// elements.
3197
3201
#[ must_use = "`self` will be dropped if the result is not used" ]
3198
3202
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
3199
- pub fn into_remainder ( self ) -> & ' a mut [ T ] {
3203
+ #[ rustc_const_unstable( feature = "const_slice_make_iter" , issue = "137737" ) ]
3204
+ pub const fn into_remainder ( self ) -> & ' a mut [ T ] {
3200
3205
self . rem
3201
3206
}
3202
3207
}
@@ -3360,7 +3365,7 @@ pub struct ChunkBy<'a, T: 'a, P> {
3360
3365
3361
3366
#[ stable( feature = "slice_group_by" , since = "1.77.0" ) ]
3362
3367
impl < ' a , T : ' a , P > ChunkBy < ' a , T , P > {
3363
- pub ( super ) fn new ( slice : & ' a [ T ] , predicate : P ) -> Self {
3368
+ pub ( super ) const fn new ( slice : & ' a [ T ] , predicate : P ) -> Self {
3364
3369
ChunkBy { slice, predicate }
3365
3370
}
3366
3371
}
@@ -3447,7 +3452,7 @@ pub struct ChunkByMut<'a, T: 'a, P> {
3447
3452
3448
3453
#[ stable( feature = "slice_group_by" , since = "1.77.0" ) ]
3449
3454
impl < ' a , T : ' a , P > ChunkByMut < ' a , T , P > {
3450
- pub ( super ) fn new ( slice : & ' a mut [ T ] , predicate : P ) -> Self {
3455
+ pub ( super ) const fn new ( slice : & ' a mut [ T ] , predicate : P ) -> Self {
3451
3456
ChunkByMut { slice, predicate }
3452
3457
}
3453
3458
}
0 commit comments