E1146: `meta copy` on a type with a field that cannot be copied

View source

A struct or an enum is never duplicated implicitly (ADR-0124).

A struct or an enum is never duplicated implicitly (ADR-0124). It declares that it may be duplicated with meta copy, and every duplication is then written as copy(value: abs x). The declaration is accepted only when every field and every enum payload is itself a copy type: Int, Usize, Bool, a fixed-width integer, a float, another meta copy struct, enum or pack, or an Array of copy types. A Buffer, an Arena, a type with a drop contract, an abs or ins view, a struct, an enum or a pack that is not meta copy, and a generic parameter are not copy types. A struct or an enum that has a drop contract (perform Drop) cannot be meta copy either, because a copy would run the cleanup twice. The message names the declaration and the field that prevents it, and the error points at that field, or at the declaration for a drop contract. For an enum the field is written Variant.name for a named payload and Variant.0 for a positional one.

A struct that holds an arena (an erg field of an arena type, ADR-0130) is an arena holder and cannot be meta copy either: the arena field is the field the message names.

Example

actus
meta copy
struct Frame {
    length: u16,
    payload: Buffer,
}

verb main() {
}
actus
meta copy
struct Scene {
    erg nodes: Arena[64],
}

verb main() {
}
actus
struct Plain {
    value: Int,
}

meta copy
struct Wrapper {
    inner: Plain,
}

verb main() {
}
actus
meta copy
struct Counter {
    value: Int,
}

perform Drop for Counter {
    verb drop(ins self: Counter) {
    }
}

verb main() {
}

Fix

Remove meta copy when the type holds a resource, or declare meta copy on the nested type as well when it holds only plain data.

actus
meta copy
struct Frame {
    length: u16,
    checksum: u32,
}

verb main() {
}
actus
meta copy
struct Plain {
    value: Int,
}

meta copy
struct Wrapper {
    inner: Plain,
}

verb main() {
}

Run actus explain E1146 in your terminal to read this entry offline. Browse Modules & rules or all error codes.