about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatt Fellenz <matt@felle.nz>2023-07-31 11:41:51 -0700
committerMatt Fellenz <matt@felle.nz>2023-07-31 11:42:14 -0700
commitf189d00d4053156b3ac08b48526e48cde402d4a9 (patch)
treed3a48d51cadde045b72deb134be2ff78fe71b8b3
parente12e7fcc500677a76785e5f791be9a637e0b8f4e (diff)
downloadrust-f189d00d4053156b3ac08b48526e48cde402d4a9.tar.gz
rust-f189d00d4053156b3ac08b48526e48cde402d4a9.zip
Work around missing <*str>::len
-rw-r--r--library/core/src/str/traits.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs
index a7d7eff609b..49f9f6d4ad1 100644
--- a/library/core/src/str/traits.rs
+++ b/library/core/src/str/traits.rs
@@ -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]