4 use std
::cell
::RefCell
;
7 pub struct DropLogger
<'a
> {
9 log
: &'a panic
::AssertUnwindSafe
<RefCell
<Vec
<usize>>>
12 impl<'a
> Drop
for DropLogger
<'a
> {
14 self.log
.0.borrow_mut().push(self.id
);
18 struct InjectedFailure
;
20 #[allow(unreachable_code)]
22 let log
= panic
::AssertUnwindSafe(RefCell
::new(vec
![]));
23 let d
= |id
| DropLogger { id: id, log: &log }
;
24 let get
= || -> Vec
<_
> {
25 let mut m
= log
.0.borrow_mut();
31 let _x
= (d(0), &d(1), d(2), &d(3));
32 // all borrows are extended - nothing has been dropped yet
33 assert_eq
!(get(), vec
![]);
35 // in a let-statement, extended places are dropped
36 // *after* the let result (tho they have the same scope
37 // as far as scope-based borrowck goes).
38 assert_eq
!(get(), vec
![0, 2, 3, 1]);
40 let _
= std
::panic
::catch_unwind(|| {
41 (d(4), &d(5), d(6), &d(7), panic
::panic_any(InjectedFailure
));
44 // here, the temporaries (5/7) live until the end of the
45 // containing statement, which is destroyed after the operands
47 assert_eq
!(get(), vec
![6, 4, 7, 5]);