@@ -1538,13 +1538,14 @@ impl<T> [T] {
1538
1538
/// }
1539
1539
/// ```
1540
1540
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1541
+ #[ rustc_const_unstable( feature = "const_slice_split_at_not_mut" , issue = "none" ) ]
1541
1542
#[ inline]
1542
1543
#[ track_caller]
1543
1544
#[ must_use]
1544
- pub fn split_at ( & self , mid : usize ) -> ( & [ T ] , & [ T ] ) {
1545
+ pub const fn split_at ( & self , mid : usize ) -> ( & [ T ] , & [ T ] ) {
1545
1546
assert ! ( mid <= self . len( ) ) ;
1546
1547
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
1547
- // fulfills the requirements of `from_raw_parts_mut `.
1548
+ // fulfills the requirements of `split_at_unchecked `.
1548
1549
unsafe { self . split_at_unchecked ( mid) }
1549
1550
}
1550
1551
@@ -1623,11 +1624,15 @@ impl<T> [T] {
1623
1624
/// }
1624
1625
/// ```
1625
1626
#[ unstable( feature = "slice_split_at_unchecked" , reason = "new API" , issue = "76014" ) ]
1627
+ #[ rustc_const_unstable( feature = "const_slice_split_at_not_mut" , issue = "none" ) ]
1626
1628
#[ inline]
1627
1629
#[ must_use]
1628
- pub unsafe fn split_at_unchecked ( & self , mid : usize ) -> ( & [ T ] , & [ T ] ) {
1630
+ pub const unsafe fn split_at_unchecked ( & self , mid : usize ) -> ( & [ T ] , & [ T ] ) {
1631
+ let len = self . len ( ) ;
1632
+ let ptr = self . as_ptr ( ) ;
1633
+
1629
1634
// SAFETY: Caller has to check that `0 <= mid <= self.len()`
1630
- unsafe { ( self . get_unchecked ( .. mid) , self . get_unchecked ( mid.. ) ) }
1635
+ unsafe { ( from_raw_parts ( ptr , mid) , from_raw_parts ( ptr . add ( mid) , len - mid ) ) }
1631
1636
}
1632
1637
1633
1638
/// Divides one mutable slice into two at an index, without doing bounds checking.
0 commit comments