Skip to content

Commit a3fe63e

Browse files
authored
Rollup merge of #94620 - pierwill:partialord-constistency, r=yaahc
Edit docs on consistency of `PartialOrd` and `PartialEq` Use ordered list to make the information about implementations more readable.
2 parents c7d2004 + f0257b1 commit a3fe63e

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

library/core/src/cmp.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -885,19 +885,18 @@ impl PartialOrd for Ordering {
885885
/// The `lt`, `le`, `gt`, and `ge` methods of this trait can be called using
886886
/// the `<`, `<=`, `>`, and `>=` operators, respectively.
887887
///
888-
/// The methods of this trait must be consistent with each other and with those of `PartialEq` in
889-
/// the following sense:
890-
///
891-
/// - `a == b` if and only if `partial_cmp(a, b) == Some(Equal)`.
892-
/// - `a < b` if and only if `partial_cmp(a, b) == Some(Less)`
893-
/// (ensured by the default implementation).
894-
/// - `a > b` if and only if `partial_cmp(a, b) == Some(Greater)`
895-
/// (ensured by the default implementation).
896-
/// - `a <= b` if and only if `a < b || a == b`
897-
/// (ensured by the default implementation).
898-
/// - `a >= b` if and only if `a > b || a == b`
899-
/// (ensured by the default implementation).
900-
/// - `a != b` if and only if `!(a == b)` (already part of `PartialEq`).
888+
/// The methods of this trait must be consistent with each other and with those of [`PartialEq`].
889+
/// The following conditions must hold:
890+
///
891+
/// 1. `a == b` if and only if `partial_cmp(a, b) == Some(Equal)`.
892+
/// 2. `a < b` if and only if `partial_cmp(a, b) == Some(Less)`
893+
/// 3. `a > b` if and only if `partial_cmp(a, b) == Some(Greater)`
894+
/// 4. `a <= b` if and only if `a < b || a == b`
895+
/// 5. `a >= b` if and only if `a > b || a == b`
896+
/// 6. `a != b` if and only if `!(a == b)`.
897+
///
898+
/// Conditions 2–5 above are ensured by the default implementation.
899+
/// Condition 6 is already ensured by [`PartialEq`].
901900
///
902901
/// If [`Ord`] is also implemented for `Self` and `Rhs`, it must also be consistent with
903902
/// `partial_cmp` (see the documentation of that trait for the exact requirements). It's

0 commit comments

Comments
 (0)