]> git.proxmox.com Git - rustc.git/blob - src/test/ui/regions/regions-mock-codegen.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / test / ui / regions / regions-mock-codegen.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(non_camel_case_types)]
4 // pretty-expanded FIXME #23616
5 #![feature(allocator_api)]
6
7 use std::alloc::{handle_alloc_error, AllocInit, AllocRef, Global, Layout};
8 use std::ptr::NonNull;
9
10 struct arena(());
11
12 struct Bcx<'a> {
13 fcx: &'a Fcx<'a>,
14 }
15
16 struct Fcx<'a> {
17 arena: &'a arena,
18 ccx: &'a Ccx,
19 }
20
21 struct Ccx {
22 x: isize,
23 }
24
25 fn alloc(_bcx: &arena) -> &Bcx<'_> {
26 unsafe {
27 let layout = Layout::new::<Bcx>();
28 let memory = Global
29 .alloc(layout, AllocInit::Uninitialized)
30 .unwrap_or_else(|_| handle_alloc_error(layout));
31 &*(memory.ptr.as_ptr() as *const _)
32 }
33 }
34
35 fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> {
36 return alloc(bcx.fcx.arena);
37 }
38
39 fn g(fcx: &Fcx) {
40 let bcx = Bcx { fcx };
41 let bcx2 = h(&bcx);
42 unsafe {
43 Global.dealloc(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>());
44 }
45 }
46
47 fn f(ccx: &Ccx) {
48 let a = arena(());
49 let fcx = Fcx { arena: &a, ccx };
50 return g(&fcx);
51 }
52
53 pub fn main() {
54 let ccx = Ccx { x: 0 };
55 f(&ccx);
56 }