Why this fires¶
A named struct pattern in parameter position (fn f(StructName { ... }: T)) names a different struct than the parameter's own type annotation.
struct Point { x: int }
struct Circle { r: int }
fn f(Point { x }: Circle) { print(x) }
// ^^^^^^^^^^^^^^^^^^^ error[TE127]: parameter pattern names struct 'Point'
// but the annotation says 'Circle'The same check applies to effect handler-arm patterns, where the operation's declared parameter type plays the role of the annotation:
struct Point { x: int, y: int }
struct Circle { r: int }
effect Gfx { fn draw(p: Point) }
fn f() {
handle work() with {
Gfx::draw(Circle { r }) => r,
// ^^^^^^^^^^^^ error[TE127]: ... names struct 'Circle' but 'Gfx::draw'
// declares parameter type 'Point'
}
}Fix it¶
Make the pattern name the same struct as the annotation (or the operation's declared parameter type):
fn f(Point { x }: Point) { print(x) } // okIf the annotation itself is wrong, fix the annotation instead.
See also¶
TE126— anonymous pattern parameter needs a type.- /docs/pattern-matching — struct patterns in parameter position.