【发布时间】:2017-05-03 14:50:42
【问题描述】:
我有以下代码:
pub trait GetIdentifier {
//...
}
impl<T: GetIdentifier> Hash for T {
fn hash(&self) -> //....
}
我收到以下错误:
error[E0119]: conflicting implementations of trait `std::hash::Hash` for type `&_`:
--> <anon>:18:1
|
18 | / impl<T: GetIdentifier> Hash for T {
19 | | }
| |_^
|
= note: conflicting implementation in crate `core`
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`); only traits defined in the current crate can be implemented for a type parameter
--> <anon>:18:1
|
18 | / impl<T: GetIdentifier> Hash for T {
19 | | }
| |_^
为什么?我还没有为&_ 实现GetIdentifier,所以毯子impl 不应该适用于&_。我的箱子的消费者也不能为核心类型实现GetIdentifier,所以没有问题。我在这里想念什么?为什么&_ 甚至涉及到这里——我没有在我的 trait 上设置 ?Sized 绑定,所以甚至不应该考虑引用......对吗?
【问题讨论】: