1 #![feature(weak_into_raw)]
3 use std::rc::{Rc, Weak};
6 /// Taken from the `Weak::as_raw` doctest.
8 let strong = Rc::new(Box::new(42));
9 let weak = Rc::downgrade(&strong);
10 // Both point to the same object
11 assert!(ptr::eq(&*strong, Weak::as_raw(&weak)));
12 // The strong here keeps it alive, so we can still access the object.
13 assert_eq!(42, **unsafe { &*Weak::as_raw(&weak) });
16 // But not any more. We can do Weak::as_raw(&weak), but accessing the pointer would lead to
17 // undefined behaviour.
18 assert_eq!(42, **unsafe { &*Weak::as_raw(&weak) }); //~ ERROR dangling pointer