about summary refs log tree commit diff
path: root/tests/rustdoc-js-std/parser-slice-array.js
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-14 01:59:08 +0000
committerbors <bors@rust-lang.org>2023-07-14 01:59:08 +0000
commitcca3373706b8f5fa12a1b7f18222dde4c3ed6e32 (patch)
tree1e2ea5116b68ea0f322d1093db43841033762485 /tests/rustdoc-js-std/parser-slice-array.js
parent7a5814f922f85370e773f2001886b8f57002811c (diff)
parentd24be14276bc5e52c6ab42d29ab2ed717b2b583c (diff)
downloadrust-cca3373706b8f5fa12a1b7f18222dde4c3ed6e32.tar.gz
rust-cca3373706b8f5fa12a1b7f18222dde4c3ed6e32.zip
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.
Diffstat (limited to 'tests/rustdoc-js-std/parser-slice-array.js')
0 files changed, 0 insertions, 0 deletions