diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-05 22:10:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-05 22:10:02 +0100 |
| commit | b08837f180697b1441d1b9bc374a044d573b83ca (patch) | |
| tree | 3bf9b6e2f7467dd6f571d3306fac22127d54223d /library/alloc/src | |
| parent | 076043346d7ae779623b3d703c32bb391188d235 (diff) | |
| parent | f391c0793b443d30ef8c4d4228550439d4dbfead (diff) | |
| download | rust-b08837f180697b1441d1b9bc374a044d573b83ca.tar.gz rust-b08837f180697b1441d1b9bc374a044d573b83ca.zip | |
Rollup merge of #122018 - RalfJung:box-custom-alloc, r=oli-obk
only set noalias on Box with the global allocator As discovered in https://github.com/rust-lang/miri/issues/3341, `noalias` and custom allocators don't go well together. rustc can now check whether a Box uses the global allocator. This replaces the previous ad-hoc and rather unprincipled check for a zero-sized allocator. This is the rustc part of fixing that; Miri will also need a patch.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/alloc.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/boxed.rs | 3 |
2 files changed, 5 insertions, 0 deletions
diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index e99d6268e53..a5d28aa5252 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -50,6 +50,8 @@ extern "Rust" { #[unstable(feature = "allocator_api", issue = "32838")] #[derive(Copy, Clone, Default, Debug)] #[cfg(not(test))] +// the compiler needs to know when a Box uses the global allocator vs a custom one +#[cfg_attr(not(bootstrap), lang = "global_alloc_ty")] pub struct Global; #[cfg(test)] diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index b202d9250d5..2736e5ee6c5 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -2062,6 +2062,9 @@ impl<Args: Tuple, F: AsyncFn<Args> + ?Sized, A: Allocator> AsyncFn<Args> for Box #[unstable(feature = "coerce_unsized", issue = "18598")] impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {} +// It is quite crucial that we only allow the `Global` allocator here. +// Handling arbitrary custom allocators (which can affect the `Box` layout heavily!) +// would need a lot of codegen and interpreter adjustments. #[unstable(feature = "dispatch_from_dyn", issue = "none")] impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T, Global> {} |
