E0127
Only a name here
ErrorA pattern at a class, array or f64 position takes only a name, which binds the value, or _, which ignores it. Variants are not patterns there.
Why
These types have no variants to tell apart. Bind the value and read its fields or test it inside the arm.
Broken
class Point {
x: i64
}
enum Slot {
Full(Point)
}
fn main() {
let s = Slot.Full(Point(x: 1))
let n = match s {
Full(Point(x)) => x
}
print(n)
}
What sisu says
error[E0127]: a `Point` position takes only a name or `_` --> E0127.sisu:12:14 | 12 | Full(Point(x)) => x | ^^^^^^^^ sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0127
Fixed
class Point {
x: i64
}
enum Slot {
Full(Point)
}
fn main() {
let s = Slot.Full(Point(x: 1))
let n = match s {
Full(p) => p.x
}
print(n)
}
Sisu