rust/tests/run-pass-fullmir/box-pair-to-vec.rs

31 lines
669 B
Rust
Raw Normal View History

2018-11-20 02:12:29 -06:00
//ignore-msvc: Stdout not implemented on Windows
2018-11-19 03:26:40 -06:00
#[repr(C)]
#[derive(Debug)]
struct PairFoo {
fst: Foo,
snd: Foo,
}
#[derive(Debug)]
struct Foo(u64);
fn reinterstruct(box_pair: Box<PairFoo>) -> Vec<Foo> {
let ref_pair = Box::leak(box_pair) as *mut PairFoo;
let ptr_foo = unsafe { &mut (*ref_pair).fst as *mut Foo };
unsafe {
Vec::from_raw_parts(ptr_foo, 2, 2)
}
}
fn main() {
let pair_foo = Box::new(PairFoo {
fst: Foo(42),
snd: Foo(1337),
});
println!("pair_foo = {:?}", pair_foo);
for (n, foo) in reinterstruct(pair_foo).into_iter().enumerate() {
println!("foo #{} = {:?}", n, foo);
}
}