Skip to content

Commit f189d00

Browse files
committed
Work around missing <*str>::len
1 parent e12e7fc commit f189d00

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/core/src/str/traits.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,16 @@ unsafe impl SliceIndex<str> for (ops::Bound<usize>, ops::Bound<usize>) {
281281

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

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

296296
#[inline]

0 commit comments

Comments
 (0)