Skip to content

Commit dd8820f

Browse files
committed
add similar attributes to slice::split_at_mut_unchecked
1 parent 900e6fa commit dd8820f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/core/src/str/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,18 @@ impl str {
772772
///
773773
/// The caller must ensure that `mid` is a valid byte offset from the start
774774
/// of the string and falls on the boundary of a UTF-8 code point.
775+
#[inline]
776+
#[must_use]
775777
unsafe const fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut str, &mut str) {
776778
let len = self.len();
777779
let ptr = self.as_mut_ptr();
780+
781+
assert_unsafe_precondition!(
782+
check_library_ub,
783+
"slice::split_at_mut_unchecked requires the index to be within the slice",
784+
(mid: usize = mid, len: usize = len) => mid <= len,
785+
);
786+
778787
// SAFETY: caller guarantees `mid` is on a char boundary.
779788
unsafe {
780789
(

0 commit comments

Comments
 (0)