docs

#E0054: 无法应用运算符

运算符用在了不支持它的类型上。对于自己定义的类型,实现该运算符的 trait(impl ops::Add for Point);对于类型参数,把该 trait 加为约束。

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`

转换其中一边;Nabi 从不自行转换数字:

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

对于类型参数,消息会指出缺少哪个约束:operator `+` on `T` needs the bound `T: Add` (第 7 章)。

相关错误码:E0040 类型不匹配,E0069 不满足 trait 约束

发现错误? 在 GitHub 上编辑此页 最后更新: