Skip to content

Commit 6f7be53

Browse files
committed
WIP: Allocation before main Test that should fail currently
1 parent 3f10032 commit 6f7be53

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tests/ui/runtime/aborting-alloc.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// Helper for 'no-allocation-before-main'.
2+
///
3+
/// This also contains a meta-test to make sure that the AbortingAllocator does indeed abort.
4+
//@ run-fail
5+
6+
pub struct AbortingAllocator;
7+
8+
unsafe impl std::alloc::GlobalAlloc for AbortingAllocator {
9+
unsafe fn alloc(&self, _: std::alloc::Layout) -> *mut u8 {
10+
std::process::abort()
11+
}
12+
13+
unsafe fn dealloc(&self, _: *mut u8, _: std::alloc::Layout) {
14+
std::process::abort()
15+
}
16+
}
17+
18+
#[global_allocator]
19+
static ALLOCATOR: AbortingAllocator = AbortingAllocator;
20+
21+
fn main() {
22+
std::hint::black_box(Box::new(false));
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Tests that a program with no body does not allocate.
2+
//!
3+
//! The initial runtime should not allocate for performance/binary size reasons.
4+
//@ run-pass
5+
6+
#[allow(dead_code)]
7+
#[path = "aborting-alloc.rs"]
8+
mod aux;
9+
10+
fn main() {}

0 commit comments

Comments
 (0)