Skip to content

Commit efa6f1e

Browse files
committed
PartialEq: handle longer transitive chains
1 parent 26089ba commit efa6f1e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/core/src/cmp.rs

+8
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ use self::Ordering::*;
5858
///
5959
/// - **Transitive**: if `A: PartialEq<B>` and `B: PartialEq<C>` and `A:
6060
/// PartialEq<C>`, then **`a == b` and `b == c` implies `a == c`**.
61+
/// This must also work for longer chains, such as when `A: PartialEq<B>`, `B: PartialEq<C>`,
62+
/// `C: PartialEq<D>`, and `A: PartialEq<D>` all exist.
6163
///
6264
/// Note that the `B: PartialEq<A>` (symmetric) and `A: PartialEq<C>`
6365
/// (transitive) impls are not forced to exist, but these requirements apply
6466
/// whenever they do exist.
67+
/// The requirement for transitive chains has a subtle consequence: if a crate `a` with type `A`
68+
/// importing types `B1`, `B2` from another crate `b` defines instances of both `A: PartialEq<B1>`
69+
/// and `B2: PartialEq<A>`, then if `b` adds a `B1: PartialEq<B2>` implementation in the future that
70+
/// could create new violations of transitivity. Effectively, crate `a` is making `B1` and `B2`
71+
/// comparable even though `b` does not permit comparing them. Crate `a` should generally refrain
72+
/// from doing that to avoid the potential for such conflicts.
6573
///
6674
/// ## Derivable
6775
///

0 commit comments

Comments
 (0)