Closed
Description
Given the following code (EDIT: see the comment below for a more concise snippet):
struct MyType<T: PartialEq>(T);
impl<T> PartialEq for MyType<T>
where
T: PartialEq + Eq,
{
fn eq(&self, other: &Self) -> bool {
true
}
}
struct MyStruct<T: PartialEq> {
a: MyType<T>,
b: MyType<T>,
}
impl<T> MyStruct<T>
where
T: PartialEq,
{
fn cond(&self) -> bool {
self.b != self.a
}
}
fn main() {
let tst = MyStruct {
a: MyType(1),
b: MyType(2),
};
tst.cond();
}
The current output is:
error[[E0369]](https://doc.rust-lang.org/stable/error-index.html#E0369): binary operation `!=` cannot be applied to type `MyType<T>`
[--> src/main.rs:22:16
](https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=1dacb528973e6547b8284f3039fadbb1#) |
22 | self.b != self.a
| ------ ^^ ------ MyType<T>
| |
| MyType<T>
|
help: consider further restricting this bound
|
19 | T: PartialEq + std::cmp::PartialEq,
| +++++++++++++++++++++
For more information about this error, try `rustc --explain E0369`.
Ideally the output should look like:
error[[E0369]](https://doc.rust-lang.org/stable/error-index.html#E0369): binary operation `!=` cannot be applied to type `MyType<T>`
[--> src/main.rs:22:16
](https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=1dacb528973e6547b8284f3039fadbb1#) |
22 | self.b != self.a
| ------ ^^ ------ MyType<T>
| |
| MyType<T>
|
help: consider further restricting this bound
|
19 | T: PartialEq + std::cmp::Eq,
| ++++++++++++++
For more information about this error, try `rustc --explain E0369`.
!=
can't be used here because MyType<T>
only implements PartialEq
where T
implements Eq
, but instead of suggesting we add an Eq
bound, rustc
suggests adding an additional PartialEq
bound, despite T
already being PartialEq
.
This bug is present on both stable and nightly.