diff options
| author | Mark Simulacrum <mark.simulacrum@gmail.com> | 2017-05-27 20:54:04 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-27 20:54:04 -0600 |
| commit | 423b410fcef856cd45cca3179119d62dd3a04af6 (patch) | |
| tree | f01300cc11a5676a794a1216108f7840dde788e6 /src/libcollections | |
| parent | 906c9bcfb97c4618765e6a8b8fb009ccbc4dbd3b (diff) | |
| parent | f5421367a2d72d5da415d2bbf97538099ff3ade0 (diff) | |
Rollup merge of #42260 - stjepang:document-cmp-traits-agreement, r=alexcrichton
Docs: impls of PartialEq/PartialOrd/Ord must agree Fixes #41270. This PR brings two improvements to the docs: 1. Docs for `PartialEq`, `PartialOrd`, and `Ord` clarify that their implementations must agree. 2. Fixes a subtle bug in the Dijkstra example for `BinaryHeap`, where the impls are inconsistent. Thanks @Rufflewind for spotting the bug! r? @alexcrichton cc @frankmcsherry
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/binary_heap.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 4e9dea09f79..988f8851625 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -43,8 +43,11 @@ //! // instead of a max-heap. //! impl Ord for State { //! fn cmp(&self, other: &State) -> Ordering { -//! // Notice that the we flip the ordering here +//! // Notice that the we flip the ordering on costs. +//! // In case of a tie we compare positions - this step is necessary +//! // to make implementations of `PartialEq` and `Ord` consistent. //! other.cost.cmp(&self.cost) +//! .then_with(|| self.position.cmp(&other.position)) //! } //! } //! |
