Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl SliceIndex<str> for (Bound<usize>, Bound<usize>) #111081

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Work around missing <*str>::len
  • Loading branch information
mattfbacon committed Jul 31, 2023
commit f189d00d4053156b3ac08b48526e48cde402d4a9
8 changes: 4 additions & 4 deletions library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,16 @@ unsafe impl SliceIndex<str> for (ops::Bound<usize>, ops::Bound<usize>) {

#[inline]
unsafe fn get_unchecked(self, slice: *const str) -> *const str {
let len = (slice as *const [u8]).len();
// SAFETY: the caller has to uphold the safety contract for `get_unchecked`.
unsafe { crate::slice::index::into_range_unchecked(slice.len(), self).get_unchecked(slice) }
unsafe { crate::slice::index::into_range_unchecked(len, self).get_unchecked(slice) }
}

#[inline]
unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut str {
let len = (slice as *mut [u8]).len();
// SAFETY: the caller has to uphold the safety contract for `get_unchecked_mut`.
unsafe {
crate::slice::index::into_range_unchecked(slice.len(), self).get_unchecked_mut(slice)
}
unsafe { crate::slice::index::into_range_unchecked(len, self).get_unchecked_mut(slice) }
}

#[inline]
Expand Down