Closed
Description
The Documentation of PartialEq
states that implementations must be transitive: for all for all a
, b
and c
, a == b
and b == c
implies a == c
. This is followed by a note indicating that the transitivity must also hold if a
, b
, and c
are of different types.
However, the last example implementation in the documentation is not transitive:
let b1 = Book { isbn: 1, format: BookFormat::Paperback };
let b2 = Book { isbn: 2, format: BookFormat::Paperback };
assert!(b1 == BookFormat::Paperback);
assert!(BookFormat::Paperback == b2);
// The following should hold by transitivity but doesn't.
assert!(b1 == b2); // <-- PANICS
I can think of three possible ways to fix this:
- Remove the last example.
- Keep the last example as an explicit counterexample to warn how easy it is to accidentally write implementations that violate the contract.
- Modify the last example in a way that fixes the issue (I'm not sure what that would look like).
I can submit a pull request if I get some guidance which of the above solutions to choose (I personally have a weak preference for the second one).