Skip to content

Commit 967bfdd

Browse files
committed
review
1 parent 037466e commit 967bfdd

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

library/core/src/slice/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ impl<T> [T] {
18321832
///
18331833
/// # Panics
18341834
///
1835-
/// Panics if `mid > len`. For non-panicking alternative see
1835+
/// Panics if `mid > len`. For a non-panicking alternative see
18361836
/// [`split_at_checked`](slice::split_at_checked).
18371837
///
18381838
/// # Examples
@@ -1879,7 +1879,7 @@ impl<T> [T] {
18791879
///
18801880
/// # Panics
18811881
///
1882-
/// Panics if `mid > len`. For non-panicking alternative see
1882+
/// Panics if `mid > len`. For a non-panicking alternative see
18831883
/// [`split_at_mut_checked`](slice::split_at_mut_checked).
18841884
///
18851885
/// # Examples
@@ -2021,7 +2021,7 @@ impl<T> [T] {
20212021
unsafe { (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) }
20222022
}
20232023

2024-
/// Divides one slice into two at an index returning `None` if slice is too
2024+
/// Divides one slice into two at an index returning, `None` if slice is too
20252025
/// short.
20262026
///
20272027
/// The first will contain all indices from `[0, mid)` (excluding
@@ -2072,7 +2072,8 @@ impl<T> [T] {
20722072
}
20732073
}
20742074

2075-
/// Divides one mutable slice into two at an index.
2075+
/// Divides one mutable slice into two at an index, returning `None` if
2076+
/// slice is too short.
20762077
///
20772078
/// The first will contain all indices from `[0, mid)` (excluding
20782079
/// the index `mid` itself) and the second will contain all

library/core/src/str/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,10 @@ impl str {
659659
#[must_use]
660660
#[stable(feature = "str_split_at", since = "1.4.0")]
661661
pub fn split_at(&self, mid: usize) -> (&str, &str) {
662-
self.split_at_checked(mid).unwrap_or_else(|| slice_error_fail(self, 0, mid))
662+
match self.split_at_checked(mid) {
663+
None => slice_error_fail(self, 0, mid),
664+
Some(pair) => pair,
665+
}
663666
}
664667

665668
/// Divide one mutable string slice into two at an index.
@@ -792,8 +795,8 @@ impl str {
792795
///
793796
/// # Safety
794797
///
795-
/// The caller must ensure `mid` is a byte offset at a UTF-8 character
796-
/// boundary.
798+
/// The caller must ensure that `mid` is a valid byte offset from the start
799+
/// of the string and falls on the boundary of a UTF-8 code point.
797800
unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut str, &mut str) {
798801
let len = self.len();
799802
let ptr = self.as_mut_ptr();

0 commit comments

Comments
 (0)