【发布时间】:2020-05-05 17:35:39
【问题描述】:
我正在尝试编译以下 rust 代码:
#[derive(Clone)]
struct Foo<Data> {
f: fn(&Data),
}
trait Trait : Clone {
type DataType;
}
// throws:
// error[E0277]: the trait bound `Data: std::clone::Clone` is not satisfied
impl<Data> Trait for Foo<Data> {
type DataType = Data;
}
它抱怨 Data 通用参数不满足 Clone 约束,即使它不应该满足。
据我了解Foo<Data> 应该支持Clone 而无需Data 支持。
我做错了什么?
【问题讨论】: