docs

您正在閱讀 v0.1.2 的文件。Nabi 0.1.2 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#E0112: invalid operator declaration

An operator attribute (#[infix(..)], #[prefix(..)], ..) on a trait method breaks a rule: a token that cannot be an operator (an identifier character such as ′ or ℱ, a fixed token at a position it has no form in, binary @ and ~ aside), precedence on a built-in token, aliases at different levels, a method that throws (operators do not throw: return a Result or T | E instead), or a Unicode spelling of a fixed operator (≤ is read as <=; implement ops::PartialOrd instead). A new token gives like = "<existing token>" for its precedence.

nabi
trait Before {
    #[infix(">>>", precedence = 3)]
    fn before(self, o: Self) -> bool;
}
error[E0112]: `#[infix]` takes only an operator token, `like = ".."` and `swap`: precedence and associativity are fixed by the language
  --> main.nabi:2:5
   |
 2 |     #[infix(">>>", precedence = 3)]
   |     ^^

Remove the precedence. A new token borrows the precedence of a built-in one with like: #[infix(">>>", like = ">>")] (6.7).

Related: E0113 invalid #[keyword] declaration, E0123 registered twice

Found a mistake? Edit this page on GitHub. Last updated