#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 上編輯此頁 最後更新: