]> git.proxmox.com Git - rustc.git/blob - src/test/ui/box/leak-alloc.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / src / test / ui / box / leak-alloc.rs
1 #![feature(allocator_api)]
2
3 use std::alloc::{AllocError, Allocator, Layout, System};
4 use std::ptr::NonNull;
5
6 use std::boxed::Box;
7
8 struct Alloc {}
9
10 unsafe impl Allocator for Alloc {
11 fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
12 System.allocate(layout)
13 }
14
15 unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
16 System.deallocate(ptr, layout)
17 }
18 }
19
20 fn use_value(_: u32) {}
21
22 fn main() {
23 let alloc = Alloc {};
24 let boxed = Box::new_in(10, alloc.by_ref());
25 let theref = Box::leak(boxed);
26 drop(alloc);
27 //~^ ERROR cannot move out of `alloc` because it is borrowed
28 use_value(*theref)
29 }