As I understand it, the current guarantees for drop glue is something like:
all owned (EDIT: let) bindings are dropped in reverse order of declaration when going out of scope
dropping a value means calling Drop::drop on the value and any members recursively (EDIT: in declaration order), as required
Is there documentation on how this is achieved currently in the compiler? I’d like to somewhat formalize my proposal for Drop reform, but it’d be much better if I can compare the new behavior of drop glue to the current. (It’d also help me check for observable changes in behavior.)
RFC 1857 specifies that fields and such are dropped in declaration order, but I think it is correct that distinct let bindings are dropped in reverse order, no?
struct Bomb(&'static str);
impl Drop for Bomb {
fn drop(&mut self) {
println!("{}", self.0);
}
}
fn main() {
let (a, b) = (Bomb("a"), Bomb("b"));
let (c, d) = (Bomb("c"), Bomb("d"));
}
d
c
b
a
I was indeed talking about let bindings and not members of a type. (My bad for not specifying more clearly.)
Drop order (the observable part of drop glue) is documented in the linked RFC; I’m curious about the mechanism used by the drop glue. (i.e. how much Drop::drop is in charge of and how much is handled inline by the drop glue.) That’s what would have to change by a Drop-changing proposal, and what I’m interested in actually specifying in terms of.