-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Open
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
While a == b works, b == a often fails to compile for many standard collection combinations (e.g., VecDeque vs Vec, Vec vs Array). This violates the intuitive expectation of symmetry in equality comparisons.
Related issue is #149017
I tried this code:
#![crate_type = "lib"]
use std::{borrow::Cow, collections::VecDeque};
fn test_deq_vec() {
let mut a = VecDeque::new();
a.push_back(1);
let b = vec![1];
let _ = a == b;
// compile error
let _ = b == a;
}
fn test_cowvec_vec() {
let a = Cow::Owned(vec![1]);
let b = vec![1];
let _ = a == b;
// compile error
let _ = b == a;
}
fn test_deq_slice() {
let mut a = VecDeque::new();
a.push_back(1);
let b = &[1][..];
let _ = a == b;
// compile error
let _ = b == a;
}
fn test_deq_array() {
let mut a = VecDeque::new();
a.push_back(1);
let b = [1];
let _ = a == b;
// compile error
let _ = b == a;
}
fn test_deq_mutslice() {
let mut a = VecDeque::new();
a.push_back(1);
let b = &mut [1][..];
let _ = a == b;
// compile error
let _ = b == a;
}
fn test_deq_array_ref() {
let mut a = VecDeque::new();
a.push_back(1);
let b = &[1];
let _ = a == b;
// compile error
let _ = b == a;
}
fn test_deq_array_mut_ref() {
let mut a = VecDeque::new();
a.push_back(1);
let b = &mut [1];
let _ = a == b;
// compile error
let _ = b == a;
}
fn test_cow_mutslice() {
let a = Cow::Owned(vec![1]);
let b = &mut [1][..];
let _ = a == b;
// compile error
let _ = b == a;
}I expected that this code successfully compiled
Instead, compile error happened.
Meta
rustc --version --verbose:
rustc 1.95.0-nightly (838709580 2026-02-17)
binary: rustc
commit-hash: 8387095803f21a256a9a772ac1f9b41ed4d5aa0a
commit-date: 2026-02-17
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0
Backtrace
error[E0277]: can't compare `Vec<{integer}>` with `VecDeque<{integer}>`
--> src/main.rs:14:15
|
14 | let _ = b == a;
| ^^ no implementation for `Vec<{integer}> == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `Vec<{integer}>`
= help: the following other types implement trait `PartialEq<Rhs>`:
`Vec<T, A1>` implements `PartialEq<Vec<U, A2>>`
`Vec<T, A>` implements `PartialEq<&[U; N]>`
`Vec<T, A>` implements `PartialEq<&[U]>`
`Vec<T, A>` implements `PartialEq<&mut [U]>`
`Vec<T, A>` implements `PartialEq<[U; N]>`
`Vec<T, A>` implements `PartialEq<[U]>`
`Vec<u8>` implements `PartialEq<ByteStr>`
`Vec<u8>` implements `PartialEq<ByteString>`
error[E0277]: can't compare `Vec<{integer}>` with `Cow<'_, [{integer}]>`
--> src/main.rs:23:15
|
23 | let _ = b == a;
| ^^ no implementation for `Vec<{integer}> == Cow<'_, [{integer}]>`
|
= help: the trait `PartialEq<Cow<'_, [{integer}]>>` is not implemented for `Vec<{integer}>`
help: consider dereferencing both sides of the expression
|
23 | let _ = *b == *a;
| + +
error[E0277]: can't compare `&[{integer}]` with `VecDeque<{integer}>`
--> src/main.rs:33:15
|
33 | let _ = b == a;
| ^^ no implementation for `&[{integer}] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `&[{integer}]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `[{integer}; 1]` with `VecDeque<{integer}>`
--> src/main.rs:43:15
|
43 | let _ = b == a;
| ^^ no implementation for `[{integer}; 1] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `[{integer}; 1]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `&mut [{integer}]` with `VecDeque<{integer}>`
--> src/main.rs:53:15
|
53 | let _ = b == a;
| ^^ no implementation for `&mut [{integer}] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `&mut [{integer}]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `&[{integer}; 1]` with `VecDeque<{integer}>`
--> src/main.rs:64:15
|
64 | let _ = b == a;
| ^^ no implementation for `&[{integer}; 1] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `&[{integer}; 1]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `&mut [{integer}; 1]` with `VecDeque<{integer}>`
--> src/main.rs:75:15
|
75 | let _ = b == a;
| ^^ no implementation for `&mut [{integer}; 1] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `&mut [{integer}; 1]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `&mut [{integer}]` with `Cow<'_, [{integer}]>`
--> src/main.rs:85:15
|
85 | let _ = b == a;
| ^^ no implementation for `&mut [{integer}] == Cow<'_, [{integer}]>`
|
= help: the trait `PartialEq<Cow<'_, [{integer}]>>` is not implemented for `&mut [{integer}]`
help: consider dereferencing both sides of the expression
|
85 | let _ = *b == *a;
| + +
For more information about this error, try `rustc --explain E0277`.
error: could not compile `rustdoc_parse` (lib) due to 8 previous errors
dai@desktopwin11:~/vscode/rustdoc_parse$ RUST_BACKTRACE=1 cargo build
Compiling rustdoc_parse v0.1.0 (/home/dai/vscode/rustdoc_parse)
error[E0277]: can't compare `Vec<{integer}>` with `VecDeque<{integer}>`
--> src/lib.rs:13:15
|
13 | let _ = b == a;
| ^^ no implementation for `Vec<{integer}> == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `Vec<{integer}>`
= help: the following other types implement trait `PartialEq<Rhs>`:
`Vec<T, A1>` implements `PartialEq<Vec<U, A2>>`
`Vec<T, A>` implements `PartialEq<&[U; N]>`
`Vec<T, A>` implements `PartialEq<&[U]>`
`Vec<T, A>` implements `PartialEq<&mut [U]>`
`Vec<T, A>` implements `PartialEq<[U; N]>`
`Vec<T, A>` implements `PartialEq<[U]>`
`Vec<u8>` implements `PartialEq<ByteStr>`
`Vec<u8>` implements `PartialEq<ByteString>`
error[E0277]: can't compare `Vec<{integer}>` with `Cow<'_, [{integer}]>`
--> src/lib.rs:22:15
|
22 | let _ = b == a;
| ^^ no implementation for `Vec<{integer}> == Cow<'_, [{integer}]>`
|
= help: the trait `PartialEq<Cow<'_, [{integer}]>>` is not implemented for `Vec<{integer}>`
help: consider dereferencing both sides of the expression
|
22 | let _ = *b == *a;
| + +
error[E0277]: can't compare `&[{integer}]` with `VecDeque<{integer}>`
--> src/lib.rs:32:15
|
32 | let _ = b == a;
| ^^ no implementation for `&[{integer}] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `&[{integer}]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `[{integer}; 1]` with `VecDeque<{integer}>`
--> src/lib.rs:42:15
|
42 | let _ = b == a;
| ^^ no implementation for `[{integer}; 1] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `[{integer}; 1]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `&mut [{integer}]` with `VecDeque<{integer}>`
--> src/lib.rs:52:15
|
52 | let _ = b == a;
| ^^ no implementation for `&mut [{integer}] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `&mut [{integer}]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `&[{integer}; 1]` with `VecDeque<{integer}>`
--> src/lib.rs:63:15
|
63 | let _ = b == a;
| ^^ no implementation for `&[{integer}; 1] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `&[{integer}; 1]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `&mut [{integer}; 1]` with `VecDeque<{integer}>`
--> src/lib.rs:74:15
|
74 | let _ = b == a;
| ^^ no implementation for `&mut [{integer}; 1] == VecDeque<{integer}>`
|
= help: the trait `PartialEq<VecDeque<{integer}>>` is not implemented for `&mut [{integer}; 1]`
= help: the following other types implement trait `PartialEq<Rhs>`:
`&[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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
error[E0277]: can't compare `&mut [{integer}]` with `Cow<'_, [{integer}]>`
--> src/lib.rs:84:15
|
84 | let _ = b == a;
| ^^ no implementation for `&mut [{integer}] == Cow<'_, [{integer}]>`
|
= help: the trait `PartialEq<Cow<'_, [{integer}]>>` is not implemented for `&mut [{integer}]`
help: consider dereferencing both sides of the expression
|
84 | let _ = *b == *a;
| + +
For more information about this error, try `rustc --explain E0277`.
error: could not compile `rustdoc_parse` (lib) due to 8 previous errors
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.