Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't derive PartialEq::ne. #98655

Merged
merged 1 commit into from
Aug 18, 2022

Commits on Jul 31, 2022

  1. Don't derive PartialEq::ne.

    Currently we skip deriving `PartialEq::ne` for C-like (fieldless) enums
    and empty structs, thus reyling on the default `ne`. This behaviour is
    unnecessarily conservative, because the `PartialEq` docs say this:
    
    > Implementations must ensure that eq and ne are consistent with each other:
    >
    > `a != b` if and only if `!(a == b)` (ensured by the default
    > implementation).
    
    This means that the default implementation (`!(a == b)`) is always good
    enough. So this commit changes things such that `ne` is never derived.
    
    The motivation for this change is that not deriving `ne` reduces compile
    times and binary sizes.
    
    Observable behaviour may change if a user has defined a type `A` with an
    inconsistent `PartialEq` and then defines a type `B` that contains an
    `A` and also derives `PartialEq`. Such code is already buggy and
    preserving bug-for-bug compatibility isn't necessary.
    
    Two side-effects of the change:
    - There is only one error message produced for types where `PartialEq`
      cannot be derived, instead of two.
    - For coverage reports, some warnings about generated `ne` methods not
      being executed have disappeared.
    
    Both side-effects seem fine, and possibly preferable.
    nnethercote committed Jul 31, 2022
    Configuration menu
    Copy the full SHA
    d4a5b03 View commit details
    Browse the repository at this point in the history