]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
0bf4aa26 | 2 | #![allow(dead_code)] |
b7449926 | 3 | #![allow(non_camel_case_types)] |
c34b1796 | 4 | // pretty-expanded FIXME #23616 |
abe05a73 | 5 | #![feature(allocator_api)] |
c34b1796 | 6 | |
ba9703b0 | 7 | use std::alloc::{handle_alloc_error, AllocInit, AllocRef, Global, Layout}; |
83c7162d | 8 | use std::ptr::NonNull; |
970d7e83 | 9 | |
223e47cc LB |
10 | struct arena(()); |
11 | ||
1a4d82fc | 12 | struct Bcx<'a> { |
ba9703b0 | 13 | fcx: &'a Fcx<'a>, |
223e47cc LB |
14 | } |
15 | ||
1a4d82fc JJ |
16 | struct Fcx<'a> { |
17 | arena: &'a arena, | |
ba9703b0 | 18 | ccx: &'a Ccx, |
223e47cc LB |
19 | } |
20 | ||
21 | struct Ccx { | |
ba9703b0 | 22 | x: isize, |
223e47cc LB |
23 | } |
24 | ||
74b04a01 | 25 | fn alloc(_bcx: &arena) -> &Bcx<'_> { |
223e47cc | 26 | unsafe { |
94b46f34 | 27 | let layout = Layout::new::<Bcx>(); |
ba9703b0 XL |
28 | let memory = Global |
29 | .alloc(layout, AllocInit::Uninitialized) | |
30 | .unwrap_or_else(|_| handle_alloc_error(layout)); | |
31 | &*(memory.ptr.as_ptr() as *const _) | |
223e47cc LB |
32 | } |
33 | } | |
34 | ||
74b04a01 | 35 | fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> { |
223e47cc LB |
36 | return alloc(bcx.fcx.arena); |
37 | } | |
38 | ||
74b04a01 XL |
39 | fn g(fcx: &Fcx) { |
40 | let bcx = Bcx { fcx }; | |
223e47cc LB |
41 | let bcx2 = h(&bcx); |
42 | unsafe { | |
83c7162d | 43 | Global.dealloc(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>()); |
223e47cc LB |
44 | } |
45 | } | |
46 | ||
74b04a01 | 47 | fn f(ccx: &Ccx) { |
223e47cc | 48 | let a = arena(()); |
74b04a01 | 49 | let fcx = Fcx { arena: &a, ccx }; |
223e47cc LB |
50 | return g(&fcx); |
51 | } | |
52 | ||
53 | pub fn main() { | |
54 | let ccx = Ccx { x: 0 }; | |
55 | f(&ccx); | |
56 | } |