Skip to content

Commit b30aaf2

Browse files
committed
get rid of str::from_raw_parts_mut
str::from_raw_parts has been removed long ago because it can be obtained via str::from_utf8_unchecked and slice::from_raw_parts. The same goes for str::from_raw_parts_mut.
1 parent 3ee9d89 commit b30aaf2

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

src/libcore/str/mod.rs

+5-31
Original file line numberDiff line numberDiff line change
@@ -376,35 +376,6 @@ pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
376376
Ok(unsafe { from_utf8_unchecked_mut(v) })
377377
}
378378

379-
/// Forms a str from a pointer and a length.
380-
///
381-
/// The `len` argument is the number of bytes in the string.
382-
///
383-
/// # Safety
384-
///
385-
/// This function is unsafe as there is no guarantee that the given pointer is
386-
/// valid for `len` bytes, nor whether the lifetime inferred is a suitable
387-
/// lifetime for the returned str.
388-
///
389-
/// The data must be valid UTF-8
390-
///
391-
/// `p` must be non-null and aligned, even for zero-length strs, as is
392-
/// required for all references. However, for zero-length strs, `p` can be
393-
/// a bogus non-dereferencable pointer such as [`NonNull::dangling()`].
394-
///
395-
/// # Caveat
396-
///
397-
/// The lifetime for the returned str is inferred from its usage. To
398-
/// prevent accidental misuse, it's suggested to tie the lifetime to whichever
399-
/// source lifetime is safe in the context, such as by providing a helper
400-
/// function taking the lifetime of a host value for the str, or by explicit
401-
/// annotation.
402-
///
403-
/// [`NonNull::dangling()`]: ../../std/ptr/struct.NonNull.html#method.dangling
404-
unsafe fn from_raw_parts_mut<'a>(p: *mut u8, len: usize) -> &'a mut str {
405-
from_utf8_unchecked_mut(slice::from_raw_parts_mut(p, len))
406-
}
407-
408379
/// Converts a slice of bytes to a string slice without checking
409380
/// that the string contains valid UTF-8.
410381
///
@@ -2600,8 +2571,11 @@ impl str {
26002571
let len = self.len();
26012572
let ptr = self.as_ptr() as *mut u8;
26022573
unsafe {
2603-
(from_raw_parts_mut(ptr, mid),
2604-
from_raw_parts_mut(ptr.offset(mid as isize), len - mid))
2574+
(from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr, mid)),
2575+
from_utf8_unchecked_mut(slice::from_raw_parts_mut(
2576+
ptr.offset(mid as isize),
2577+
len - mid
2578+
)))
26052579
}
26062580
} else {
26072581
slice_error_fail(self, 0, mid)

0 commit comments

Comments
 (0)