3 // ignore-wasm32-bare compiled with panic=abort by default
5 use std::cell::RefCell;
8 pub struct DropLogger<'a> {
10 log: &'a panic::AssertUnwindSafe<RefCell<Vec<usize>>>
13 impl<'a> Drop for DropLogger<'a> {
15 self.log.0.borrow_mut().push(self.id);
19 struct InjectedFailure;
21 #[allow(unreachable_code)]
23 let log = panic::AssertUnwindSafe(RefCell::new(vec![]));
24 let d = |id| DropLogger { id: id, log: &log };
25 let get = || -> Vec<_> {
26 let mut m = log.0.borrow_mut();
32 let _x = (d(0), &d(1), d(2), &d(3));
33 // all borrows are extended - nothing has been dropped yet
34 assert_eq!(get(), vec![]);
36 // in a let-statement, extended places are dropped
37 // *after* the let result (tho they have the same scope
38 // as far as scope-based borrowck goes).
39 assert_eq!(get(), vec![0, 2, 3, 1]);
41 let _ = std::panic::catch_unwind(|| {
42 (d(4), &d(5), d(6), &d(7), panic::panic_any(InjectedFailure));
45 // here, the temporaries (5/7) live until the end of the
46 // containing statement, which is destroyed after the operands
48 assert_eq!(get(), vec![6, 4, 7, 5]);