1 // This should fail even without validation
2 // compile-flags: -Zmiri-disable-validation
3 #![feature(weak_into_raw)]
5 use std::rc::{Rc, Weak};
8 /// Taken from the `Weak::as_raw` doctest.
10 let strong = Rc::new(Box::new(42));
11 let weak = Rc::downgrade(&strong);
12 // Both point to the same object
13 assert!(ptr::eq(&*strong, Weak::as_raw(&weak)));
14 // The strong here keeps it alive, so we can still access the object.
15 assert_eq!(42, **unsafe { &*Weak::as_raw(&weak) });
18 // But not any more. We can do Weak::as_raw(&weak), but accessing the pointer would lead to
19 // undefined behaviour.
20 assert_eq!(42, **unsafe { &*Weak::as_raw(&weak) }); //~ ERROR dangling pointer