Skip to content

Commit 0eecc9e

Browse files
committed
PartialOrd: transitivity and duality are required only if the corresponding impls exist
1 parent 9a66e44 commit 0eecc9e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

library/core/src/cmp.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -916,14 +916,18 @@ pub macro Ord($item:item) {
916916
/// easy to accidentally make them disagree by deriving some of the traits and manually
917917
/// implementing others.
918918
///
919-
/// The comparison must satisfy, for all `a`, `b` and `c`:
919+
/// The comparison relations must satisfy the following conditions
920+
/// (for all `a`, `b`, `c` of type `A`, `B`, `C`):
920921
///
921-
/// - transitivity: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
922-
/// - duality: `a < b` if and only if `b > a`.
922+
/// - **Transitivity**: if `A: PartialOrd<B>` and `B: PartialOrd<C>` and `A:
923+
/// PartialOrd<C>`, then `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
924+
/// This must also work for longer chains, such as when `A: PartialOrd<B>`, `B: PartialOrd<C>`,
925+
/// `C: PartialOrd<D>`, and `A: PartialOrd<D>` all exist.
926+
/// - **Duality**: if `A: PartialOrd<B>` and `B: PartialOrd<A>`, then `a < b` if and only if `b > a`.
923927
///
924-
/// Note that these requirements mean that the trait itself must be implemented symmetrically and
925-
/// transitively: if `T: PartialOrd<U>` and `U: PartialOrd<V>` then `U: PartialOrd<T>` and `T:
926-
/// PartialOrd<V>`.
928+
/// Note that the `B: PartialOrd<A>` (dual) and `A: PartialOrd<C>`
929+
/// (transitive) impls are not forced to exist, but these requirements apply
930+
/// whenever they do exist.
927931
///
928932
/// Violating these requirements is a logic error. The behavior resulting from a logic error is not
929933
/// specified, but users of the trait must ensure that such logic errors do *not* result in

0 commit comments

Comments
 (0)