|
|
|
|
|
by cousin_it
3330 days ago
|
|
What? It's very easy to get use-after-invalidation in Rust. Destructors called during unwinding see stuff in an invalid state. You can probably make a language that prevents use-after-invalidation in safe code (e.g. mark all accessible mutable references as "dirty" during unwinding, and require unsafe code to "clean" them) but Rust isn't trying to do that AFAIK. |
|
A common case where I see people trying to do this is when you have a struct where you are trying to replace a member variable:
This code produces the error `cannot move out of borrowed content`. For those curious, you normally would write this as