Move last remaining Rc test to alloctests

This commit is contained in:
bjorn3 2025-02-06 12:09:45 +00:00
parent be1e0b786d
commit 701bedc323
3 changed files with 18 additions and 18 deletions

View File

@ -276,9 +276,6 @@ use crate::string::String;
#[cfg(not(no_global_oom_handling))]
use crate::vec::Vec;
#[cfg(test)]
mod tests;
// This is repr(C) to future-proof against possible field-reordering, which
// would interfere with otherwise safe [into|from]_raw() of transmutable
// inner types.

View File

@ -1,15 +0,0 @@
use super::*;
#[test]
fn is_unique() {
let x = Rc::new(3);
assert!(Rc::is_unique(&x));
let y = x.clone();
assert!(!Rc::is_unique(&x));
drop(y);
assert!(Rc::is_unique(&x));
let w = Rc::downgrade(&x);
assert!(!Rc::is_unique(&x));
drop(w);
assert!(Rc::is_unique(&x));
}

View File

@ -315,6 +315,24 @@ fn weak_self_cyclic() {
// hopefully we don't double-free (or leak)...
}
#[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);