E0603: Nested pattern position conflict
| Code | Category | Stability |
|---|---|---|
E0603 | Match | Permanent |
Explanation
A variant pattern's payload position may hold a nested variant pattern, and the arms that share the outer variant then dispatch on that one extracted payload field. Nesting in two positions of the same pattern, or in different positions across arms matching the same variant, asks for a dispatch on several payloads at once.
Likely cause
Two payload positions of one pattern were written as nested variant patterns, or two arms matching the same variant nested in different positions. Nest in a single position and bind the others, matching them in a nested match.
Examples
Nest in two payload positions
enum Inner { A(i32), B }
enum Outer { Pair(Inner, Inner) }
fn main() -> i32 {
match Outer.Pair(Inner.A(1), Inner.B) {
Outer.Pair(Inner.A(v), Inner.B) => v,
Outer.Pair(_, _) => 0,
}
}
Nest in one position and match the other
enum Inner { A(i32), B }
enum Outer { Pair(Inner, Inner) }
fn main() -> i32 {
match Outer.Pair(Inner.A(1), Inner.B) {
Outer.Pair(Inner.A(v), second) => match second {
Inner.A(w) => v + w,
Inner.B => v,
},
Outer.Pair(Inner.B, second) => match second {
Inner.A(w) => w,
Inner.B => 0,
},
}
}