Skip to content

make aggregate types non-copyable by default; provide copyable attribute #3804

Closed
@andrewrk

Description

@andrewrk

This is a competing proposal with #3803. It solves the same problem in a different way, which is arguably simpler, and safer by default.

It's pretty easy to explain: make all aggregate types non-copyable by default. So this would be an error:

const Point = struct {
    x: i32,
    y: i32,
};

test "copy a point" {
    var pt = Point{.x = 1, .y = 2};
    var pt2 = pt; // error: copy of struct which does not have the `copyok` attribute
}

But this would work:

const Point2 = struct copyok {
    x: i32,
    y: i32,
};

test "copy a point" {
    var pt = Point{.x = 1, .y = 2};
    var pt2 = pt; // OK
}

Some notes:

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions