Error codes

E0261: operator not defined for a user type (missing add/sub/...)

In a terminal: auk explain E0261 prints this page.

On this page

Operators call functions on user types: + calls add, - sub, * mul, / div, % mod, and < calls cmp. This struct or enum has no such function.

Wrong#

auk
struct V { x: int }
fn main() { print(V { x: 1 } + V { x: 2 }) }

Fixed#

auk
struct V { x: int }
fn add(a: V, b: V): V = V { x: a.x + b.x }
fn main() { print(V { x: 1 } + V { x: 2 }) }

Common causes#

  • Using +, < etc. on your own type without defining add, cmp, ...
  • == is automatic for structs, enums and tuples; ordering is not (define cmp).

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page