Today I ran into a pretty strange error message that I'm having a hard time understanding. Consider this easy map-entry-like struct:
struct Entry<K, V> {
key: K,
value: V
}
Now, I want to implement all the std::cmp traits between Entry<K, V> with itself and with just K. Let's focus on PartialEq for now. These two implementations work just fine:
impl<K: PartialEq, V> PartialEq for Entry<K, V> { /* ... */ }
impl<K: PartialEq, V> PartialEq<K> for Entry<K, V> { /* ... */ }
But the last one gives me a hard time (Playground)
impl<K: PartialEq, V> PartialEq<Entry<K, V>> for K {
fn eq(&self, other: &Entry<K, V>) -> bool {
self.eq(&other.key)
}
}
The error message, as far as I can understand it, claims I'd be using a non-local type as the first parameter of the foreign trait. However, Entry ist defined locally in the same file.
error[E0210]: type parameter
Kmust be covered by another type when it appears before the first local type (Entry<K, V>)--> src/lib.rs:6:6 | 6 | impl<K: PartialEq, V> PartialEq<Entry<K, V>> for K { | ^ type parameter `K` must be covered by another type when it appears before the first local type (`Entry<K, V>`) |note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local, and no uncovered type parameters appear before that first local type
note: in this case, 'before' refers to the following order:impl<..> ForeignTrait<T1, ..., Tn> for T0, whereT0is the first andTnis the last
Can someone explain why I am getting this error message, what the error and especially uncovered means and why this implementation is disallowed?