]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/regions-mock-trans.rs
ac8a1c04fbe4fa583172ac238dd3c71f92af071b
[rust.git] / tests / run-pass / regions-mock-trans.rs
1 //ignore-windows: Uses POSIX APIs
2
3 #![feature(rustc_private)]
4
5 #![allow(dead_code)]
6
7 extern crate libc;
8 use std::mem;
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<'a>(_bcx : &'a Arena) -> &'a Bcx<'a> {
26     unsafe {
27         mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>()
28             as libc::size_t))
29     }
30 }
31
32 fn h<'a>(bcx : &'a Bcx<'a>) -> &'a Bcx<'a> {
33     return alloc(bcx.fcx.arena);
34 }
35
36 fn g(fcx : &Fcx) {
37     let bcx = Bcx { fcx: fcx };
38     let bcx2 = h(&bcx);
39     unsafe {
40         libc::free(mem::transmute(bcx2));
41     }
42 }
43
44 fn f(ccx : &Ccx) {
45     let a = Arena(());
46     let fcx = Fcx { arena: &a, ccx: ccx };
47     return g(&fcx);
48 }
49
50 pub fn main() {
51     let ccx = Ccx { x: 0 };
52     f(&ccx);
53 }