Skip to content

Box-enclosed destructors can't safely access other boxes. #3039

Closed
@bblum

Description

@bblum

Ran into this issue when trying to write a destructor for the doubly-linked-list. The following code segfaults after (i believe) one of the boxes has been annihilated and the other's destructor attempts to run.

The solution, I think, is for the box annihilator to run in two phases - one phase to run destructors, and then another to actually annihilate the boxes after that. (EDIT: this is a point of contention.)

class ticky_tacky {
    let data: uint;
    let mut neighbour: @little_box;
    new(data: uint) { self.data = data; self.neighbour = @none; }
    drop {
        alt *self.neighbour {
            some(other_box) {
                #error["Neighbour's value is %u", other_box.data];
            }
            none { }
        }
    }
}

enum little_box { none, some(ticky_tacky) }

fn main() {
    let box1: @little_box = @some(ticky_tacky(42));
    let box2: @little_box = @some(ticky_tacky(31337));

    alt check *box1 {
        some(x) { x.neighbour = box2; }
    }
    alt check *box2 {
        some(x) { x.neighbour = box1; }
    }
    fail;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions