rust-lang / rust-lang/rust

update `#[derive(Eq)]` to not need `assert_receiver_is_total_eq`

Open
#152,504 3 comments 0 reactions 1 assignee View on GitHub

@KiChjang is already working on this.

Since Feb 25, 2026.

A-macros C-cleanup E-help-wanted
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

#[derive(Eq)] currently uses the hidden method Eq::assert_receiver_is_total_eq to emit checks that every field of the type being derived on also implements Eq. It would be nice to be able to get rid of it entirely, which requires changing this derive macro to no longer place its checks in this method.

Some implementation notes from https://github.com/rust-lang/rust/pull/149978#issuecomment-3781908738:


For this struct:

struct Point {
    x: u32,
    y: u32,
}

Instead of generating this:

#[automatically_derived]
impl ::core::cmp::Eq for Point {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    #[allow(internal_eq_trait_method_impls)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<u32>;
    }
}

You would generate this:

#[automatically_derived]
impl ::core::cmp::Eq for Point {}
const _: () = {
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq() {
        let _: ::core::cmp::AssertParamIsEq<u32>;
    }
};

One problem is that the const should probably also have #[automatically_derived] put on it, but that's currently not permitted.


https://github.com/rust-lang/rust/pull/149978#discussion_r2795421972 contains some more notes on this.

Tracking issue: https://github.com/rust-lang/rust/issues/152336

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.