]> git.lizzy.rs Git - rust.git/blob - src/test/ui/drop/issue-90752.rs
Rollup merge of #92959 - asquared31415:test-non-fn-help, r=estebank
[rust.git] / src / test / ui / drop / issue-90752.rs
1 // run-pass
2
3 use std::cell::RefCell;
4
5 struct S<'a>(i32, &'a RefCell<Vec<i32>>);
6
7 impl<'a> Drop for S<'a> {
8     fn drop(&mut self) {
9         self.1.borrow_mut().push(self.0);
10     }
11 }
12
13 fn test(drops: &RefCell<Vec<i32>>) {
14     let mut foo = None;
15     match foo {
16         None => (),
17         _ => return,
18     }
19
20     *(&mut foo) = Some((S(0, drops), S(1, drops))); // Both S(0) and S(1) should be dropped
21
22     match foo {
23         Some((_x, _)) => {}
24         _ => {}
25     }
26 }
27
28 fn main() {
29     let drops = RefCell::new(Vec::new());
30     test(&drops);
31     assert_eq!(*drops.borrow(), &[0, 1]);
32 }