3 ms·
> maybe even an RFC I really should try to pull together my proposal for back references. A big problem in Rust is that if A owns B, B can't have a static refe
by Animats 2y ago
> maybe even an RFC
I really should try to pull together my proposal for back references.
A big problem in Rust is that if A owns B, B can't have a static reference to A. If you want to do that, you have to make all links to A be Rc references, and have B contain a Rc::Weak reference to A. Then there's a run-time check if you try to make the weak reference into a strong reference temporarily. Usually, the program is set to panic if that fails.
The question is whether a static analysis can determine that such a weak to strong raise will never fail. If that could be proven at compile time, the reference counting would be unnecessary. And Rust could have sound back-references.
If all the places where a weak link is raised to a strong link are bounded by scopes, this is probably do-able. But hard.