summaryrefslogtreecommitdiffstats
path: root/library/alloc/src/rc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /library/alloc/src/rc
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/alloc/src/rc')
-rw-r--r--library/alloc/src/rc/tests.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/library/alloc/src/rc/tests.rs b/library/alloc/src/rc/tests.rs
index 2784108e0..1f221b86f 100644
--- a/library/alloc/src/rc/tests.rs
+++ b/library/alloc/src/rc/tests.rs
@@ -574,3 +574,48 @@ fn test_rc_cyclic_with_two_ref() {
assert_eq!(Rc::strong_count(&two_refs), 3);
assert_eq!(Rc::weak_count(&two_refs), 2);
}
+
+#[test]
+fn test_unique_rc_weak() {
+ let rc = UniqueRc::new(42);
+ let weak = UniqueRc::downgrade(&rc);
+ assert!(weak.upgrade().is_none());
+
+ let _rc = UniqueRc::into_rc(rc);
+ assert_eq!(*weak.upgrade().unwrap(), 42);
+}
+
+#[test]
+fn test_unique_rc_drop_weak() {
+ let rc = UniqueRc::new(42);
+ let weak = UniqueRc::downgrade(&rc);
+ mem::drop(weak);
+
+ let rc = UniqueRc::into_rc(rc);
+ assert_eq!(*rc, 42);
+}
+
+#[test]
+fn test_unique_rc_drops_contents() {
+ let mut dropped = false;
+ struct DropMe<'a>(&'a mut bool);
+ impl Drop for DropMe<'_> {
+ fn drop(&mut self) {
+ *self.0 = true;
+ }
+ }
+ {
+ let rc = UniqueRc::new(DropMe(&mut dropped));
+ drop(rc);
+ }
+ assert!(dropped);
+}
+
+#[test]
+fn test_unique_rc_weak_clone_holding_ref() {
+ let mut v = UniqueRc::new(0u8);
+ let w = UniqueRc::downgrade(&v);
+ let r = &mut *v;
+ let _ = w.clone(); // touch weak count
+ *r = 123;
+}