]> git.proxmox.com Git - rustc.git/blob - vendor/maybe-uninit/tests/doesnt_drop.rs
New upstream version 1.59.0+dfsg1
[rustc.git] / vendor / maybe-uninit / tests / doesnt_drop.rs
1 extern crate maybe_uninit;
2 use maybe_uninit::MaybeUninit;
3
4 use std::cell::Cell;
5
6 struct DecrementOnDrop<'a>(&'a Cell<usize>);
7
8 impl<'a> DecrementOnDrop<'a> {
9 pub fn new(ref_:&'a Cell<usize>) -> Self {
10 ref_.set(1);
11 DecrementOnDrop(ref_)
12 }
13 }
14
15 impl<'a> Clone for DecrementOnDrop<'a> {
16 fn clone(&self) -> Self {
17 self.0.set(self.0.get() + 1);
18
19 DecrementOnDrop(self.0)
20 }
21 }
22
23 impl<'a> Drop for DecrementOnDrop<'a>{
24 fn drop(&mut self) {
25 self.0.set(self.0.get() - 1);
26 }
27 }
28
29 #[test]
30 fn doesnt_drop(){
31 let count = Cell::new(0);
32 let arc = DecrementOnDrop::new(&count);
33 let maybe = MaybeUninit::new(arc.clone());
34 assert_eq!(count.get(), 2);
35 drop(maybe);
36 assert_eq!(count.get(), 2);
37 }