docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0054: operator cannot be applied

An operator is used on types that do not support it. For your own types, implement the operator's trait (impl ops::Add for Point); for a type parameter, add that trait as a bound.

nabi
let a: i32 = 1;
let b: i64 = 2;
println(f"{a + b}");
error[E0054]: operator `+` cannot be applied to `i32` and `i64`
  --> main.nabi:3:12
   |
 3 | println(f"{a + b}");
   |            ^^^^^
   |
   = help: Nabi never converts numbers implicitly; convert one side: `(a as i64) + b`

Convert one side; Nabi never converts numbers on its own:

nabi
let a: i32 = 1;
let b: i64 = 2;
println(f"{a as i64 + b}");
3

On a type parameter the message says which bound is missing: operator `+` on `T` needs the bound `T: Add` (chapter 7).

Related: E0040 mismatched types, E0069 trait bound not satisfied

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