We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0f639d7 commit 88031c3Copy full SHA for 88031c3
library/core/src/str/mod.rs
@@ -679,9 +679,12 @@ impl str {
679
#[must_use]
680
#[stable(feature = "str_split_at", since = "1.4.0")]
681
pub fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
682
- match self.split_at_mut_checked(mid) {
683
- None => slice_error_fail(self, 0, mid),
684
- Some(pair) => pair,
+ // is_char_boundary checks that the index is in [0, .len()]
+ if self.is_char_boundary(mid) {
+ // SAFETY: just checked that `mid` is on a char boundary.
685
+ unsafe { self.split_at_mut_unchecked(mid) }
686
+ } else {
687
+ slice_error_fail(self, 0, mid)
688
}
689
690
0 commit comments