本页尚未翻译,以下为英文原文。
#E0078: impl not allowed
This impl is not allowed: an inherent impl on a type parameter, a manual impl of Reflect, an unsafe impl of a trait that is neither an auto trait (Send, Sync) nor an unsafe trait, an impl !Trait of a trait that is not an auto trait, or a plain impl of an unsafe trait. Remove it, or write the form the message gives.
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 and Sync come from the fields, so a type of Send fields is Send without an impl:
nabi
struct X { n: i32; }
fn needs_send<T: Send>(x: T) -> T { x }
println(f"{needs_send(X { n: 1 }).n}");
1
Related: E0076 impl of a foreign trait for a foreign type, E0085 value cannot cross threads
Found a mistake? Edit this page on GitHub. Last updated