derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

Generate `PartialEq::ne()` (#163)

Open tyranron opened this issue 5 months ago • 4 comments
trafficstars

Part of #163
Follows #473

Synopsis

derive(PartialEq) in std generates only PartialEq::eq() method implementation in its expansion. This silently kills any potential performance benefits if the underlying types implement PartialEq::ne() more efficiently than the default implementation (!PartialEq::eq()).

Solution

Generate PartialEq::ne() implementation always as well, by structurally calling != operator instead of ==.

Additionally

Unfortunately, the assert_ne!() macro also doesn't call PartialEq::ne() or != operator inside its expansion, and only negates the equality check. Found this when running tests against a purposely incorrect PartialEq::ne() implementation. That's why the assert_ne!() macro is redefined in partial_eq tests as asset!(left != right).

Checklist

  • [x] Documentation is updated
  • [x] Tests are added/updated
  • [x] CHANGELOG entry is added (if required)

tyranron avatar May 28 '25 11:05 tyranron