Description
Code
use std::io::{Error, ErrorKind};
struct NoEq;
fn main() {
//let a: Result<u8, _> = "".parse();
//let b: Result<u8, _> = "".parse();
//let _ = (NoEq, 1) == (NoEq, 1);
(Error::new(ErrorKind::Other, "foo"), 1) == (Error::new(ErrorKind::Other, "bar"), 2);
//let _ = (|| 1, 2).eq(|| 3, 4);
//let _ = File::open("foo") == File::open("bar");
}
Current output
⣿
Errors
Exited with status 101
Standard Error
Compiling playground v0.0.1 (/playground)
error[E0369]: binary operation `==` cannot be applied to type `(std::io::Error, {integer})`
--> src/main.rs:9:46
|
9 | (Error::new(ErrorKind::Other, "foo"), 1) == (Error::new(ErrorKind::Other, "bar"), 2);
| ---------------------------------------- ^^ ---------------------------------------- (std::io::Error, {integer})
| |
| (std::io::Error, {integer})
For more information about this error, try `rustc --explain E0369`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Standard Output
Desired output
⣿
Errors
Exited with status 101
Standard Error
Compiling playground v0.0.1 (/playground)
error[E0369]: binary operation `==` cannot be applied to type `(std::io::Error, {integer})`
--> src/main.rs:9:46
|
9 | (Error::new(ErrorKind::Other, "foo"), 1) == (Error::new(ErrorKind::Other, "bar"), 2);
| ---------------------------------------- ^^ ---------------------------------------- (std::io::Error, {integer})
| |
| (std::io::Error, {integer})
note: `std::io::Error` does not implement `PartialEq`
For more information about this error, try `rustc --explain E0369`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Standard Output
Rationale and extra context
usually, when calling a trait method on a complex type that requires its member types to implement a specific trait, a "the following trait bounds were not satisfied" message will be printed, showing which member type does not implement the required trait.
however, since binary operations have their own unique error message, they completely hide this info.
although, if the member type that does not implement the trait is defined in the current crate, rustc will note that type, and say it might be missing a PartialEq impl. it's only with foreign types where no additional output is shown.
this is particularly confusing when trying to compare an io::Result in unit tests.
additionally, the fact that the error message is completely different, and doesn't mention traits at all, is especially confusing.
Other cases
No response
Rust Version
rustc 1.80.0-nightly (9cdfe285c 2024-05-22)
binary: rustc
commit-hash: 9cdfe285ca724c801dc9f78d22b24ea69b787f26
commit-date: 2024-05-22
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6
Anything else?
No response