Similar to what #58183 did for Box, I think we should document a guarantee that Vec<T> and String are allocated through the standard library’s global allocator.
Namely:
-
It is valid (under some conditions) to pass a pointer allocated with std::alloc::Global (or corresponding free functions in std::alloc) to Vec::from_raw_parts.
-
It is valid (under some conditions) to deallocate or reallocate with std::alloc::Global (or corresponding free functions in std::alloc) a pointer from Vec::into_raw_parts (or from ManuallyDrop + Vec::as_mut_ptr).
Conditions include using the appropriate std::alloc::Layout, properly transferring ownership, etc.
Perhaps the documented guarantees should also extend to using NonNull<T>::dangling for zero-size allocations. (And similarly for Box.)
@rust-lang/libs, any throughts?
Similar to what #58183 did for
Box, I think we should document a guarantee thatVec<T>andStringare allocated through the standard library’s global allocator.Namely:
It is valid (under some conditions) to pass a pointer allocated with
std::alloc::Global(or corresponding free functions instd::alloc) toVec::from_raw_parts.It is valid (under some conditions) to deallocate or reallocate with
std::alloc::Global(or corresponding free functions instd::alloc) a pointer fromVec::into_raw_parts(or fromManuallyDrop+Vec::as_mut_ptr).Conditions include using the appropriate
std::alloc::Layout, properly transferring ownership, etc.Perhaps the documented guarantees should also extend to using
NonNull<T>::danglingfor zero-size allocations. (And similarly forBox.)@rust-lang/libs, any throughts?