|
1 | 1 | use std::any::Any;
|
2 | 2 | use std::cell::{Cell, RefCell};
|
3 | 3 | use std::iter::TrustedLen;
|
4 |
| -use std::sync::{Arc, Weak}; |
| 4 | +use std::sync::{Arc, UniqueArc, Weak}; |
5 | 5 |
|
6 | 6 | #[test]
|
7 | 7 | fn uninhabited() {
|
@@ -263,6 +263,27 @@ fn make_mut_unsized() {
|
263 | 263 | assert_eq!(*other_data, [110, 20, 30]);
|
264 | 264 | }
|
265 | 265 |
|
| 266 | +#[test] |
| 267 | +fn test_unique_arc_weak() { |
| 268 | + let data = UniqueArc::new(32); |
| 269 | + |
| 270 | + // Test that `Weak` downgraded from `UniqueArc` cannot be upgraded. |
| 271 | + let weak = UniqueArc::downgrade(&data); |
| 272 | + assert_eq!(weak.strong_count(), 0); |
| 273 | + assert_eq!(weak.weak_count(), 0); |
| 274 | + assert!(weak.upgrade().is_none()); |
| 275 | + |
| 276 | + // Test that `Weak` can now be upgraded after the `UniqueArc` being converted to `Arc`. |
| 277 | + let strong = UniqueArc::into_arc(data); |
| 278 | + assert_eq!(*strong, 32); |
| 279 | + assert_eq!(weak.strong_count(), 1); |
| 280 | + assert_eq!(weak.weak_count(), 1); |
| 281 | + let upgraded = weak.upgrade().unwrap(); |
| 282 | + assert_eq!(*upgraded, 32); |
| 283 | + assert_eq!(weak.strong_count(), 2); |
| 284 | + assert_eq!(weak.weak_count(), 1); |
| 285 | +} |
| 286 | + |
266 | 287 | #[allow(unused)]
|
267 | 288 | mod pin_coerce_unsized {
|
268 | 289 | use alloc::sync::{Arc, UniqueArc};
|
|
0 commit comments