Skip to content

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

@cyrgani

Description

@cyrgani

#[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 #149978 (comment):


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.


#149978 (comment) contains some more notes on this.

Tracking issue: #152336

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-help-wantedCall for participation: Help is requested to fix this issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions