Closed
Description
This code:
use std::thread;
struct D(u32);
impl Drop for D {
fn drop(&mut self) {
println!("Dropping {}", self.0);
}
}
fn main() {
fn die() -> D { panic!("Oh no"); }
let g = thread::spawn(|| {
let _a: [D; 3] = [D(101), D(102), D(103)];
let _d: [D; 4] = [D(401), D(402), die(), D(404)];
});
assert!(g.join().is_err());
}
prints
Dropping 402
Dropping 401
Dropping 101
Dropping 102
Dropping 103
i.e. when the panic occurs, we do the dropping in reverse order for the array being built, but then we do the drop in "declaration order" for the array that was fully constructed.
See also rust-lang/rfcs#744 and #16493