Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binary operators hide "trait bounds not satisfied" errors #125631

Closed
lolbinarycat opened this issue May 27, 2024 · 1 comment · Fixed by #126925
Closed

binary operators hide "trait bounds not satisfied" errors #125631

lolbinarycat opened this issue May 27, 2024 · 1 comment · Fixed by #126925
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link

lolbinarycat commented May 27, 2024

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

@lolbinarycat lolbinarycat added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 27, 2024
@surechen
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 26, 2024
…rors

Change E0369 to give note informations for foreign items.

Change E0369 to give note informations for foreign items.
Make it easy for developers to understand why the binop cannot be applied.

fixes rust-lang#125631
@bors bors closed this as completed in 2a6a423 Jun 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 26, 2024
Rollup merge of rust-lang#126925 - surechen:fix_125631, r=compiler-errors

Change E0369 to give note informations for foreign items.

Change E0369 to give note informations for foreign items.
Make it easy for developers to understand why the binop cannot be applied.

fixes rust-lang#125631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants