Repository navigation
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn main() {
let v = vec![1, 2, 3];
let a = [1, 2, 3];
assert_eq!(a, v);
}Current output
error[E0277]: can't compare `[{integer}; 3]` with `Vec<{integer}>`
--> src/main.rs:4:5
|
4 | assert_eq!(a, v);
| ^^^^^^^^^^^^^^^^ no implementation for `[{integer}; 3] == Vec<{integer}>`
|
= help: the trait `PartialEq<Vec<{integer}>>` is not implemented for `[{integer}; 3]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[T]` implements `PartialEq<Cow<'_, [U]>>`
`&[T]` implements `PartialEq<Vec<U, A>>`
`&[T]` implements `PartialEq<[U; N]>`
`&[u8; N]` implements `PartialEq<ByteStr>`
`&[u8; N]` implements `PartialEq<ByteString>`
`&[u8]` implements `PartialEq<ByteStr>`
`&[u8]` implements `PartialEq<ByteString>`
`&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
and 13 others
For more information about this error, try `rustc --explain E0277`.Rationale and extra context
Right now, PartialEq<[T; N]> for Vec<T> exists, but not the other way around. It would be helpful for this diagnostic to simply recommend swapping operands instead of just showing other implementations.
Note that assert_eq! is a special case where as a macro we can auto-suggest this, but in other cases, showing how to swap operands should be helpful.
Other cases
This applies to pretty much all binary operations in core::ops, although you need to verify that the output is the same for them to be truly reasonable to swap. We could probably still suggest swapping the order if it's still possible.
Rust Version
rustc 1.102.0-nightly (5b7b37aef 2026-11-08)
binary: rustc
commit-hash: 5b7b37aefcb5b2fba3c2392bc9065b9e4602d494
commit-date: 2026-11-08
host: x86_64-unknown-linux-gnu
release: 1.102.0-nightly
LLVM version: 23.1.5Anything else?
No response
Reacted by Robert Shecter
Reacted by Esteban Kuber
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
estebank commentedon Nov 17, 2026
This needs to be adjusted in
compiler/rustc_hir_typeck/src/op.rs:report_binop_fulfillment_errorsin some cases. Do note that both the case in this ticket, and other cases in which an unmet trait bound E0277 error is emitted instead of a binop error would not get the improvement. I had an old PR to unify the errors after encountering E0277 on binops so that a failure on LHS and RHS would have consistent output regardless of position. That divergence should also be addressed, for completeness, and would simplify providing better error context.Yogeshwaran-Projects commentedon Nov 18, 2026
@rustbot claim