Hi!
I've recently published my first crate GitHub - frengor/rust-cc: Rust cycle collector., which implements a cycle collector in Rust.
This is also my first Rust program using unsafe, so any type of advice is welcome!
All tests pass successfully under Miri. However, my greatest worry is about the usage of UnsafeCell
s and the new_cyclic
function. For example:
let returned: Cc<MyData> = Cc::new_cyclic(|not_yet_init_cc: &Cc<MyData>| { // types left for clearness
// Trying to dereference not_yet_init_cc here will panic, since the data inside is uninit
not_yet_init_cc.deref(); // Panics!
// Cloning doesn't panic however
let cloned = not_yet_init_cc.clone();
MyData { ... } // Data with which not_yet_init_cc will be initialized
}); // new_cyclic then returns the initialized not_yet_init_cc
My fear is that it may be possible to trigger UB calling other methods like clone
inside the closure.
Also, is there any unsoundness?
Thank you in advance!