diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/maybe-uninit/tests | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/maybe-uninit/tests')
-rw-r--r-- | third_party/rust/maybe-uninit/tests/doesnt_drop.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/third_party/rust/maybe-uninit/tests/doesnt_drop.rs b/third_party/rust/maybe-uninit/tests/doesnt_drop.rs new file mode 100644 index 0000000000..1d4b30fc46 --- /dev/null +++ b/third_party/rust/maybe-uninit/tests/doesnt_drop.rs @@ -0,0 +1,37 @@ +extern crate maybe_uninit; +use maybe_uninit::MaybeUninit; + +use std::cell::Cell; + +struct DecrementOnDrop<'a>(&'a Cell<usize>); + +impl<'a> DecrementOnDrop<'a> { + pub fn new(ref_:&'a Cell<usize>) -> Self { + ref_.set(1); + DecrementOnDrop(ref_) + } +} + +impl<'a> Clone for DecrementOnDrop<'a> { + fn clone(&self) -> Self { + self.0.set(self.0.get() + 1); + + DecrementOnDrop(self.0) + } +} + +impl<'a> Drop for DecrementOnDrop<'a>{ + fn drop(&mut self) { + self.0.set(self.0.get() - 1); + } +} + +#[test] +fn doesnt_drop(){ + let count = Cell::new(0); + let arc = DecrementOnDrop::new(&count); + let maybe = MaybeUninit::new(arc.clone()); + assert_eq!(count.get(), 2); + drop(maybe); + assert_eq!(count.get(), 2); +} |