2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2018-09-25 23:51:35 +02:00
|
|
|
#![allow(dead_code)]
|
2018-08-31 15:02:01 +02:00
|
|
|
#![allow(non_camel_case_types)]
|
2017-10-22 20:01:00 -07:00
|
|
|
#![feature(allocator_api)]
|
2015-03-05 18:33:58 -08:00
|
|
|
|
2020-12-04 14:47:15 +01:00
|
|
|
use std::alloc::{handle_alloc_error, Allocator, Global, Layout};
|
2018-04-03 08:51:02 +09:00
|
|
|
use std::ptr::NonNull;
|
2013-05-24 19:35:29 -07:00
|
|
|
|
2013-03-07 16:36:30 -08:00
|
|
|
struct arena(());
|
2012-03-23 14:42:39 -07:00
|
|
|
|
2013-12-09 23:16:18 -08:00
|
|
|
struct Bcx<'a> {
|
2020-03-24 11:45:38 +01:00
|
|
|
fcx: &'a Fcx<'a>,
|
2013-01-25 22:46:32 -08:00
|
|
|
}
|
2012-03-23 14:42:39 -07:00
|
|
|
|
2013-12-09 23:16:18 -08:00
|
|
|
struct Fcx<'a> {
|
|
|
|
|
arena: &'a arena,
|
2020-03-24 11:45:38 +01:00
|
|
|
ccx: &'a Ccx,
|
2013-01-25 22:46:32 -08:00
|
|
|
}
|
2012-03-23 14:42:39 -07:00
|
|
|
|
2013-01-25 22:46:32 -08:00
|
|
|
struct Ccx {
|
2020-03-24 11:45:38 +01:00
|
|
|
x: isize,
|
2013-01-25 22:46:32 -08:00
|
|
|
}
|
2012-03-23 14:42:39 -07:00
|
|
|
|
2023-02-12 16:30:37 +01:00
|
|
|
fn allocate(_bcx: &arena) -> &mut Bcx<'_> {
|
2013-01-23 11:43:58 -08:00
|
|
|
unsafe {
|
2018-05-15 09:56:46 +09:00
|
|
|
let layout = Layout::new::<Bcx>();
|
2020-12-04 14:47:15 +01:00
|
|
|
let ptr = Global.allocate(layout).unwrap_or_else(|_| handle_alloc_error(layout));
|
2023-02-12 16:30:37 +01:00
|
|
|
&mut *ptr.as_ptr().cast()
|
2013-01-23 11:43:58 -08:00
|
|
|
}
|
2012-03-23 14:42:39 -07:00
|
|
|
}
|
|
|
|
|
|
2023-02-12 16:30:37 +01:00
|
|
|
fn h<'a>(bcx: &'a Bcx<'a>) -> &'a mut Bcx<'a> {
|
2020-12-04 14:47:15 +01:00
|
|
|
return allocate(bcx.fcx.arena);
|
2012-03-23 14:42:39 -07:00
|
|
|
}
|
|
|
|
|
|
2020-03-03 00:08:24 +01:00
|
|
|
fn g(fcx: &Fcx) {
|
|
|
|
|
let bcx = Bcx { fcx };
|
2012-03-23 14:42:39 -07:00
|
|
|
let bcx2 = h(&bcx);
|
2012-03-23 15:17:34 -07:00
|
|
|
unsafe {
|
2023-02-12 16:30:37 +01:00
|
|
|
Global.deallocate(NonNull::new_unchecked(bcx2 as *mut _ as *mut _), Layout::new::<Bcx>());
|
2012-03-23 15:17:34 -07:00
|
|
|
}
|
2012-03-23 14:42:39 -07:00
|
|
|
}
|
|
|
|
|
|
2020-03-03 00:08:24 +01:00
|
|
|
fn f(ccx: &Ccx) {
|
2012-03-23 14:42:39 -07:00
|
|
|
let a = arena(());
|
2020-03-03 00:08:24 +01:00
|
|
|
let fcx = Fcx { arena: &a, ccx };
|
2012-08-01 17:30:05 -07:00
|
|
|
return g(&fcx);
|
2012-03-23 14:42:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2013-01-25 22:46:32 -08:00
|
|
|
let ccx = Ccx { x: 0 };
|
2012-03-23 14:42:39 -07:00
|
|
|
f(&ccx);
|
|
|
|
|
}
|