Re:My favorite Rust function
by edflsafoiewq on Saturday October 12, 2019 @08:10PM
(#21237277)
NLL didn't affect when objects get dropped. That would be a breaking change. Things still get dropped at end of block (well, approximately... the exact rule is actual quite complex).
This is incorrect. Values still go out of scope and have their destructors run at the same time.
NLL only affects values without destructors.
Re:My favorite Rust function
by oconnor663 on Saturday October 12, 2019 @08:22PM
(#21237327)
I think `#[may_dangle]` is an exception to this, and the standard library puts it on many (most?) container types.
It is not an exception; #[may_dangle] does not change the time drop runs. All it does is promise that drop will not access borrowed data, allowing that data to die before drop: https://doc.rust-lang.org/nightly/nomicon/dropck.html
It's not just a matter of memory use. References and mutable references form a sort of compile-time read-write mutex; you can't take a mutable reference without first dropping all other references. See https://stackoverflow.com/questions/50251487/what-are-non-le... for more.