Skip to content

Pattern-destructing a struct inside a ~-pointer violates linearity #3224

Closed
@bblum

Description

@bblum

EDIT(bblum): modernized the example

extern mod extra;
use extra::arc;

struct Bar { x: arc::ARC<()> }

impl Drop for Bar {
    fn finalize(&self) {
        error!("%?", self.x.get());
    }   
}

struct Foo { x: Bar }

fn main() {
    let x = ~Foo { x: Bar { x: arc::ARC(()) } };
    let ~Foo { x: _y } = x;
}

This runs the destructor twice and crashes. It does not run the destructor twice if the ~ are removed.

Unlike #3218, this code should compile, because A is the one with the destructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-destructorsArea: Destructors (`Drop`, …)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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions