32 ms·
Even when destructors are deterministic, they still may run later than you realise or not at all. For example, the Rust docs list some platform specific exampl
by ChrisSD 8y ago
Even when destructors are deterministic, they still may run later than you realise or not at all.
For example, the Rust docs list some platform specific examples of when the 'drop trait' (aka destructor) may not run for thread local values[0]. There are also circular references or simply another object holding a reference (directly or indirectly) that isn't clear from the context.
The `with` statement at least seems to clear up a lot of potential ambiguity if nothing else.
[0] https://doc.rust-lang.org/std/thread/struct.LocalKey.html#platform-specific-behavior https://doc.rust-lang.org/std/thread/struct.LocalKey.html#pl...
- chronial 8y agoThis is stated even more clearly here: https://doc.rust-lang.org/std/mem/fn.forget.html#safety https://doc.rust-lang.org/std/mem/fn.forget.html#safety > forget is not marked as unsafe, because Rust's safety guarantees do not include a guarantee that destructors will always run. For example, a program can create a reference cycle using Rc, or call process::exit to exit without running destructors. Thus, allowing mem::forget from safe code does not fundamentally change Rust's safety guarantees.