E0407: Linear struct copy
| Code | Category | Stability |
|---|---|---|
E0407 | Struct and enum | Permanent |
Explanation
A struct was declared both linear and @copy. Linear values must have one tracked consumption, while Copy values may be duplicated implicitly.
Likely cause
The @copy directive was applied to a linear struct, combining incompatible ownership promises. Remove @copy and consume each linear value, or remove linear if freely duplicating the value is the intended behavior.
Examples
Linear struct marked @copy
@copy
linear struct Token { value: i32 }
fn main() -> i32 { 0 }
Keep the value linear and consume it
linear struct Token { value: i32 }
fn consume(token: Token) -> i32 { token.value }
fn main() -> i32 {
let token = Token { value: 42 };
consume(token)
}