Binary operators still have worse trait error information than their corrosponding operators.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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 https://github.com/rust-lang/rust/issues/125631
this time it would be nice if the logic could be unified somehow.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue's == and .eq() examples with the stated Rust nightly version and compare their diagnostics. Use the desired trait-bound output and the related issue #125631 as the completion criteria; the payload does not name a compiler file or test entry point.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100