Skip to content

Commit 2885987

Browse files
committed
Add test assertions that as_weak does not modify reference counts, and points to the right address.
1 parent 668c57a commit 2885987

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

library/alloc/src/rc/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ fn test_weak_count() {
103103
let w = Rc::downgrade(&a);
104104
assert!(Rc::strong_count(&a) == 1);
105105
assert!(Rc::weak_count(&a) == 1);
106+
let r = Rc::as_weak(&a);
107+
assert!(Rc::strong_count(&a) == 1);
108+
assert!(Rc::weak_count(&a) == 1);
109+
assert!(r.as_ptr() == Rc::as_ptr(&a));
106110
drop(w);
107111
assert!(Rc::strong_count(&a) == 1);
108112
assert!(Rc::weak_count(&a) == 0);

library/alloc/src/sync/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ fn test_weak_count() {
314314
let w = Arc::downgrade(&a);
315315
assert!(Arc::strong_count(&a) == 1);
316316
assert!(Arc::weak_count(&a) == 1);
317+
let r = Arc::as_weak(&a);
318+
assert!(Arc::strong_count(&a) == 1);
319+
assert!(Arc::weak_count(&a) == 1);
320+
assert!(r.as_ptr() == Arc::as_ptr(&a));
317321
let x = w.clone();
318322
assert!(Arc::weak_count(&a) == 2);
319323
drop(w);

0 commit comments

Comments
 (0)