-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
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:
- Enums, anonymous struct literals and anonymous list literals would be copyable
- Non-copyable types would be always passed as a reference when the parameter used pass-by-value parameter syntax
- This would probably be too inconvenient without result locations: unwrap optional and error unions so that the payload can be non-copied #2761 and result location: ability to refer to the return result location before the
returnstatement #2765 implemented.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.