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 上编辑此页 最后更新: