Open
Description
This code
struct S;
fn main() {
let _ = S == ();
}
Emits the error message
error[E0369]: binary operation `==` cannot be applied to type `S`
--> src/main.rs:4:15
|
4 | let _ = S == ();
| - ^^ -- ()
| |
| S
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `S`
However, if the type S
has any implementation of PartialEq<T>
for a single type T
that is not ()
, the error message becomes less helpful:
#[derive(PartialEq)]
struct S;
fn main() {
let _ = S == ();
}
error[E0308]: mismatched types
--> src/main.rs:5:18
|
5 | let _ = S == ();
| ^^ expected struct `S`, found `()`
If there are two or more impls of PartialEq
, the error message becomes helpful again:
#[derive(PartialEq)]
struct S;
impl PartialEq<u8> for S {
fn eq(&self, _: &u8) -> bool {
unimplemented!()
}
}
fn main() {
let _ = S == ();
}
error[E0277]: can't compare `S` with `()`
--> src/main.rs:11:15
|
11 | let _ = S == ();
| ^^ no implementation for `S == ()`
|
= help: the trait `std::cmp::PartialEq<()>` is not implemented for `S`
This also applies to other binary operation traits like PartialOrd
and Add
.