rust/tests/pass-dep/regions-mock-trans.rs

46 lines
735 B
Rust
Raw Normal View History

2017-06-21 08:51:42 -05:00
use std::mem;
2017-06-22 05:30:02 -05:00
struct Arena(());
2017-06-21 08:51:42 -05:00
struct Bcx<'a> {
fcx: &'a Fcx<'a>,
2017-06-21 08:51:42 -05:00
}
#[allow(dead_code)]
2017-06-21 08:51:42 -05:00
struct Fcx<'a> {
2017-06-22 05:30:02 -05:00
arena: &'a Arena,
ccx: &'a Ccx,
2017-06-21 08:51:42 -05:00
}
#[allow(dead_code)]
2017-06-21 08:51:42 -05:00
struct Ccx {
x: isize,
2017-06-21 08:51:42 -05:00
}
fn alloc<'a>(_bcx: &'a Arena) -> &'a mut Bcx<'a> {
unsafe { mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>() as libc::size_t)) }
2017-06-21 08:51:42 -05:00
}
fn h<'a>(bcx: &'a Bcx<'a>) -> &'a mut Bcx<'a> {
2017-06-21 08:51:42 -05:00
return alloc(bcx.fcx.arena);
}
fn g(fcx: &Fcx) {
2017-06-21 08:51:42 -05:00
let bcx = Bcx { fcx: fcx };
let bcx2 = h(&bcx);
unsafe {
libc::free(mem::transmute(bcx2));
}
}
fn f(ccx: &Ccx) {
2017-06-22 05:30:02 -05:00
let a = Arena(());
2017-06-21 08:51:42 -05:00
let fcx = Fcx { arena: &a, ccx: ccx };
return g(&fcx);
}
pub fn main() {
let ccx = Ccx { x: 0 };
f(&ccx);
}