docs

你正在阅读 v0.1.0 的文档。Nabi 0.1.0 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#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