rust/library
bors cca3373706 Auto merge of #113113 - Amanieu:box-vec-zst, r=Mark-Simulacrum
Eliminate ZST allocations in `Box` and `Vec`

This PR fixes 2 issues with `Box` and `RawVec` related to ZST allocations. Specifically, the `Allocator` trait requires that:
- If you allocate a zero-sized layout then you must later deallocate it, otherwise the allocator may leak memory.
- You cannot pass a ZST pointer to the allocator that you haven't previously allocated.

These restrictions exist because an allocator implementation is allowed to allocate non-zero amounts of memory for a zero-sized allocation. For example, `malloc` in libc does this.

Currently, ZSTs are handled differently in `Box` and `Vec`:
- `Vec` never allocates when `T` is a ZST or if the vector capacity is 0.
- `Box` just blindly passes everything on to the allocator, including ZSTs.

This causes problems due to the free conversions between `Box<[T]>` and `Vec<T>`, specifically that ZST allocations could get leaked or a dangling pointer could be passed to `deallocate`.

This PR fixes this by changing `Box` to not allocate for zero-sized values and slices. It also fixes a bug in `RawVec::shrink` where shrinking to a size of zero did not actually free the backing memory.
2023-07-14 01:59:08 +00:00
..
alloc Auto merge of #113113 - Amanieu:box-vec-zst, r=Mark-Simulacrum 2023-07-14 01:59:08 +00:00
backtrace@e1c49fbd61 Update std to backtrace 0.3.68 2023-07-02 17:02:45 -07:00
core Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
panic_abort
panic_unwind
portable-simd Sync portable-simd to 2023 July 07 2023-07-07 04:07:00 -07:00
proc_macro Merge proc_macro_span_shrink and proc_macro_span 2023-06-20 19:40:26 -04:00
profiler_builtins
rtstartup
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Rollup merge of #113618 - tshepang:patch-1, r=jyn514 2023-07-14 01:03:08 +02:00
stdarch@d77878b729
sysroot Expose compiler-builtins-weak-intrinsics feature for -Zbuild-std 2023-06-23 11:15:34 +01:00
test Auto merge of #111992 - ferrocene:pa-panic-abort-tests-bench, r=m-ou-se 2023-07-01 07:07:50 +00:00
unwind wip: Support Apple tvOS in libstd 2023-06-21 14:59:37 -07:00