2018-08-30 08:57:17 -05:00
|
|
|
//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
|
|
|
|
|
|
|
extern crate libc;
|
2020-11-10 09:51:07 -06:00
|
|
|
|
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>
|
|
|
|
}
|
|
|
|
|
2020-04-16 02:25:12 -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,
|
2017-06-21 08:51:42 -05:00
|
|
|
ccx: &'a Ccx
|
|
|
|
}
|
|
|
|
|
2020-04-16 02:25:12 -05:00
|
|
|
#[allow(dead_code)]
|
2017-06-21 08:51:42 -05:00
|
|
|
struct Ccx {
|
|
|
|
x: isize
|
|
|
|
}
|
|
|
|
|
2019-04-15 10:06:42 -05:00
|
|
|
fn alloc<'a>(_bcx : &'a Arena) -> &'a mut Bcx<'a> {
|
2017-06-21 08:51:42 -05:00
|
|
|
unsafe {
|
|
|
|
mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>()
|
|
|
|
as libc::size_t))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 10:06: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) {
|
|
|
|
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);
|
|
|
|
}
|