about summary refs log tree commit diff
path: root/library/alloctests
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-02-06 12:09:45 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-03-07 19:11:13 +0000
commit701bedc323b0314ef6f084ba98ed18327faa36bc (patch)
tree447ae293e9cb286685c766c2c2c3ef0593428d55 /library/alloctests
parentbe1e0b786df35a535327ed3b1457622e357bae6d (diff)
downloadrust-701bedc323b0314ef6f084ba98ed18327faa36bc.tar.gz
rust-701bedc323b0314ef6f084ba98ed18327faa36bc.zip
Move last remaining Rc test to alloctests
Diffstat (limited to 'library/alloctests')
-rw-r--r--library/alloctests/tests/rc.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/library/alloctests/tests/rc.rs b/library/alloctests/tests/rc.rs
index 0628011ba68..bb68eb4ac9e 100644
--- a/library/alloctests/tests/rc.rs
+++ b/library/alloctests/tests/rc.rs
@@ -316,6 +316,24 @@ fn weak_self_cyclic() {
 }
 
 #[test]
+fn is_unique() {
+    fn is_unique<T>(this: &Rc<T>) -> bool {
+        Rc::weak_count(this) == 0 && Rc::strong_count(this) == 1
+    }
+
+    let x = Rc::new(3);
+    assert!(is_unique(&x));
+    let y = x.clone();
+    assert!(!is_unique(&x));
+    drop(y);
+    assert!(is_unique(&x));
+    let w = Rc::downgrade(&x);
+    assert!(!is_unique(&x));
+    drop(w);
+    assert!(is_unique(&x));
+}
+
+#[test]
 fn test_strong_count() {
     let a = Rc::new(0);
     assert!(Rc::strong_count(&a) == 1);