Skip to content

Commit f721090

Browse files
committed
Move last remaining Rc test to alloctests
1 parent 96e100e commit f721090

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

library/alloc/src/rc/mod.rs library/alloc/src/rc.rs

-3
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,6 @@ use crate::string::String;
276276
#[cfg(not(no_global_oom_handling))]
277277
use crate::vec::Vec;
278278

279-
#[cfg(test)]
280-
mod tests;
281-
282279
// This is repr(C) to future-proof against possible field-reordering, which
283280
// would interfere with otherwise safe [into|from]_raw() of transmutable
284281
// inner types.

library/alloc/src/rc/tests.rs

-15
This file was deleted.

library/alloctests/tests/rc.rs

+18
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,24 @@ fn weak_self_cyclic() {
315315
// hopefully we don't double-free (or leak)...
316316
}
317317

318+
#[test]
319+
fn is_unique() {
320+
fn is_unique<T>(this: &Rc<T>) -> bool {
321+
Rc::weak_count(this) == 0 && Rc::strong_count(this) == 1
322+
}
323+
324+
let x = Rc::new(3);
325+
assert!(is_unique(&x));
326+
let y = x.clone();
327+
assert!(!is_unique(&x));
328+
drop(y);
329+
assert!(is_unique(&x));
330+
let w = Rc::downgrade(&x);
331+
assert!(!is_unique(&x));
332+
drop(w);
333+
assert!(is_unique(&x));
334+
}
335+
318336
#[test]
319337
fn test_strong_count() {
320338
let a = Rc::new(0);

0 commit comments

Comments
 (0)