Here is an example. There is a Wrapper struct which is parametrized with a Trait, but has a single element of an associated type (Trait::A).
#[derive(PartialEq)]
pub struct Wrapper<T: Trait>(pub(crate) <T as Trait>::A);
pub trait Trait {
type A: Eq + PartialEq;
fn a() -> Self::A;
}
pub fn test<T: Trait>() {
let wrapper = Wrapper::<T>(T::a());
let _r = wrapper == wrapper;
}
which gives this compiling error:
error[E0369]: binary operation `==` cannot be applied to type `Wrapper<T>`
--> src/main.rs:12:22
|
12 | let _r = wrapper == wrapper;
| ------- ^^ ------- Wrapper<T>
| |
| Wrapper<T>
|
help: consider further restricting this bound
|
10 | pub fn test<T: Trait + std::cmp::PartialEq>() {
| +++++++++++++++++++++
For more information about this error, try `rustc --explain E0369`.
Why is the PartialEq bound required, if no Traits are compared, just Trait::As?