Although dtors should not fail (by convention), it can happen. The Vec dtor doesn't do anything to defend against one of its elements' failing.
Since there's no winning when dtors fail, it's not obvious that Vec should try to do anything, but for comparison, the I/O process and stream types both take defensive measures to try to make the best of similar situations.
This program leaks 4 boxes, the buffer, and fails to run 3 dtors:
struct F(Box<()>);
impl Drop for F {
fn drop(&mut self) {
println!("drop");
fail!()
}
}
fn main() {
let _v = vec!(F(box () ()), F(box () ()), F(box () ()), F(box () ()));
}
Although dtors should not fail (by convention), it can happen. The
Vecdtor doesn't do anything to defend against one of its elements' failing.Since there's no winning when dtors fail, it's not obvious that
Vecshould try to do anything, but for comparison, the I/O process and stream types both take defensive measures to try to make the best of similar situations.This program leaks 4 boxes, the buffer, and fails to run 3 dtors: