Skip to content

Commit 3e389ef

Browse files
committed
PartialOrd: transitivity and duality are required only if the corresponding impls exist
1 parent a63880c commit 3e389ef

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
@@ -921,14 +921,18 @@ pub macro Ord($item:item) {
921921
/// easy to accidentally make them disagree by deriving some of the traits and manually
922922
/// implementing others.
923923
///
924-
/// The comparison must satisfy, for all `a`, `b` and `c`:
924+
/// The comparison relations must satisfy the following conditions
925+
/// (for all `a`, `b`, `c` of type `A`, `B`, `C`):
925926
///
926-
/// - transitivity: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
927-
/// - duality: `a < b` if and only if `b > a`.
927+
/// - **Transitivity**: if `A: PartialOrd<B>` and `B: PartialOrd<C>` and `A:
928+
/// PartialOrd<C>`, then `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
929+
/// This must also work for longer chains, such as when `A: PartialOrd<B>`, `B: PartialOrd<C>`,
930+
/// `C: PartialOrd<D>`, and `A: PartialOrd<D>` all exist.
931+
/// - **Duality**: if `A: PartialOrd<B>` and `B: PartialOrd<A>`, then `a < b` if and only if `b > a`.
928932
///
929-
/// Note that these requirements mean that the trait itself must be implemented symmetrically and
930-
/// transitively: if `T: PartialOrd<U>` and `U: PartialOrd<V>` then `U: PartialOrd<T>` and `T:
931-
/// PartialOrd<V>`.
933+
/// Note that the `B: PartialOrd<A>` (dual) and `A: PartialOrd<C>`
934+
/// (transitive) impls are not forced to exist, but these requirements apply
935+
/// whenever they do exist.
932936
///
933937
/// Violating these requirements is a logic error. The behavior resulting from a logic error is not
934938
/// specified, but users of the trait must ensure that such logic errors do *not* result in

0 commit comments

Comments
 (0)