From cf3959c5b07a03da5e3682743c7596fc05ef68a2 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Sat, 29 Dec 2018 17:48:43 -0500 Subject: [PATCH 1/2] Make std::cmp::Ord documentation specify what it means to agree with PartialEq --- src/libcore/cmp.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 9336b130d1b..8eff9a8c8a2 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -472,9 +472,10 @@ impl Ord for Reverse { /// Then you must define an implementation for `cmp()`. You may find it useful to use /// `cmp()` on your type's fields. /// -/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with each other. It's -/// easy to accidentally make them disagree by deriving some of the traits and manually -/// implementing others. +/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* +/// agree with each other. That is, `a.cmp(b) == Ordering::Equal` if +/// and only if `a == b`. It's easy to accidentally make them disagree +/// by deriving some of the traits and manually implementing others. /// /// Here's an example where you want to sort people by height only, disregarding `id` /// and `name`: From 445dadca33f5109398d819dd4dd408c291d110fb Mon Sep 17 00:00:00 2001 From: Czipperz Date: Sat, 29 Dec 2018 19:14:06 -0500 Subject: [PATCH 2/2] Specify criterion for PartialOrd --- src/libcore/cmp.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 8eff9a8c8a2..f420d0d00a4 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -474,8 +474,9 @@ impl Ord for Reverse { /// /// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* /// agree with each other. That is, `a.cmp(b) == Ordering::Equal` if -/// and only if `a == b`. It's easy to accidentally make them disagree -/// by deriving some of the traits and manually implementing others. +/// and only if `a == b` and `Some(a.cmp(b)) == a.partial_cmp(b)` for +/// all `a` and `b`. It's easy to accidentally make them disagree by +/// deriving some of the traits and manually implementing others. /// /// Here's an example where you want to sort people by height only, disregarding `id` /// and `name`: