1
Fork 0

Auto merge of #87870 - WaffleLapkin:pub_split_at_unchecked, r=dtolnay

Make `<[T]>::split_at_unchecked` and `<[T]>::split_at_mut_unchecked` public

The methods were originally added in https://github.com/rust-lang/rust/pull/75936 (30dc32b10e), but for some reason as private. Nevertheless, the methods have documentation and even a [tracking issue](https://github.com/rust-lang/rust/issues/76014).

It's very weird to have a tracking issue for private methods and these methods may be useful outside of the standard library. As such, this PR makes the methods public.
This commit is contained in:
bors 2021-10-03 13:41:52 +00:00
commit 5051904d66

View file

@ -1556,7 +1556,7 @@ impl<T> [T] {
/// ///
/// # Examples /// # Examples
/// ///
/// ```compile_fail /// ```
/// #![feature(slice_split_at_unchecked)] /// #![feature(slice_split_at_unchecked)]
/// ///
/// let v = [1, 2, 3, 4, 5, 6]; /// let v = [1, 2, 3, 4, 5, 6];
@ -1581,7 +1581,7 @@ impl<T> [T] {
/// ``` /// ```
#[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")] #[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")]
#[inline] #[inline]
unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]) { pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]) {
// SAFETY: Caller has to check that `0 <= mid <= self.len()` // SAFETY: Caller has to check that `0 <= mid <= self.len()`
unsafe { (self.get_unchecked(..mid), self.get_unchecked(mid..)) } unsafe { (self.get_unchecked(..mid), self.get_unchecked(mid..)) }
} }
@ -1605,7 +1605,7 @@ impl<T> [T] {
/// ///
/// # Examples /// # Examples
/// ///
/// ```compile_fail /// ```
/// #![feature(slice_split_at_unchecked)] /// #![feature(slice_split_at_unchecked)]
/// ///
/// let mut v = [1, 0, 3, 0, 5, 6]; /// let mut v = [1, 0, 3, 0, 5, 6];
@ -1621,7 +1621,7 @@ impl<T> [T] {
/// ``` /// ```
#[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")] #[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")]
#[inline] #[inline]
unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut [T], &mut [T]) { pub unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
let len = self.len(); let len = self.len();
let ptr = self.as_mut_ptr(); let ptr = self.as_mut_ptr();