@@ -153,7 +153,11 @@ impl<T> [T] {
153
153
#[ inline]
154
154
#[ must_use]
155
155
pub const fn first ( & self ) -> Option < & T > {
156
- if let [ first, ..] = self { Some ( first) } else { None }
156
+ if let [ first, ..] = self {
157
+ Some ( first)
158
+ } else {
159
+ None
160
+ }
157
161
}
158
162
159
163
/// Returns a mutable reference to the first element of the slice, or `None` if it is empty.
@@ -176,7 +180,11 @@ impl<T> [T] {
176
180
#[ inline]
177
181
#[ must_use]
178
182
pub const fn first_mut ( & mut self ) -> Option < & mut T > {
179
- if let [ first, ..] = self { Some ( first) } else { None }
183
+ if let [ first, ..] = self {
184
+ Some ( first)
185
+ } else {
186
+ None
187
+ }
180
188
}
181
189
182
190
/// Returns the first and all the rest of the elements of the slice, or `None` if it is empty.
@@ -196,7 +204,11 @@ impl<T> [T] {
196
204
#[ inline]
197
205
#[ must_use]
198
206
pub const fn split_first ( & self ) -> Option < ( & T , & [ T ] ) > {
199
- if let [ first, tail @ ..] = self { Some ( ( first, tail) ) } else { None }
207
+ if let [ first, tail @ ..] = self {
208
+ Some ( ( first, tail) )
209
+ } else {
210
+ None
211
+ }
200
212
}
201
213
202
214
/// Returns the first and all the rest of the elements of the slice, or `None` if it is empty.
@@ -218,7 +230,11 @@ impl<T> [T] {
218
230
#[ inline]
219
231
#[ must_use]
220
232
pub const fn split_first_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
221
- if let [ first, tail @ ..] = self { Some ( ( first, tail) ) } else { None }
233
+ if let [ first, tail @ ..] = self {
234
+ Some ( ( first, tail) )
235
+ } else {
236
+ None
237
+ }
222
238
}
223
239
224
240
/// Returns the last and all the rest of the elements of the slice, or `None` if it is empty.
@@ -238,7 +254,11 @@ impl<T> [T] {
238
254
#[ inline]
239
255
#[ must_use]
240
256
pub const fn split_last ( & self ) -> Option < ( & T , & [ T ] ) > {
241
- if let [ init @ .., last] = self { Some ( ( last, init) ) } else { None }
257
+ if let [ init @ .., last] = self {
258
+ Some ( ( last, init) )
259
+ } else {
260
+ None
261
+ }
242
262
}
243
263
244
264
/// Returns the last and all the rest of the elements of the slice, or `None` if it is empty.
@@ -260,7 +280,11 @@ impl<T> [T] {
260
280
#[ inline]
261
281
#[ must_use]
262
282
pub const fn split_last_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
263
- if let [ init @ .., last] = self { Some ( ( last, init) ) } else { None }
283
+ if let [ init @ .., last] = self {
284
+ Some ( ( last, init) )
285
+ } else {
286
+ None
287
+ }
264
288
}
265
289
266
290
/// Returns the last element of the slice, or `None` if it is empty.
@@ -279,7 +303,11 @@ impl<T> [T] {
279
303
#[ inline]
280
304
#[ must_use]
281
305
pub const fn last ( & self ) -> Option < & T > {
282
- if let [ .., last] = self { Some ( last) } else { None }
306
+ if let [ .., last] = self {
307
+ Some ( last)
308
+ } else {
309
+ None
310
+ }
283
311
}
284
312
285
313
/// Returns a mutable reference to the last item in the slice, or `None` if it is empty.
@@ -302,7 +330,11 @@ impl<T> [T] {
302
330
#[ inline]
303
331
#[ must_use]
304
332
pub const fn last_mut ( & mut self ) -> Option < & mut T > {
305
- if let [ .., last] = self { Some ( last) } else { None }
333
+ if let [ .., last] = self {
334
+ Some ( last)
335
+ } else {
336
+ None
337
+ }
306
338
}
307
339
308
340
/// Returns an array reference to the first `N` items in the slice.
@@ -353,7 +385,8 @@ impl<T> [T] {
353
385
/// ```
354
386
#[ inline]
355
387
#[ stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
356
- #[ rustc_const_unstable( feature = "const_slice_first_last_chunk" , issue = "111774" ) ]
388
+ #[ rustc_const_stable( feature = "const_slice_first_last_chunk" , since = "CURRENT_RUSTC_VERSION" ) ]
389
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
357
390
pub const fn first_chunk_mut < const N : usize > ( & mut self ) -> Option < & mut [ T ; N ] > {
358
391
if self . len ( ) < N {
359
392
None
@@ -384,6 +417,7 @@ impl<T> [T] {
384
417
#[ inline]
385
418
#[ stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
386
419
#[ rustc_const_stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
420
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
387
421
pub const fn split_first_chunk < const N : usize > ( & self ) -> Option < ( & [ T ; N ] , & [ T ] ) > {
388
422
if self . len ( ) < N {
389
423
None
@@ -418,7 +452,8 @@ impl<T> [T] {
418
452
/// ```
419
453
#[ inline]
420
454
#[ stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
421
- #[ rustc_const_unstable( feature = "const_slice_first_last_chunk" , issue = "111774" ) ]
455
+ #[ rustc_const_stable( feature = "const_slice_first_last_chunk" , since = "CURRENT_RUSTC_VERSION" ) ]
456
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
422
457
pub const fn split_first_chunk_mut < const N : usize > (
423
458
& mut self ,
424
459
) -> Option < ( & mut [ T ; N ] , & mut [ T ] ) > {
@@ -454,6 +489,7 @@ impl<T> [T] {
454
489
#[ inline]
455
490
#[ stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
456
491
#[ rustc_const_stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
492
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
457
493
pub const fn split_last_chunk < const N : usize > ( & self ) -> Option < ( & [ T ] , & [ T ; N ] ) > {
458
494
if self . len ( ) < N {
459
495
None
@@ -488,7 +524,8 @@ impl<T> [T] {
488
524
/// ```
489
525
#[ inline]
490
526
#[ stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
491
- #[ rustc_const_unstable( feature = "const_slice_first_last_chunk" , issue = "111774" ) ]
527
+ #[ rustc_const_stable( feature = "const_slice_first_last_chunk" , since = "CURRENT_RUSTC_VERSION" ) ]
528
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
492
529
pub const fn split_last_chunk_mut < const N : usize > (
493
530
& mut self ,
494
531
) -> Option < ( & mut [ T ] , & mut [ T ; N ] ) > {
@@ -524,6 +561,7 @@ impl<T> [T] {
524
561
#[ inline]
525
562
#[ stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
526
563
#[ rustc_const_stable( feature = "const_slice_last_chunk" , since = "1.80.0" ) ]
564
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
527
565
pub const fn last_chunk < const N : usize > ( & self ) -> Option < & [ T ; N ] > {
528
566
if self . len ( ) < N {
529
567
None
@@ -557,7 +595,8 @@ impl<T> [T] {
557
595
/// ```
558
596
#[ inline]
559
597
#[ stable( feature = "slice_first_last_chunk" , since = "1.77.0" ) ]
560
- #[ rustc_const_unstable( feature = "const_slice_first_last_chunk" , issue = "111774" ) ]
598
+ #[ rustc_const_stable( feature = "const_slice_first_last_chunk" , since = "CURRENT_RUSTC_VERSION" ) ]
599
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
561
600
pub const fn last_chunk_mut < const N : usize > ( & mut self ) -> Option < & mut [ T ; N ] > {
562
601
if self . len ( ) < N {
563
602
None
@@ -1900,7 +1939,8 @@ impl<T> [T] {
1900
1939
#[ inline]
1901
1940
#[ track_caller]
1902
1941
#[ must_use]
1903
- #[ rustc_const_unstable( feature = "const_slice_split_at_mut" , issue = "101804" ) ]
1942
+ #[ rustc_const_stable( feature = "const_slice_split_at_mut" , since = "CURRENT_RUSTC_VERSION" ) ]
1943
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
1904
1944
pub const fn split_at_mut ( & mut self , mid : usize ) -> ( & mut [ T ] , & mut [ T ] ) {
1905
1945
match self . split_at_mut_checked ( mid) {
1906
1946
Some ( pair) => pair,
@@ -2002,7 +2042,9 @@ impl<T> [T] {
2002
2042
/// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
2003
2043
/// ```
2004
2044
#[ stable( feature = "slice_split_at_unchecked" , since = "1.79.0" ) ]
2005
- #[ rustc_const_unstable( feature = "const_slice_split_at_mut" , issue = "101804" ) ]
2045
+ #[ rustc_const_stable( feature = "const_slice_split_at_mut" , since = "CURRENT_RUSTC_VERSION" ) ]
2046
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
2047
+ #[ rustc_allow_const_fn_unstable( const_slice_from_raw_parts_mut) ]
2006
2048
#[ inline]
2007
2049
#[ must_use]
2008
2050
pub const unsafe fn split_at_mut_unchecked ( & mut self , mid : usize ) -> ( & mut [ T ] , & mut [ T ] ) {
@@ -2102,7 +2144,8 @@ impl<T> [T] {
2102
2144
/// assert_eq!(None, v.split_at_mut_checked(7));
2103
2145
/// ```
2104
2146
#[ stable( feature = "split_at_checked" , since = "1.80.0" ) ]
2105
- #[ rustc_const_unstable( feature = "const_slice_split_at_mut" , issue = "101804" ) ]
2147
+ #[ rustc_const_stable( feature = "const_slice_split_at_mut" , since = "CURRENT_RUSTC_VERSION" ) ]
2148
+ #[ cfg_attr( bootstrap, rustc_allow_const_fn_unstable( const_mut_refs) ) ]
2106
2149
#[ inline]
2107
2150
#[ must_use]
2108
2151
pub const fn split_at_mut_checked ( & mut self , mid : usize ) -> Option < ( & mut [ T ] , & mut [ T ] ) > {
@@ -3814,7 +3857,11 @@ impl<T> [T] {
3814
3857
//
3815
3858
// Luckily since all this is constant-evaluated... performance here matters not!
3816
3859
const fn gcd ( a : usize , b : usize ) -> usize {
3817
- if b == 0 { a } else { gcd ( b, a % b) }
3860
+ if b == 0 {
3861
+ a
3862
+ } else {
3863
+ gcd ( b, a % b)
3864
+ }
3818
3865
}
3819
3866
3820
3867
// Explicitly wrap the function call in a const block so it gets
@@ -4587,7 +4634,11 @@ impl<T> [T] {
4587
4634
4588
4635
let offset = byte_offset / mem:: size_of :: < T > ( ) ;
4589
4636
4590
- if offset < self . len ( ) { Some ( offset) } else { None }
4637
+ if offset < self . len ( ) {
4638
+ Some ( offset)
4639
+ } else {
4640
+ None
4641
+ }
4591
4642
}
4592
4643
4593
4644
/// Returns the range of indices that a subslice points to.
@@ -4641,7 +4692,11 @@ impl<T> [T] {
4641
4692
let start = byte_start / core:: mem:: size_of :: < T > ( ) ;
4642
4693
let end = start. wrapping_add ( subslice. len ( ) ) ;
4643
4694
4644
- if start <= self . len ( ) && end <= self . len ( ) { Some ( start..end) } else { None }
4695
+ if start <= self . len ( ) && end <= self . len ( ) {
4696
+ Some ( start..end)
4697
+ } else {
4698
+ None
4699
+ }
4645
4700
}
4646
4701
}
4647
4702
0 commit comments