本頁尚未翻譯,以下為英文原文。
#E0108: cannot derive
A #[derive(..)] cannot implement the trait for this type: a field does not implement it, it needs another derived trait too, or the type is of a kind the derive does not support. Implement the trait by hand, or fix the field the message names.
nabi
struct NoClone { n: i32; }
#[derive(Clone)]
struct Holder { n: NoClone; }
error[E0108]: cannot derive `Clone` for `Holder`: `n` has type `NoClone`, which does not implement `Clone` --> main.nabi:2:1 | 2 | #[derive(Clone)] | ^^
Derive the trait for the field's type too, or implement it by hand:
nabi
#[derive(Clone)]
struct NoClone { n: i32; }
#[derive(Clone)]
struct Holder { n: NoClone; }
let h = Holder { n: NoClone { n: 1 } };
println(f"{h.clone().n.n}");
1
A trait that cannot be derived at all, such as Display, is also E0108; the message says why.
Related: E0109 malformed attribute
Found a mistake? Edit this page on GitHub. Last updated