Skip to content

Commit 41e74a2

Browse files
committedMay 28, 2017
Auto merge of #42276 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 6 pull requests - Successful merges: #42207, #42217, #42249, #42251, #42260, #42266 - Failed merges:
·
1.88.01.19.0
2 parents 5d2512e + 1128fab commit 41e74a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+155
-1235
lines changed
 

‎src/libcollections/binary_heap.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@
4343
//! // instead of a max-heap.
4444
//! impl Ord for State {
4545
//! fn cmp(&self, other: &State) -> Ordering {
46-
//! // Notice that the we flip the ordering here
46+
//! // Notice that the we flip the ordering on costs.
47+
//! // In case of a tie we compare positions - this step is necessary
48+
//! // to make implementations of `PartialEq` and `Ord` consistent.
4749
//! other.cost.cmp(&self.cost)
50+
//! .then_with(|| self.position.cmp(&other.position))
4851
//! }
4952
//! }
5053
//!

‎src/libcore/cmp.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ use self::Ordering::*;
6767
/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
6868
/// only if `a != b`.
6969
///
70+
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with
71+
/// each other. It's easy to accidentally make them disagree by deriving some
72+
/// of the traits and manually implementing others.
73+
///
7074
/// An example implementation for a domain in which two books are considered
7175
/// the same book if their ISBN matches, even if the formats differ:
7276
///
@@ -386,6 +390,10 @@ impl<T: Ord> Ord for Reverse<T> {
386390
/// Then you must define an implementation for `cmp()`. You may find it useful to use
387391
/// `cmp()` on your type's fields.
388392
///
393+
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with each other. It's
394+
/// easy to accidentally make them disagree by deriving some of the traits and manually
395+
/// implementing others.
396+
///
389397
/// Here's an example where you want to sort people by height only, disregarding `id`
390398
/// and `name`:
391399
///
@@ -474,15 +482,19 @@ impl PartialOrd for Ordering {
474482
///
475483
/// ## How can I implement `PartialOrd`?
476484
///
477-
/// PartialOrd only requires implementation of the `partial_cmp` method, with the others generated
478-
/// from default implementations.
485+
/// `PartialOrd` only requires implementation of the `partial_cmp` method, with the others
486+
/// generated from default implementations.
479487
///
480488
/// However it remains possible to implement the others separately for types which do not have a
481489
/// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
482490
/// false` (cf. IEEE 754-2008 section 5.11).
483491
///
484492
/// `PartialOrd` requires your type to be `PartialEq`.
485493
///
494+
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with each other. It's
495+
/// easy to accidentally make them disagree by deriving some of the traits and manually
496+
/// implementing others.
497+
///
486498
/// If your type is `Ord`, you can implement `partial_cmp()` by using `cmp()`:
487499
///
488500
/// ```

0 commit comments

Comments
 (0)
Please sign in to comment.