Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c8fcb5d

Browse files
author
Jorge Aparicio
committedDec 1, 2014
[Don't review] PR rust-lang#19167
1 parent acad03a commit c8fcb5d

File tree

40 files changed

+341
-218
lines changed

40 files changed

+341
-218
lines changed
 

‎src/libcollections/dlist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -945,15 +945,15 @@ mod tests {
945945
let mut m = list_from(v.as_slice());
946946
m.rotate_backward(); check_links(&m);
947947
m.rotate_forward(); check_links(&m);
948-
assert_eq!(v.iter().collect::<Vec<&int>>(), m.iter().collect());
948+
assert_eq!(v.iter().collect::<Vec<&int>>(), m.iter().collect::<Vec<_>>());
949949
m.rotate_forward(); check_links(&m);
950950
m.rotate_forward(); check_links(&m);
951951
m.pop_front(); check_links(&m);
952952
m.rotate_forward(); check_links(&m);
953953
m.rotate_backward(); check_links(&m);
954954
m.push_front(9); check_links(&m);
955955
m.rotate_forward(); check_links(&m);
956-
assert_eq!(vec![3i,9,5,1,2], m.into_iter().collect());
956+
assert_eq!(vec![3i,9,5,1,2], m.into_iter().collect::<Vec<_>>());
957957
}
958958

959959
#[test]

‎src/libcollections/enum_set.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -401,19 +401,19 @@ mod test {
401401
assert!(elems.is_empty())
402402

403403
e1.insert(A);
404-
let elems = e1.iter().collect();
404+
let elems: Vec<_> = e1.iter().collect();
405405
assert_eq!(vec![A], elems)
406406

407407
e1.insert(C);
408-
let elems = e1.iter().collect();
408+
let elems: Vec<_> = e1.iter().collect();
409409
assert_eq!(vec![A,C], elems)
410410

411411
e1.insert(C);
412-
let elems = e1.iter().collect();
412+
let elems: Vec<_> = e1.iter().collect();
413413
assert_eq!(vec![A,C], elems)
414414

415415
e1.insert(B);
416-
let elems = e1.iter().collect();
416+
let elems: Vec<_> = e1.iter().collect();
417417
assert_eq!(vec![A,B,C], elems)
418418
}
419419

@@ -431,35 +431,35 @@ mod test {
431431
e2.insert(C);
432432

433433
let e_union = e1 | e2;
434-
let elems = e_union.iter().collect();
434+
let elems: Vec<_> = e_union.iter().collect();
435435
assert_eq!(vec![A,B,C], elems)
436436

437437
let e_intersection = e1 & e2;
438-
let elems = e_intersection.iter().collect();
438+
let elems: Vec<_> = e_intersection.iter().collect();
439439
assert_eq!(vec![C], elems)
440440

441441
// Another way to express intersection
442442
let e_intersection = e1 - (e1 - e2);
443-
let elems = e_intersection.iter().collect();
443+
let elems: Vec<_> = e_intersection.iter().collect();
444444
assert_eq!(vec![C], elems)
445445

446446
let e_subtract = e1 - e2;
447-
let elems = e_subtract.iter().collect();
447+
let elems: Vec<_> = e_subtract.iter().collect();
448448
assert_eq!(vec![A], elems)
449449

450450
// Bitwise XOR of two sets, aka symmetric difference
451451
let e_symmetric_diff = e1 ^ e2;
452-
let elems = e_symmetric_diff.iter().collect();
452+
let elems: Vec<_> = e_symmetric_diff.iter().collect();
453453
assert_eq!(vec![A,B], elems)
454454

455455
// Another way to express symmetric difference
456456
let e_symmetric_diff = (e1 - e2) | (e2 - e1);
457-
let elems = e_symmetric_diff.iter().collect();
457+
let elems: Vec<_> = e_symmetric_diff.iter().collect();
458458
assert_eq!(vec![A,B], elems)
459459

460460
// Yet another way to express symmetric difference
461461
let e_symmetric_diff = (e1 | e2) - (e1 & e2);
462-
let elems = e_symmetric_diff.iter().collect();
462+
let elems: Vec<_> = e_symmetric_diff.iter().collect();
463463
assert_eq!(vec![A,B], elems)
464464
}
465465

‎src/libcollections/str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ impl<'a> Ord for MaybeOwned<'a> {
563563
}
564564
}
565565

