Skip to content

Commit 6585294

Browse files
committed
Merge pull request #20155 from tbu-/pr_vecmap_fiximpls
Fix `collections::VecMap`'s `PartialEq` implementation Reviewed-by: Gankro
2 parents 3f8d94e + d62cf31 commit 6585294

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/libcollections/ring_buf.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1295,9 +1295,6 @@ impl<A: PartialEq> PartialEq for RingBuf<A> {
12951295
self.len() == other.len() &&
12961296
self.iter().zip(other.iter()).all(|(a, b)| a.eq(b))
12971297
}
1298-
fn ne(&self, other: &RingBuf<A>) -> bool {
1299-
!self.eq(other)
1300-
}
13011298
}
13021299

13031300
impl<A: Eq> Eq for RingBuf<A> {}

src/libcollections/vec_map.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ use vec::Vec;
6060
/// months.clear();
6161
/// assert!(months.is_empty());
6262
/// ```
63-
#[deriving(PartialEq, Eq)]
6463
pub struct VecMap<V> {
6564
v: Vec<Option<V>>,
6665
}
@@ -492,6 +491,14 @@ impl<V:Clone> VecMap<V> {
492491
}
493492
}
494493

494+
impl<V: PartialEq> PartialEq for VecMap<V> {
495+
fn eq(&self, other: &VecMap<V>) -> bool {
496+
iter::order::eq(self.iter(), other.iter())
497+
}
498+
}
499+
500+
impl<V: Eq> Eq for VecMap<V> {}
501+
495502
impl<V: PartialOrd> PartialOrd for VecMap<V> {
496503
#[inline]
497504
fn partial_cmp(&self, other: &VecMap<V>) -> Option<Ordering> {
@@ -955,6 +962,10 @@ mod test_map {
955962
assert!(a != b);
956963
assert!(b.insert(5, 19).is_none());
957964
assert!(a == b);
965+
966+
a = VecMap::new();
967+
b = VecMap::with_capacity(1);
968+
assert!(a == b);
958969
}
959970

960971
#[test]

0 commit comments

Comments
 (0)