From f0257b1b4c76a23392c91db1b81754b85a9202c2 Mon Sep 17 00:00:00 2001 From: pierwill Date: Fri, 4 Mar 2022 13:31:23 -0600 Subject: [PATCH] Edit docs on consistency of `PartialOrd` and `PartialEq` Use ordered list to make the information about implementations more readable. --- library/core/src/cmp.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index a3e77479911..ddaeb9eca97 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -885,19 +885,18 @@ fn partial_cmp(&self, other: &Ordering) -> Option { /// The `lt`, `le`, `gt`, and `ge` methods of this trait can be called using /// the `<`, `<=`, `>`, and `>=` operators, respectively. /// -/// The methods of this trait must be consistent with each other and with those of `PartialEq` in -/// the following sense: +/// The methods of this trait must be consistent with each other and with those of [`PartialEq`]. +/// The following conditions must hold: /// -/// - `a == b` if and only if `partial_cmp(a, b) == Some(Equal)`. -/// - `a < b` if and only if `partial_cmp(a, b) == Some(Less)` -/// (ensured by the default implementation). -/// - `a > b` if and only if `partial_cmp(a, b) == Some(Greater)` -/// (ensured by the default implementation). -/// - `a <= b` if and only if `a < b || a == b` -/// (ensured by the default implementation). -/// - `a >= b` if and only if `a > b || a == b` -/// (ensured by the default implementation). -/// - `a != b` if and only if `!(a == b)` (already part of `PartialEq`). +/// 1. `a == b` if and only if `partial_cmp(a, b) == Some(Equal)`. +/// 2. `a < b` if and only if `partial_cmp(a, b) == Some(Less)` +/// 3. `a > b` if and only if `partial_cmp(a, b) == Some(Greater)` +/// 4. `a <= b` if and only if `a < b || a == b` +/// 5. `a >= b` if and only if `a > b || a == b` +/// 6. `a != b` if and only if `!(a == b)`. +/// +/// Conditions 2–5 above are ensured by the default implementation. +/// Condition 6 is already ensured by [`PartialEq`]. /// /// If [`Ord`] is also implemented for `Self` and `Rhs`, it must also be consistent with /// `partial_cmp` (see the documentation of that trait for the exact requirements). It's