566+
#[allow(deprecated)]
566567
#[deprecated = "use std::str::CowString"]
567568
impl<'a, S: Str> Equiv<S> for MaybeOwned<'a> {
568569
#[inline]

‎src/libcollections/string.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use str::{CharRange, CowString, FromStr, StrAllocating, Owned};
3030
use vec::{DerefVec, Vec, as_vec};
3131

3232
/// A growable string stored as a UTF-8 encoded buffer.
33-
#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord)]
33+
#[deriving(Clone, PartialOrd, Eq, Ord)]
3434
#[stable]
3535
pub struct String {
3636
vec: Vec<u8>,
@@ -738,6 +738,20 @@ impl Extend<char> for String {
738738
}
739739
}
740740

741+
impl<Rhs> PartialEq<Rhs> for String where Rhs: Deref<str> {
742+
#[inline]
743+
fn eq(&self, other: &Rhs) -> bool { PartialEq::eq(&**self, &**other) }
744+
#[inline]
745+
fn ne(&self, other: &Rhs) -> bool { PartialEq::ne(&**self, &**other) }
746+
}
747+
748+
impl<'a> PartialEq<String> for &'a str {
749+
#[inline]
750+
fn eq(&self, other: &String) -> bool { PartialEq::eq(*self, &**other) }
751+
#[inline]
752+
fn ne(&self, other: &String) -> bool { PartialEq::ne(*self, &**other) }
753+
}
754+
741755
#[experimental = "waiting on Str stabilization"]
742756
impl Str for String {
743757
#[inline]
@@ -779,7 +793,8 @@ impl<H: hash::Writer> hash::Hash<H> for String {
779793
}
780794
}
781795

782-
#[experimental = "waiting on Equiv stabilization"]
796+
#[allow(deprecated)]
797+
#[deprecated = "Use overloaded `core::cmp::PartialEq`"]
783798
impl<'a, S: Str> Equiv<S> for String {
784799
#[inline]
785800
fn equiv(&self, other: &S) -> bool {

‎src/libcollections/vec.rs

+24-10
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,25 @@ impl<T> Extend<T> for Vec<T> {
535535
}
536536
}
537537

538-
#[unstable = "waiting on PartialEq stability"]
539-
impl<T: PartialEq> PartialEq for Vec<T> {
538+
impl<A, B, Rhs> PartialEq<Rhs> for Vec<A> where A: PartialEq<B>, Rhs: Deref<[B]> {
540539
#[inline]
541-
fn eq(&self, other: &Vec<T>) -> bool {
542-
self.as_slice() == other.as_slice()
543-
}
540+
fn eq(&self, other: &Rhs) -> bool { PartialEq::eq(&**self, &**other) }
541+
#[inline]
542+
fn ne(&self, other: &Rhs) -> bool { PartialEq::ne(&**self, &**other) }
543+
}
544+
545+
impl<'a, A, B> PartialEq<Vec<B>> for &'a [A] where A: PartialEq<B> {
546+
#[inline]
547+
fn eq(&self, other: &Vec<B>) -> bool { PartialEq::eq(*self, &**other) }
548+
#[inline]
549+
fn ne(&self, other: &Vec<B>) -> bool { PartialEq::ne(*self, &**other) }
550+
}
551+
552+
impl<'a, A, B> PartialEq<Vec<B>> for &'a mut [A] where A: PartialEq<B> {
553+
#[inline]
554+
fn eq(&self, other: &Vec<B>) -> bool { PartialEq::eq(&**self, &**other) }
555+
#[inline]
556+
fn ne(&self, other: &Vec<B>) -> bool { PartialEq::ne(&**self, &**other) }
544557
}
545558

546559
#[unstable = "waiting on PartialOrd stability"]
@@ -554,7 +567,8 @@ impl<T: PartialOrd> PartialOrd for Vec<T> {
554567
#[unstable = "waiting on Eq stability"]
555568
impl<T: Eq> Eq for Vec<T> {}
556569

557-
#[experimental]
570+
#[allow(deprecated)]
571+
#[deprecated = "Use overloaded `core::cmp::PartialEq`"]
558572
impl<T: PartialEq, Sized? V: AsSlice<T>> Equiv<V> for Vec<T> {
559573
#[inline]
560574
fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() }
@@ -1813,27 +1827,27 @@ mod tests {
18131827
let mut values = vec![1u8,2,3,4,5];
18141828
{
18151829
let slice = values.slice_from_mut(2);
1816-
assert!(slice == &mut [3, 4, 5]);
1830+
assert!(slice == [3, 4, 5]);
18171831
for p in slice.iter_mut() {
18181832
*p += 2;
18191833
}
18201834
}
18211835

1822-
assert!(values.as_slice() == &[1, 2, 5, 6, 7]);
1836+
assert!(values.as_slice() == [1, 2, 5, 6, 7]);
18231837
}
18241838

18251839
#[test]
18261840
fn test_slice_to_mut() {
18271841
let mut values = vec![1u8,2,3,4,5];
18281842
{
18291843
let slice = values.slice_to_mut(2);
1830-
assert!(slice == &mut [1, 2]);
1844+
assert!(slice == [1, 2]);
18311845
for p in slice.iter_mut() {
18321846
*p += 1;
18331847
}
18341848
}
18351849

1836-
assert!(values.as_slice() == &[2, 3, 3, 4, 5]);
1850+
assert!(values.as_slice() == [2, 3, 3, 4, 5]);
18371851
}
18381852

18391853
#[test]

‎src/libcore/array.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use clone::Clone;
1818
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
1919
use fmt;
2020
use kinds::Copy;
21+
use ops::Deref;
2122
use option::Option;
2223

2324
// macro for implementing n-ary tuple functions and operations
@@ -39,17 +40,37 @@ macro_rules! array_impls {
3940
}
4041

4142
#[unstable = "waiting for PartialEq to stabilize"]
42-
impl<T:PartialEq> PartialEq for [T, ..$N] {
43+
impl<A, B> PartialEq<[B, ..$N]> for [A, ..$N] where A: PartialEq<B> {
4344
#[inline]
44-
fn eq(&self, other: &[T, ..$N]) -> bool {
45+
fn eq(&self, other: &[B, ..$N]) -> bool {
4546
self[] == other[]
4647
}
4748
#[inline]
48-
fn ne(&self, other: &[T, ..$N]) -> bool {
49+
fn ne(&self, other: &[B, ..$N]) -> bool {
4950
self[] != other[]
5051
}
5152
}
5253

54+
impl<'a, A, B, Rhs> PartialEq<Rhs> for [A, ..$N] where
55+
A: PartialEq<B>,
56+
Rhs: Deref<[B]>,
57+
{
58+
#[inline(always)]
59+
fn eq(&self, other: &Rhs) -> bool { PartialEq::eq(self[], &**other) }
60+
#[inline(always)]
61+
fn ne(&self, other: &Rhs) -> bool { PartialEq::ne(self[], &**other) }
62+
}
63+
64+
impl<'a, A, B, Lhs> PartialEq<[B, ..$N]> for Lhs where
65+
A: PartialEq<B>,
66+
Lhs: Deref<[A]>
67+
{
68+
#[inline(always)]
69+
fn eq(&self, other: &[B, ..$N]) -> bool { PartialEq::eq(&**self, other[]) }
70+
#[inline(always)]
71+
fn ne(&self, other: &[B, ..$N]) -> bool { PartialEq::ne(&**self, other[]) }
72+
}
73+
5374
#[unstable = "waiting for Eq to stabilize"]
5475
impl<T:Eq> Eq for [T, ..$N] { }
5576

0 commit comments

Comments
 (0)
Please sign in to comment.