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