Skip to content

Commit

Permalink
Make iter::order functions into methods on Iterator
Browse files Browse the repository at this point in the history
This does cause some breakage due to deficiencies in resolve -
`path::Components` is both an `Iterator` and implements `Eq`, `Ord`,
etc. If one calls e.g. `partial_cmp` on a `Components` and passes a
`&Components` intending to target the `PartialOrd` impl, the compiler
will select the `partial_cmp` from `Iterator` and then error out. I
doubt anyone will run into breakage from `Components` specifically, but
we should see if there are third party types that will run into issues.

`iter::order::equals` wasn't moved to `Iterator` since it's exactly the
same as `iter::order::eq` but with an `Eq` instead of `PartialEq` bound,
which doensn't seem very useful.

I also updated `le`, `gt`, etc to use `partial_cmp` which lets us drop
the extra `PartialEq` bound.

cc #27737
  • Loading branch information
sfackler committed Aug 27, 2015
1 parent 63ba780 commit 651c42f
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 115 deletions.
6 changes: 3 additions & 3 deletions src/libcollections/btree/map.rs
Expand Up @@ -22,7 +22,7 @@ use core::fmt::Debug;
use core::hash::{Hash, Hasher};
use core::iter::{Map, FromIterator};
use core::ops::Index;
use core::{iter, fmt, mem, usize};
use core::{fmt, mem, usize};
use Bound::{self, Included, Excluded, Unbounded};

use borrow::Borrow;
Expand Down Expand Up @@ -915,15 +915,15 @@ impl<K: Eq, V: Eq> Eq for BTreeMap<K, V> {}
impl<K: PartialOrd, V: PartialOrd> PartialOrd for BTreeMap<K, V> {
#[inline]
fn partial_cmp(&self, other: &BTreeMap<K, V>) -> Option<Ordering> {
iter::order::partial_cmp(self.iter(), other.iter())
self.iter().partial_cmp(other.iter())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> {
#[inline]
fn cmp(&self, other: &BTreeMap<K, V>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
self.iter().cmp(other.iter())
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/libcollections/linked_list.rs
Expand Up @@ -25,7 +25,7 @@ use alloc::boxed::Box;
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hasher, Hash};
use core::iter::{self, FromIterator};
use core::iter::FromIterator;
use core::mem;
use core::ptr;

Expand Down Expand Up @@ -917,12 +917,12 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for LinkedList<T> {
impl<A: PartialEq> PartialEq for LinkedList<A> {
fn eq(&self, other: &LinkedList<A>) -> bool {
self.len() == other.len() &&
iter::order::eq(self.iter(), other.iter())
self.iter().eq(other.iter())
}

fn ne(&self, other: &LinkedList<A>) -> bool {
self.len() != other.len() ||
iter::order::ne(self.iter(), other.iter())
self.iter().ne(other.iter())
}
}

Expand All @@ -932,15 +932,15 @@ impl<A: Eq> Eq for LinkedList<A> {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialOrd> PartialOrd for LinkedList<A> {
fn partial_cmp(&self, other: &LinkedList<A>) -> Option<Ordering> {
iter::order::partial_cmp(self.iter(), other.iter())
self.iter().partial_cmp(other.iter())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Ord> Ord for LinkedList<A> {
#[inline]
fn cmp(&self, other: &LinkedList<A>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
self.iter().cmp(other.iter())
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/vec_deque.rs
Expand Up @@ -20,7 +20,7 @@

use core::cmp::Ordering;
use core::fmt;
use core::iter::{self, repeat, FromIterator};
use core::iter::{repeat, FromIterator};
use core::ops::{Index, IndexMut};
use core::ptr;
use core::slice;
Expand Down Expand Up @@ -1676,15 +1676,15 @@ impl<A: Eq> Eq for VecDeque<A> {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialOrd> PartialOrd for VecDeque<A> {
fn partial_cmp(&self, other: &VecDeque<A>) -> Option<Ordering> {
iter::order::partial_cmp(self.iter(), other.iter())
self.iter().partial_cmp(other.iter())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Ord> Ord for VecDeque<A> {
#[inline]
fn cmp(&self, other: &VecDeque<A>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
self.iter().cmp(other.iter())
}
}

Expand Down

0 comments on commit 651c42f

Please sign in to comment.