Skip to content

Binary operators still have worse trait error information than their corrosponding operators. #135781

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

Open
lolbinarycat opened this issue Jan 20, 2025 · 0 comments
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
Contributor

Code

struct Whatever;

fn main() {
    let _ = Some([1, 2].into_iter()) == &Some([1, 2].into_iter());
}

Current output

error[E0369]: binary operation `==` cannot be applied to type `Option<std::array::IntoIter<{integer}, 2>>`
   --> src/main.rs:4:38
    |
4   |     let _ = Some([1, 2].into_iter()) == &Some([1, 2].into_iter());
    |             ------------------------ ^^ ------------------------- &Option<std::array::IntoIter<{integer}, 2>>
    |             |
    |             Option<std::array::IntoIter<{integer}, 2>>
    |
note: the foreign item type `Option<std::array::IntoIter<{integer}, 2>>` doesn't implement `PartialEq<&Option<std::array::IntoIter<{integer}, 2>>>`
   --> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:572:1
    |
572 | pub enum Option<T> {
    | ^^^^^^^^^^^^^^^^^^ not implement `PartialEq<&Option<std::array::IntoIter<{integer}, 2>>>`

For more information about this error, try `rustc --explain E0369`.

Desired output

error[E0369]: binary operation `==` cannot be applied to type `Option<std::array::IntoIter<{integer}, 2>>`
   --> src/main.rs:4:38
    |
4   |     let _ = Some([1, 2].into_iter()) == &Some([1, 2].into_iter());
    |             ------------------------ ^^ ------------------------- &Option<std::array::IntoIter<{integer}, 2>>
    |             |
    |             Option<std::array::IntoIter<{integer}, 2>>
    |
    |
    = note: the following trait bounds were not satisfied:
             `std::array::IntoIter<{integer}, 2>: PartialEq`
             which is required by `Option<std::array::IntoIter<{integer}, 2>>: PartialEq`
             `Option<std::array::IntoIter<{integer}, 2>>: Iterator`
             which is required by `&mut Option<std::array::IntoIter<{integer}, 2>>: Iterator`

For more information about this error, try `rustc --explain E0369`.

Rationale and extra context

compare to this code:

struct Whatever;

fn main() {
    let _ = Some([1, 2].into_iter()).eq(&Some([1, 2].into_iter()));
}

that gives the exact trait bounds that were not satisfied (in particular, iterators over arrays do not implement PartialEq).

this isn't the most realistic case, but i wanted to repro it without external dependencies, and there's a different diagnostic that triggers if the type is defined in the same crate as the error.

Other cases

this diagnostic should fire whenever there is a type whose ability to implement a trait is dependent on one of its type variables implementing a trait.

Rust Version

rustc 1.85.0-nightly (7442931d4 2024-11-30)

Anything else?

related to #125631

this time it would be nice if the logic could be unified somehow.

@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 Jan 20, 2025
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

No branches or pull requests

1 participant