E0486: Linear payload discarded
| Code | Category | Stability |
|---|---|---|
E0486 | Struct and enum | Permanent |
Explanation
A wildcard payload position still receives the matched value, but gives the program no name with which to consume it. When that payload carries a linear obligation, either an explicit _ or the equivalent bare variant pattern would silently discard the value, so Rue rejects the pattern.
Likely cause
A match arm uses _ for a linear payload, or uses a bare variant name whose payload includes a linear value. Bind each linear payload by name and consume it in the arm; _ remains valid for payloads that do not carry linear values.
Examples
Discard a linear match payload
linear struct Token { value: i32 }
enum Event { Token(Token), Empty }
fn main() -> i32 {
match Event.Token(Token { value: 42 }) {
Event.Token(_) => 1,
Event.Empty => 0,
}
}
Bind and consume the linear payload
linear struct Token { value: i32 }
enum Event { Token(Token), Empty }
fn main() -> i32 {
match Event.Token(Token { value: 42 }) {
Event.Token(token) => { @drop(token); 1 },
Event.Empty => 0,
}
}