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

54 lines
816 B
Rust
Raw Normal View History

//ignore-windows: Uses POSIX APIs
2017-09-16 06:32:38 -05:00
2018-12-13 13:25:24 -06:00
#![feature(rustc_private)]
2017-06-21 08:51:42 -05:00
2017-06-22 05:30:02 -05:00
#![allow(dead_code)]
2017-06-21 08:51:42 -05:00
extern crate libc;
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>
}
struct Fcx<'a> {
2017-06-22 05:30:02 -05:00
arena: &'a Arena,
2017-06-21 08:51:42 -05:00
ccx: &'a Ccx
}
struct Ccx {
x: isize
}
2017-06-22 05:30:02 -05:00
fn alloc<'a>(_bcx : &'a Arena) -> &'a Bcx<'a> {
2017-06-21 08:51:42 -05:00
unsafe {
mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>()
as libc::size_t))
}
}
fn h<'a>(bcx : &'a Bcx<'a>) -> &'a Bcx<'a> {
return alloc(bcx.fcx.arena);
}
fn g(fcx : &Fcx) {
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);
}