Skip to content

Vec dtor might want to try harder on failure #16135

Closed
@brson

Description

@brson

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 () ()));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-destructorsArea: Destructors (`Drop`, …)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions