error pattern-bindings
Альтернативы образца привязывают разные имена.
What it means#
In an alternative pattern A | B every branch MUST bind the same set of names (§5.5), otherwise the name would be undefined when the other branch matches.
Example#
enum Shape { Circle(r: f64), Rect(w: f64, h: f64) }
fn size(s: Shape) -> f64 {
match s {
Circle(r) | Rect(w, _) => 1.0 // <- pattern-bindings (r vs w)
}
}error
pattern-bindings
How to fix#
enum Shape { Circle(r: f64), Rect(w: f64, h: f64) }
fn size(s: Shape) -> f64 {
match s {
Circle(r) => r
Rect(w, _) => w
}
}Bind the same names in every alternative, or split the alternatives into separate arms.