test the Rc::{into,from}_raw roundtrip

This uses some pointer arithmetic based on field offsets
This commit is contained in:
Ralf Jung 2017-06-12 15:22:58 -07:00
parent 03577a905a
commit 4b1a12c240

View File

@ -8,6 +8,16 @@ fn rc_refcell() -> i32 {
x
}
fn rc_raw() {
let r = Rc::new(0);
let r2 = Rc::into_raw(r.clone());
let r2 = unsafe { Rc::from_raw(r2) };
assert!(Rc::ptr_eq(&r, &r2));
drop(r);
assert!(Rc::try_unwrap(r2).is_ok());
}
fn main() {
rc_refcell();
rc_raw();
}