Skip to content

classes with destructor should error if one tries an explicit copy #2823

Closed
@erickt

Description

@erickt
class C {
    let x: int;
    new(x: int) { self.x = x; }

    drop {
        #error("dropping: %?", self.x);
    }
}

fn main() {
    let c = C(2);
    let d = copy c;
    #error("%?", d.x);
}

Even though the class has a destructor, it is valid rust code because it seems rust is ignoring the explicit copy because let d = copy c is the last use of c. I feel this is confusing, so I think rustc should report an error here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions