Skip to content

PartialEq implementations are missing for symmetric comparisons between certain collections #152830

Description

@is57primenumber

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 19, 2026
  2. eggyal commented on Feb 19, 2026

    @eggyal
    Contributor

    @rustbot label +A-collections -C-bug +C-enhancement +E-easy +T-libs-api -needs-triage

  3. added
    C-enhancementCategory: 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.
    T-libs-api[DEPRECATED; DO NOT USE]
    and removed
    C-bugCategory: This is a bug.
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 19, 2026
  4. Vrajs16 commented on Feb 19, 2026

    @Vrajs16

    @rustbot claim

  5. lms0806 commented on Mar 7, 2026

    @lms0806
    Contributor

    How is this issue progressing?

    If possible, I'd like to resolve it.

  6. eggyal commented on Mar 7, 2026

    @eggyal
    Contributor

    #152972 is awaiting review.

  7. is57primenumber commented on Mar 7, 2026

    @is57primenumber
    ContributorAuthor

    I think the PR doesn't cover Cow type cases.

  8. kx0101 commented on May 4, 2026

    @kx0101
    Contributor

    @rustbot claim

  9. 3 remaining items

  10. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  11. added 4 commits that reference this issue on Aug 22, 2026
  12. added a commit that references this issue on Aug 22, 2026
  13. added a commit that references this issue on Aug 23, 2026
  14. added 2 commits that reference this issue on Sep 27, 2026
  15. added a commit that references this issue on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-collectionsArea: `std::collections`C-enhancementCategory: 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.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions