mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00
Move last remaining Rc test to alloctests
This commit is contained in:
parent
be1e0b786d
commit
701bedc323
@ -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.
|
@ -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));
|
||||
}
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user