Files
rust/tests/ui/box/leak-alloc.rs
Nia Deckers f4d4ee7489 allocator: refactor for stabilisation
yk what we can do btree later

raaaaagh

pain and suffering

*unleaks your box* whats thiSegmentation fault (core dumped)

straight up testing it. and by it,

well, let's just say. "my allocator"

linked and listed

the unnecesary bits? gone. reduced to atoms
2026-08-09 17:37:43 +02:00

30 lines
661 B
Rust

#![feature(allocator_api)]
use std::alloc::{AllocError, Allocator, Layout, System};
use std::ptr::NonNull;
use std::boxed::Box;
struct Alloc {}
unsafe impl Allocator for Alloc {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
System.allocate(layout)
}
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
System.deallocate(ptr, layout)
}
}
fn use_value(_: u32) {}
fn main() {
let alloc = Alloc {};
let boxed = Box::new_in(10, &alloc);
let theref = Box::leak(boxed);
drop(alloc);
//~^ ERROR cannot move out of `alloc` because it is borrowed
use_value(*theref)
}