]> git.lizzy.rs Git - rust.git/blob - tests/ui/regions/regions-mock-codegen.rs
internally change regions to be covariant
[rust.git] / tests / 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, Allocator, 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 allocate(_bcx: &arena) -> &Bcx<'_> {
26     unsafe {
27         let layout = Layout::new::<Bcx>();
28         let ptr = Global.allocate(layout).unwrap_or_else(|_| handle_alloc_error(layout));
29         &*(ptr.as_ptr() as *const _)
30     }
31 }
32
33 fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> {
34     return allocate(bcx.fcx.arena);
35 }
36
37 fn g(fcx: &Fcx) {
38     let bcx = Bcx { fcx };
39     let bcx2 = h(&bcx);
40     unsafe {
41         Global.deallocate(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>());
42     }
43 }
44
45 fn f(ccx: &Ccx) {
46     let a = arena(());
47     let fcx = Fcx { arena: &a, ccx };
48     return g(&fcx);
49 }
50
51 pub fn main() {
52     let ccx = Ccx { x: 0 };
53     f(&ccx);
54 }