Skip to content

Commit 1cec942

Browse files
committed
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;
1 parent a8b5039 commit 1cec942

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

alloc/src/alloc.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ extern "Rust" {
3737
#[rustc_allocator_zeroed]
3838
#[rustc_nounwind]
3939
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
40+
41+
#[cfg(not(bootstrap))]
42+
static __rust_no_alloc_shim_is_unstable: u8;
4043
}
4144

4245
/// The global memory allocator.
@@ -90,7 +93,14 @@ pub use std::alloc::Global;
9093
#[must_use = "losing the pointer will leak memory"]
9194
#[inline]
9295
pub unsafe fn alloc(layout: Layout) -> *mut u8 {
93-
unsafe { __rust_alloc(layout.size(), layout.align()) }
96+
unsafe {
97+
// Make sure we don't accidentally allow omitting the allocator shim in
98+
// stable code until it is actually stabilized.
99+
#[cfg(not(bootstrap))]
100+
core::ptr::read_volatile(&__rust_no_alloc_shim_is_unstable);
101+
102+
__rust_alloc(layout.size(), layout.align())
103+
}
94104
}
95105

96106
/// Deallocate memory with the global allocator.

0 commit comments

Comments
 (0)