clarify provenance issue in new_owned
This commit is contained in:
parent
b9e3c090d7
commit
eb64585d3c
|
@ -94,6 +94,9 @@ impl Stringish {
|
||||||
/// Alternatively, use the [`Ish::ish`] method.
|
/// Alternatively, use the [`Ish::ish`] method.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new_owned(s: String) -> Self {
|
pub fn new_owned(s: String) -> Self {
|
||||||
|
// converting to a `Vec` is necessary since `s.as_mut_ptr()` would call `str::as_mut_ptr`
|
||||||
|
// through deref coercion, which would only give us a pointer with provenance to the
|
||||||
|
// initialized part of the `String`, which is not enough to deallocate.
|
||||||
let mut v = ManuallyDrop::new(s.into_bytes());
|
let mut v = ManuallyDrop::new(s.into_bytes());
|
||||||
Self {
|
Self {
|
||||||
// SAFETY: `v.as_mut_ptr()` is never null
|
// SAFETY: `v.as_mut_ptr()` is never null
|
||||||
|
|
Loading…
Reference in a new issue