@@ -4446,8 +4446,10 @@ impl<T> [T] {
4446
4446
/// ```
4447
4447
#[ inline]
4448
4448
#[ stable( feature = "slice_take" , since = "CURRENT_RUSTC_VERSION" ) ]
4449
- pub fn split_off_first < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
4450
- let ( first, rem) = self . split_first ( ) ?;
4449
+ #[ rustc_const_unstable( feature = "const_split_off_first_last" , issue = "138539" ) ]
4450
+ pub const fn split_off_first < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
4451
+ // FIXME(const-hack): Use `?` when available in const instead of `let-else`.
4452
+ let Some ( ( first, rem) ) = self . split_first ( ) else { return None } ;
4451
4453
* self = rem;
4452
4454
Some ( first)
4453
4455
}
@@ -4469,8 +4471,11 @@ impl<T> [T] {
4469
4471
/// ```
4470
4472
#[ inline]
4471
4473
#[ stable( feature = "slice_take" , since = "CURRENT_RUSTC_VERSION" ) ]
4472
- pub fn split_off_first_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
4473
- let ( first, rem) = mem:: take ( self ) . split_first_mut ( ) ?;
4474
+ #[ rustc_const_unstable( feature = "const_split_off_first_last" , issue = "138539" ) ]
4475
+ pub const fn split_off_first_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
4476
+ // FIXME(const-hack): Use `mem::take` and `?` when available in const.
4477
+ // Original: `mem::take(self).split_first_mut()?`
4478
+ let Some ( ( first, rem) ) = mem:: replace ( self , & mut [ ] ) . split_first_mut ( ) else { return None } ;
4474
4479
* self = rem;
4475
4480
Some ( first)
4476
4481
}
@@ -4491,8 +4496,10 @@ impl<T> [T] {
4491
4496
/// ```
4492
4497
#[ inline]
4493
4498
#[ stable( feature = "slice_take" , since = "CURRENT_RUSTC_VERSION" ) ]
4494
- pub fn split_off_last < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
4495
- let ( last, rem) = self . split_last ( ) ?;
4499
+ #[ rustc_const_unstable( feature = "const_split_off_first_last" , issue = "138539" ) ]
4500
+ pub const fn split_off_last < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
4501
+ // FIXME(const-hack): Use `?` when available in const instead of `let-else`.
4502
+ let Some ( ( last, rem) ) = self . split_last ( ) else { return None } ;
4496
4503
* self = rem;
4497
4504
Some ( last)
4498
4505
}
@@ -4514,8 +4521,11 @@ impl<T> [T] {
4514
4521
/// ```
4515
4522
#[ inline]
4516
4523
#[ stable( feature = "slice_take" , since = "CURRENT_RUSTC_VERSION" ) ]
4517
- pub fn split_off_last_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
4518
- let ( last, rem) = mem:: take ( self ) . split_last_mut ( ) ?;
4524
+ #[ rustc_const_unstable( feature = "const_split_off_first_last" , issue = "138539" ) ]
4525
+ pub const fn split_off_last_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
4526
+ // FIXME(const-hack): Use `mem::take` and `?` when available in const.
4527
+ // Original: `mem::take(self).split_last_mut()?`
4528
+ let Some ( ( last, rem) ) = mem:: replace ( self , & mut [ ] ) . split_last_mut ( ) else { return None } ;
4519
4529
* self = rem;
4520
4530
Some ( last)
4521
4531
}
0 commit comments