E0403: Copy struct non copy field
| Code | Category | Stability |
|---|---|---|
E0403 | Struct and enum | Permanent |
Explanation
A struct marked @copy contains a field whose type has move semantics. Implicitly duplicating the outer value would also have to duplicate that non-Copy field.
Likely cause
A field is a struct without @copy, a move-typed aggregate, or another type that cannot be implicitly duplicated. Remove @copy from the outer struct or make every field type Copy when that is semantically valid.
Examples
Non-Copy field in a @copy struct
struct Inner { value: i32 }
@copy
struct Outer { inner: Inner }
fn main() -> i32 { 0 }
Use only Copy field types
@copy
struct Inner { value: i32 }
@copy
struct Outer { inner: Inner }
fn main() -> i32 {
let outer = Outer { inner: Inner { value: 42 } };
let duplicate = outer;
outer.inner.value + duplicate.inner.value
}