Skip to content

Non copyable values captured by fn~ closures can be copied #2828

Closed
@msullivan

Description

@msullivan

The following program compiles and runs and will run the destructor twice:

class non_copyable {
    let n: int;
    new() { self.n = 0; }
    drop { log(error, "running destructor"); }
}

fn main() {
    let x = non_copyable();

    let f = fn~() { assert x.n == 0; };
    let g = copy f;

    f(); g();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions