E0129
Name bound twice in one pattern
ErrorEach name in a pattern binds one field, so a name appears at most once in a pattern.
Why
In some languages Add(x, x) matches only when both fields are equal; in Sisu a pattern never compares two fields. Bind two names and compare them in a guard: Add(x, y) if x == y.
Broken
enum Expr {
Add(i64, i64)
}
fn same(e: Expr) -> bool {
match e {
Add(x, x) => true
}
}
fn main() {
print(same(Expr.Add(1, 1)))
}
What sisu says
error[E0129]: `x` is bound twice in this pattern --> E0129.sisu:7:16 | 7 | Add(x, x) => true | - ^ | | | first bound here | = help: use a guard: `Add(x, y) if x == y` sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0129
Fixed
enum Expr {
Add(i64, i64)
}
fn same(e: Expr) -> bool {
match e {
Add(x, y) if x == y => true
_ => false
}
}
fn main() {
print(same(Expr.Add(1, 1)))
}
Sisu