3 ms·
std::mem::forget() is allowed in Safe Rust specifically because it's always possible to reconstruct it safely using Rc. As for where it comes up, it's usually
by lilyball 8y ago
std::mem::forget() is allowed in Safe Rust specifically because it's always possible to reconstruct it safely using Rc.
As for where it comes up, it's usually because you're handing ownership of the memory to something outside of Rust's normal memory management. In most cases you'll be using a higher-level API like Box::into_raw(), but if you look at the implementation of that you'll see it uses mem::forget() internally.