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