docs

#E0078: 不允許的 impl

這個 impl 不被允許:對型別參數的固有 impl、手動實作 Reflect、對既不是自動 trait(Send、Sync)也不是 unsafe trait 的 trait 寫 unsafe impl、對不是自動 trait 的 trait 寫 impl !Trait,或對 unsafe trait 寫一般的 impl。刪除它,或改寫成訊息給出的形式。

nabi
struct X { n: i32; }
impl Send for X {}
error[E0078]: `Send` is an auto trait the compiler derives from the fields; a manual impl for `X` must be `unsafe impl Send for X {}`
  --> main.nabi:2:1
   |
 2 | impl Send for X {}
   | ^^^^

Send 和 Sync 由欄位決定,所以欄位都是 Send 的型別不需要 impl 就是 Send:

nabi
struct X { n: i32; }
fn needs_send<T: Send>(x: T) -> T { x }
println(f"{needs_send(X { n: 1 }).n}");
1

相關錯誤碼:E0076 為外部型別實作外部 trait、E0085 無法跨執行緒的值

發現錯誤? 在 GitHub 上編輯此頁 最後更新: