diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2022-09-10 11:33:44 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2023-05-11 14:35:09 +0000 |
| commit | 66982a383b6f7d3a933fc6896202632bee7161a4 (patch) | |
| tree | ed731f72cfa4b15ef644e34a1bca986a580a588a /library/alloc/src | |
| parent | 145b0574efd63603f35beda4d6b69933c8a01c1f (diff) | |
| download | rust-66982a383b6f7d3a933fc6896202632bee7161a4.tar.gz rust-66982a383b6f7d3a933fc6896202632bee7161a4.zip | |
Prevent insta-stable no alloc shim support
You will need to add the following as replacement for the old __rust_*
definitions when not using the alloc shim.
#[no_mangle]
static __rust_no_alloc_shim_is_unstable: u8 = 0;
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/alloc.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 6f2ba957bcd..01d1fdc9b2a 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -37,6 +37,9 @@ extern "Rust" { #[rustc_allocator_zeroed] #[rustc_nounwind] fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8; + + #[cfg(not(bootstrap))] + static __rust_no_alloc_shim_is_unstable: u8; } /// The global memory allocator. @@ -90,7 +93,14 @@ pub use std::alloc::Global; #[must_use = "losing the pointer will leak memory"] #[inline] pub unsafe fn alloc(layout: Layout) -> *mut u8 { - unsafe { __rust_alloc(layout.size(), layout.align()) } + unsafe { + // Make sure we don't accidentally allow omitting the allocator shim in + // stable code until it is actually stabilized. + #[cfg(not(bootstrap))] + core::ptr::read_volatile(&__rust_no_alloc_shim_is_unstable); + + __rust_alloc(layout.size(), layout.align()) + } } /// Deallocate memory with the global allocator. |
