rust/tests/ui/hygiene
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
..
auxiliary remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
arguments.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
arguments.stderr remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
assoc_item_ctxt.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
assoc_item_ctxt.stderr remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
assoc_ty_bindings.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
cross-crate-codegen-attrs.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-define-and-use.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-fields.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-glob-hygiene.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-glob-hygiene.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-methods.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-name-collision.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-name-hiding-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-name-hiding-2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-name-hiding.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-name-hiding.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-redefine.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-redefine.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cross-crate-variants.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
dollar-crate-modern.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
duplicate_lifetimes.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
duplicate_lifetimes.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
eager-from-opaque-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
eager-from-opaque.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expansion-info-reset.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expansion-info-reset.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
extern-prelude-from-opaque-fail-2018.rs Add filter with next segment while lookup typo for path 2023-07-07 09:00:50 +08:00
extern-prelude-from-opaque-fail-2018.stderr adjust smart_resolve_partial_mod_path_errors 2023-07-07 10:19:30 +08:00
extern-prelude-from-opaque-fail.rs Add filter with next segment while lookup typo for path 2023-07-07 09:00:50 +08:00
extern-prelude-from-opaque-fail.stderr adjust smart_resolve_partial_mod_path_errors 2023-07-07 10:19:30 +08:00
fields-definition.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fields-definition.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fields-move.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fields-move.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fields-numeric-borrowck.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fields-numeric-borrowck.stderr Do not set up wrong span for adjustments 2023-07-10 20:09:26 +00:00
fields.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
fields.stderr remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
for-loop.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
generate-mod.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
generate-mod.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
generic_params.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
globs.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
globs.stderr Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
hir-res-hygiene.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygiene-dodging-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygiene.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-label-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-label-1.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-label-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-label-2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-label-3.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-label-3.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-label-4.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-label-4.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-labels-in-let.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
hygienic-labels.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
impl_items-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
impl_items-2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
impl_items.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
impl_items.stderr remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
intercrate.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
intercrate.stderr remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
issue-15221.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-32922.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-40847.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-44128.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-47311.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
issue-47312.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
issue-61574-const-parameters.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-77523-def-site-async-await.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
items.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
lambda-var-hygiene.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
legacy_interaction.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
lexical.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
local_inner_macros.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
macro-metavars-legacy.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
macro-metavars-transparent.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
missing-self-diag.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
missing-self-diag.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
nested_macro_privacy.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
nested_macro_privacy.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
nested-dollar-crate.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
no_implicit_prelude-2018.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
no_implicit_prelude-2018.stderr Make "consider importing" consistent for macros 2023-06-10 00:06:34 +08:00
no_implicit_prelude-2021.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
no_implicit_prelude.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
no_implicit_prelude.stderr Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
panic-location.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
panic-location.run.stderr Eliminate ZST allocations in Box and Vec 2023-07-13 15:00:53 +01:00
pattern-macro.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pattern-macro.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
prelude-import-hygiene.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
privacy-early.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
privacy-early.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
privacy.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
privacy.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
rustc-macro-transparency.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
rustc-macro-transparency.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
specialization.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
stdlib-prelude-from-opaque-early.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
stdlib-prelude-from-opaque-late.rs Rename drop_copy lint to dropping_copy_types 2023-05-21 13:37:32 +02:00
thread-local-not-in-prelude.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
trait_items-2.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
trait_items.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
trait_items.stderr Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
traits-in-scope.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
transparent-basic.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
unpretty-debug.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
unpretty-debug.stdout Move /src/test to /tests 2023-01-11 09:32:08 +00:00
wrap_unhygienic_example.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
xcrate.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00