Skip to content

Commit 50cbbef

Browse files
committed
review
1 parent 755cfbf commit 50cbbef

File tree

2 files changed

+20
-178
lines changed

2 files changed

+20
-178
lines changed

library/core/src/slice/mod.rs

+18-176
Original file line numberDiff line numberDiff line change
@@ -2034,37 +2034,38 @@ impl<T> [T] {
20342034
unsafe { (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) }
20352035
}
20362036

2037-
/// Divides one slice into two at an index returning, `None` if slice is too
2038-
/// short.
2037+
/// Divides one slice into two at an index, returning `None` if the slice is
2038+
/// too short.
20392039
///
2040-
/// The first will contain all indices from `[0, mid)` (excluding
2041-
/// the index `mid` itself) and the second will contain all
2042-
/// indices from `[mid, len)` (excluding the index `len` itself).
2040+
/// If `mid ≤ len` returns a pair of slices where the first will contain all
2041+
/// indices from `[0, mid)` (excluding the index `mid` itself) and the
2042+
/// second will contain all indices from `[mid, len)` (excluding the index
2043+
/// `len` itself).
20432044
///
2044-
/// Returns `None` if `mid > len`.
2045+
/// Otherwise, if `mid > len`, returns `None`.
20452046
///
20462047
/// # Examples
20472048
///
20482049
/// ```
20492050
/// #![feature(split_at_checked)]
20502051
///
2051-
/// let v = [1, 2, 3, 4, 5, 6];
2052+
/// let v = [1, -2, 3, -4, 5, -6];
20522053
///
20532054
/// {
20542055
/// let (left, right) = v.split_at_checked(0).unwrap();
20552056
/// assert_eq!(left, []);
2056-
/// assert_eq!(right, [1, 2, 3, 4, 5, 6]);
2057+
/// assert_eq!(right, [1, -2, 3, -4, 5, -6]);
20572058
/// }
20582059
///
20592060
/// {
20602061
/// let (left, right) = v.split_at_checked(2).unwrap();
2061-
/// assert_eq!(left, [1, 2]);
2062-
/// assert_eq!(right, [3, 4, 5, 6]);
2062+
/// assert_eq!(left, [1, -2]);
2063+
/// assert_eq!(right, [3, -4, 5, -6]);
20632064
/// }
20642065
///
20652066
/// {
20662067
/// let (left, right) = v.split_at_checked(6).unwrap();
2067-
/// assert_eq!(left, [1, 2, 3, 4, 5, 6]);
2068+
/// assert_eq!(left, [1, -2, 3, -4, 5, -6]);
20682069
/// assert_eq!(right, []);
20692070
/// }
20702071
///
@@ -2073,7 +2074,6 @@ impl<T> [T] {
20732074
#[unstable(feature = "split_at_checked", reason = "new API", issue = "119128")]
20742075
#[rustc_const_unstable(feature = "split_at_checked", issue = "119128")]
20752076
#[inline]
2076-
#[track_caller]
20772077
#[must_use]
20782078
pub const fn split_at_checked(&self, mid: usize) -> Option<(&[T], &[T])> {
20792079
if mid <= self.len() {
@@ -2085,14 +2085,15 @@ impl<T> [T] {
20852085
}
20862086
}
20872087

2088-
/// Divides one mutable slice into two at an index, returning `None` if
2088+
/// Divides one mutable slice into two at an index, returning `None` if the
20892089
/// slice is too short.
20902090
///
2091-
/// The first will contain all indices from `[0, mid)` (excluding
2092-
/// the index `mid` itself) and the second will contain all
2093-
/// indices from `[mid, len)` (excluding the index `len` itself).
2091+
/// If `mid ≤ len` returns a pair of slices where the first will contain all
2092+
/// indices from `[0, mid)` (excluding the index `mid` itself) and the
2093+
/// second will contain all indices from `[mid, len)` (excluding the index
2094+
/// `len` itself).
20942095
///
2095-
/// Returns `None` if `mid > len`.
2096+
/// Otherwise, if `mid > len`, returns `None`.
20962097
///
20972098
/// # Examples
20982099
///
@@ -2114,7 +2115,6 @@ impl<T> [T] {
21142115
#[unstable(feature = "split_at_checked", reason = "new API", issue = "119128")]
21152116
#[rustc_const_unstable(feature = "split_at_checked", issue = "119128")]
21162117
#[inline]
2117-
#[track_caller]
21182118
#[must_use]
21192119
pub const fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&mut [T], &mut [T])> {
21202120
if mid <= self.len() {
@@ -2126,164 +2126,6 @@ impl<T> [T] {
21262126
}
21272127
}
21282128

2129-
/// Divides one slice into an array and a remainder slice at an index.
2130-
///
2131-
/// The array will contain all indices from `[0, N)` (excluding
2132-
/// the index `N` itself) and the slice will contain all
2133-
/// indices from `[N, len)` (excluding the index `len` itself).
2134-
///
2135-
/// # Panics
2136-
///
2137-
/// Panics if `N > len`.
2138-
///
2139-
/// # Examples
2140-
///
2141-
/// ```
2142-
/// #![feature(split_array)]
2143-
///
2144-
/// let v = &[1, 2, 3, 4, 5, 6][..];
2145-
///
2146-
/// {
2147-
/// let (left, right) = v.split_array_ref::<0>();
2148-
/// assert_eq!(left, &[]);
2149-
/// assert_eq!(right, [1, 2, 3, 4, 5, 6]);
2150-
/// }
2151-
///
2152-
/// {
2153-
/// let (left, right) = v.split_array_ref::<2>();
2154-
/// assert_eq!(left, &[1, 2]);
2155-
/// assert_eq!(right, [3, 4, 5, 6]);
2156-
/// }
2157-
///
2158-
/// {
2159-
/// let (left, right) = v.split_array_ref::<6>();
2160-
/// assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
2161-
/// assert_eq!(right, []);
2162-
/// }
2163-
/// ```
2164-
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
2165-
#[inline]
2166-
#[track_caller]
2167-
#[must_use]
2168-
pub fn split_array_ref<const N: usize>(&self) -> (&[T; N], &[T]) {
2169-
let (a, b) = self.split_at(N);
2170-
// SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at)
2171-
unsafe { (&*(a.as_ptr() as *const [T; N]), b) }
2172-
}
2173-
2174-
/// Divides one mutable slice into an array and a remainder slice at an index.
2175-
///
2176-
/// The array will contain all indices from `[0, N)` (excluding
2177-
/// the index `N` itself) and the slice will contain all
2178-
/// indices from `[N, len)` (excluding the index `len` itself).
2179-
///
2180-
/// # Panics
2181-
///
2182-
/// Panics if `N > len`.
2183-
///
2184-
/// # Examples
2185-
///
2186-
/// ```
2187-
/// #![feature(split_array)]
2188-
///
2189-
/// let mut v = &mut [1, 0, 3, 0, 5, 6][..];
2190-
/// let (left, right) = v.split_array_mut::<2>();
2191-
/// assert_eq!(left, &mut [1, 0]);
2192-
/// assert_eq!(right, [3, 0, 5, 6]);
2193-
/// left[1] = 2;
2194-
/// right[1] = 4;
2195-
/// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
2196-
/// ```
2197-
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
2198-
#[inline]
2199-
#[track_caller]
2200-
#[must_use]
2201-
pub fn split_array_mut<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]) {
2202-
let (a, b) = self.split_at_mut(N);
2203-
// SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at_mut)
2204-
unsafe { (&mut *(a.as_mut_ptr() as *mut [T; N]), b) }
2205-
}
2206-
2207-
/// Divides one slice into an array and a remainder slice at an index from
2208-
/// the end.
2209-
///
2210-
/// The slice will contain all indices from `[0, len - N)` (excluding
2211-
/// the index `len - N` itself) and the array will contain all
2212-
/// indices from `[len - N, len)` (excluding the index `len` itself).
2213-
///
2214-
/// # Panics
2215-
///
2216-
/// Panics if `N > len`.
2217-
///
2218-
/// # Examples
2219-
///
2220-
/// ```
2221-
/// #![feature(split_array)]
2222-
///
2223-
/// let v = &[1, 2, 3, 4, 5, 6][..];
2224-
///
2225-
/// {
2226-
/// let (left, right) = v.rsplit_array_ref::<0>();
2227-
/// assert_eq!(left, [1, 2, 3, 4, 5, 6]);
2228-
/// assert_eq!(right, &[]);
2229-
/// }
2230-
///
2231-
/// {
2232-
/// let (left, right) = v.rsplit_array_ref::<2>();
2233-
/// assert_eq!(left, [1, 2, 3, 4]);
2234-
/// assert_eq!(right, &[5, 6]);
2235-
/// }
2236-
///
2237-
/// {
2238-
/// let (left, right) = v.rsplit_array_ref::<6>();
2239-
/// assert_eq!(left, []);
2240-
/// assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
2241-
/// }
2242-
/// ```
2243-
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
2244-
#[inline]
2245-
#[must_use]
2246-
pub fn rsplit_array_ref<const N: usize>(&self) -> (&[T], &[T; N]) {
2247-
assert!(N <= self.len());
2248-
let (a, b) = self.split_at(self.len() - N);
2249-
// SAFETY: b points to [T; N]? Yes it's [T] of length N (checked by split_at)
2250-
unsafe { (a, &*(b.as_ptr() as *const [T; N])) }
2251-
}
2252-
2253-
/// Divides one mutable slice into an array and a remainder slice at an
2254-
/// index from the end.
2255-
///
2256-
/// The slice will contain all indices from `[0, len - N)` (excluding
2257-
/// the index `N` itself) and the array will contain all
2258-
/// indices from `[len - N, len)` (excluding the index `len` itself).
2259-
///
2260-
/// # Panics
2261-
///
2262-
/// Panics if `N > len`.
2263-
///
2264-
/// # Examples
2265-
///
2266-
/// ```
2267-
/// #![feature(split_array)]
2268-
///
2269-
/// let mut v = &mut [1, 0, 3, 0, 5, 6][..];
2270-
/// let (left, right) = v.rsplit_array_mut::<4>();
2271-
/// assert_eq!(left, [1, 0]);
2272-
/// assert_eq!(right, &mut [3, 0, 5, 6]);
2273-
/// left[1] = 2;
2274-
/// right[1] = 4;
2275-
/// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
2276-
/// ```
2277-
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
2278-
#[inline]
2279-
#[must_use]
2280-
pub fn rsplit_array_mut<const N: usize>(&mut self) -> (&mut [T], &mut [T; N]) {
2281-
assert!(N <= self.len());
2282-
let (a, b) = self.split_at_mut(self.len() - N);
2283-
// SAFETY: b points to [T; N]? Yes it's [T] of length N (checked by split_at_mut)
2284-
unsafe { (a, &mut *(b.as_mut_ptr() as *mut [T; N])) }
2285-
}
2286-
22872129
/// Returns an iterator over subslices separated by elements that match
22882130
/// `pred`. The matched element is not contained in the subslices.
22892131
///

library/core/src/str/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl str {
642642
/// # Panics
643643
///
644644
/// Panics if `mid` is not on a UTF-8 code point boundary, or if it is past
645-
/// the end of the last code point of the string slice. For non-panicking
645+
/// the end of the last code point of the string slice. For a non-panicking
646646
/// alternative see [`split_at_checked`](str::split_at_checked).
647647
///
648648
/// # Examples
@@ -680,7 +680,7 @@ impl str {
680680
/// # Panics
681681
///
682682
/// Panics if `mid` is not on a UTF-8 code point boundary, or if it is past
683-
/// the end of the last code point of the string slice. For non-panicking
683+
/// the end of the last code point of the string slice. For a non-panicking
684684
/// alternative see [`split_at_mut_checked`](str::split_at_mut_checked).
685685
///
686686
/// # Examples

0 commit comments

Comments
 (0)