Skip to content

Commit b94bcbf

Browse files
committed
Stabilize cmp
This patch marks `PartialEq`, `Eq`, `PartialOrd`, and `Ord` as `#[stable]`, as well as the majorify of manual implementaitons of these traits. The traits match the [reform RFC](rust-lang/rfcs#439). Along the way, two changes are made: * The recently-added type parameters for `Ord` and `Eq` are removed. These were mistakenly added while adding them to `PartialOrd` and `PartialEq`, but they don't make sense given the laws that are required for (and use cases for) `Ord` and `Eq`. * More explicit laws are added for `PartialEq` and `PartialOrd`, connecting them to their associated mathematical concepts. In the future, many of the impls should be generalized; see since generalizing later is not a breaking change. [breaking-change]
1 parent 84f5ad8 commit b94bcbf

File tree

20 files changed

+182
-83
lines changed

20 files changed

+182
-83
lines changed

src/liballoc/arc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<T: Sync + Send> Drop for Weak<T> {
458458
}
459459
}
460460

461-
#[unstable = "waiting on PartialEq"]
461+
#[stable]
462462
impl<T: PartialEq> PartialEq for Arc<T> {
463463
/// Equality for two `Arc<T>`s.
464464
///
@@ -490,7 +490,7 @@ impl<T: PartialEq> PartialEq for Arc<T> {
490490
/// ```
491491
fn ne(&self, other: &Arc<T>) -> bool { *(*self) != *(*other) }
492492
}
493-
#[unstable = "waiting on PartialOrd"]
493+
#[stable]
494494
impl<T: PartialOrd> PartialOrd for Arc<T> {
495495
/// Partial comparison for two `Arc<T>`s.
496496
///
@@ -569,11 +569,11 @@ impl<T: PartialOrd> PartialOrd for Arc<T> {
569569
/// ```
570570
fn ge(&self, other: &Arc<T>) -> bool { *(*self) >= *(*other) }
571571
}
572-
#[unstable = "waiting on Ord"]
572+
#[stable]
573573
impl<T: Ord> Ord for Arc<T> {
574574
fn cmp(&self, other: &Arc<T>) -> Ordering { (**self).cmp(&**other) }
575575
}
576-
#[unstable = "waiting on Eq"]
576+
#[stable]
577577
impl<T: Eq> Eq for Arc<T> {}
578578

579579
impl<T: fmt::Show> fmt::Show for Arc<T> {

src/liballoc/boxed.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ impl<T: Clone> Clone for Box<T> {
7272
}
7373
}
7474

75+
#[stable]
7576
impl<Sized? T: PartialEq> PartialEq for Box<T> {
7677
#[inline]
7778
fn eq(&self, other: &Box<T>) -> bool { PartialEq::eq(&**self, &**other) }
7879
#[inline]
7980
fn ne(&self, other: &Box<T>) -> bool { PartialEq::ne(&**self, &**other) }
8081
}
82+
#[stable]
8183
impl<Sized? T: PartialOrd> PartialOrd for Box<T> {
8284
#[inline]
8385
fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
@@ -92,12 +94,14 @@ impl<Sized? T: PartialOrd> PartialOrd for Box<T> {
9294
#[inline]
9395
fn gt(&self, other: &Box<T>) -> bool { PartialOrd::gt(&**self, &**other) }
9496
}
97+
#[stable]
9598
impl<Sized? T: Ord> Ord for Box<T> {
9699
#[inline]
97100
fn cmp(&self, other: &Box<T>) -> Ordering {
98101
Ord::cmp(&**self, &**other)
99102
}
100-
}
103+
104+
#[stable]}
101105
impl<Sized? T: Eq> Eq for Box<T> {}
102106

103107
impl<S: hash::Writer, Sized? T: Hash<S>> Hash<S> for Box<T> {

src/liballoc/rc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl<T: Default> Default for Rc<T> {
452452
}
453453
}
454454

455-
#[unstable = "PartialEq is unstable."]
455+
#[stable]
456456
impl<T: PartialEq> PartialEq for Rc<T> {
457457
/// Equality for two `Rc<T>`s.
458458
///
@@ -487,10 +487,10 @@ impl<T: PartialEq> PartialEq for Rc<T> {
487487
fn ne(&self, other: &Rc<T>) -> bool { **self != **other }
488488
}
489489

490-
#[unstable = "Eq is unstable."]
490+
#[stable]
491491
impl<T: Eq> Eq for Rc<T> {}
492492

493-
#[unstable = "PartialOrd is unstable."]
493+
#[stable]
494494
impl<T: PartialOrd> PartialOrd for Rc<T> {
495495
/// Partial comparison for two `Rc<T>`s.
496496
///
@@ -575,7 +575,7 @@ impl<T: PartialOrd> PartialOrd for Rc<T> {
575575
fn ge(&self, other: &Rc<T>) -> bool { **self >= **other }
576576
}
577577

578-
#[unstable = "Ord is unstable."]
578+
#[stable]
579579
impl<T: Ord> Ord for Rc<T> {
580580
/// Comparison for two `Rc<T>`s.
581581
///

src/libcollections/bit.rs

+8
Original file line numberDiff line numberDiff line change
@@ -965,13 +965,15 @@ impl Clone for Bitv {
965965
}
966966
}
967967

968+
#[stable]
968969
impl PartialOrd for Bitv {
969970
#[inline]
970971
fn partial_cmp(&self, other: &Bitv) -> Option<Ordering> {
971972
iter::order::partial_cmp(self.iter(), other.iter())
972973
}
973974
}
974975

976+
#[stable]
975977
impl Ord for Bitv {
976978
#[inline]
977979
fn cmp(&self, other: &Bitv) -> Ordering {
@@ -997,6 +999,7 @@ impl<S: hash::Writer> hash::Hash<S> for Bitv {
997999
}
9981000
}
9991001

1002+
#[stable]
10001003
impl cmp::PartialEq for Bitv {
10011004
#[inline]
10021005
fn eq(&self, other: &Bitv) -> bool {
@@ -1007,6 +1010,7 @@ impl cmp::PartialEq for Bitv {
10071010
}
10081011
}
10091012

1013+
#[stable]
10101014
impl cmp::Eq for Bitv {}
10111015

10121016
/// An iterator for `Bitv`.
@@ -1129,6 +1133,7 @@ impl Extend<uint> for BitvSet {
11291133
}
11301134
}
11311135

1136+
#[stable]
11321137
impl PartialOrd for BitvSet {
11331138
#[inline]
11341139
fn partial_cmp(&self, other: &BitvSet) -> Option<Ordering> {
@@ -1137,6 +1142,7 @@ impl PartialOrd for BitvSet {
11371142
}
11381143
}
11391144

1145+
#[stable]
11401146
impl Ord for BitvSet {
11411147
#[inline]
11421148
fn cmp(&self, other: &BitvSet) -> Ordering {
@@ -1145,6 +1151,7 @@ impl Ord for BitvSet {
11451151
}
11461152
}
11471153

1154+
#[stable]
11481155
impl cmp::PartialEq for BitvSet {
11491156
#[inline]
11501157
fn eq(&self, other: &BitvSet) -> bool {
@@ -1153,6 +1160,7 @@ impl cmp::PartialEq for BitvSet {
11531160
}
11541161
}
11551162

1163+
#[stable]
11561164
impl cmp::Eq for BitvSet {}
11571165

11581166
impl BitvSet {

src/libcollections/btree/map.rs

+4
Original file line numberDiff line numberDiff line change
@@ -843,22 +843,26 @@ impl<K: Ord, V> Default for BTreeMap<K, V> {
843843
}
844844
}
845845

846+
#[stable]
846847
impl<K: PartialEq, V: PartialEq> PartialEq for BTreeMap<K, V> {
847848
fn eq(&self, other: &BTreeMap<K, V>) -> bool {
848849
self.len() == other.len() &&
849850
self.iter().zip(other.iter()).all(|(a, b)| a == b)
850851
}
851852
}
852853

854+
#[stable]
853855
impl<K: Eq, V: Eq> Eq for BTreeMap<K, V> {}
854856

857+
#[stable]
855858
impl<K: PartialOrd, V: PartialOrd> PartialOrd for BTreeMap<K, V> {
856859
#[inline]
857860
fn partial_cmp(&self, other: &BTreeMap<K, V>) -> Option<Ordering> {
858861
iter::order::partial_cmp(self.iter(), other.iter())
859862
}
860863
}
861864

865+
#[stable]
862866
impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> {
863867
#[inline]
864868
fn cmp(&self, other: &BTreeMap<K, V>) -> Ordering {

src/libcollections/dlist.rs

+4
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ impl<A> Extend<A> for DList<A> {
770770
}
771771
}
772772

773+
#[stable]
773774
impl<A: PartialEq> PartialEq for DList<A> {
774775
fn eq(&self, other: &DList<A>) -> bool {
775776
self.len() == other.len() &&
@@ -782,14 +783,17 @@ impl<A: PartialEq> PartialEq for DList<A> {
782783
}
783784
}
784785

786+
#[stable]
785787
impl<A: Eq> Eq for DList<A> {}
786788

789+
#[stable]
787790
impl<A: PartialOrd> PartialOrd for DList<A> {
788791
fn partial_cmp(&self, other: &DList<A>) -> Option<Ordering> {
789792
iter::order::partial_cmp(self.iter(), other.iter())
790793
}
791794
}
792795

796+
#[stable]
793797
impl<A: Ord> Ord for DList<A> {
794798
#[inline]
795799
fn cmp(&self, other: &DList<A>) -> Ordering {

src/libcollections/ring_buf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1290,21 +1290,25 @@ impl<'a, T: 'a> DoubleEndedIterator<T> for Drain<'a, T> {
12901290

12911291
impl<'a, T: 'a> ExactSizeIterator<T> for Drain<'a, T> {}
12921292

1293+
#[stable]
12931294
impl<A: PartialEq> PartialEq for RingBuf<A> {
12941295
fn eq(&self, other: &RingBuf<A>) -> bool {
12951296
self.len() == other.len() &&
12961297
self.iter().zip(other.iter()).all(|(a, b)| a.eq(b))
12971298
}
12981299
}
12991300

1301+
#[stable]
13001302
impl<A: Eq> Eq for RingBuf<A> {}
13011303

1304+
#[stable]
13021305
impl<A: PartialOrd> PartialOrd for RingBuf<A> {
13031306
fn partial_cmp(&self, other: &RingBuf<A>) -> Option<Ordering> {
13041307
iter::order::partial_cmp(self.iter(), other.iter())
13051308
}
13061309
}
13071310

1311+
#[stable]
13081312
impl<A: Ord> Ord for RingBuf<A> {
13091313
#[inline]
13101314
fn cmp(&self, other: &RingBuf<A>) -> Ordering {

src/libcollections/string.rs

+5
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ impl<'a> Extend<&'a str> for String {
815815
}
816816
}
817817

818+
#[stable]
818819
impl PartialEq for String {
819820
#[inline]
820821
fn eq(&self, other: &String) -> bool { PartialEq::eq(&**self, &**other) }
@@ -824,13 +825,15 @@ impl PartialEq for String {
824825

825826
macro_rules! impl_eq {
826827
($lhs:ty, $rhs: ty) => {
828+
#[stable]
827829
impl<'a> PartialEq<$rhs> for $lhs {
828830
#[inline]
829831
fn eq(&self, other: &$rhs) -> bool { PartialEq::eq(&**self, &**other) }
830832
#[inline]
831833
fn ne(&self, other: &$rhs) -> bool { PartialEq::ne(&**self, &**other) }
832834
}
833835

836+
#[stable]
834837
impl<'a> PartialEq<$lhs> for $rhs {
835838
#[inline]
836839
fn eq(&self, other: &$lhs) -> bool { PartialEq::eq(&**self, &**other) }
@@ -844,13 +847,15 @@ macro_rules! impl_eq {
844847
impl_eq! { String, &'a str }
845848
impl_eq! { CowString<'a>, String }
846849

850+
#[stable]
847851
impl<'a, 'b> PartialEq<&'b str> for CowString<'a> {
848852
#[inline]
849853
fn eq(&self, other: &&'b str) -> bool { PartialEq::eq(&**self, &**other) }
850854
#[inline]
851855
fn ne(&self, other: &&'b str) -> bool { PartialEq::ne(&**self, &**other) }
852856
}
853857

858+
#[stable]
854859
impl<'a, 'b> PartialEq<CowString<'a>> for &'b str {
855860
#[inline]
856861
fn eq(&self, other: &CowString<'a>) -> bool { PartialEq::eq(&**self, &**other) }

src/libcollections/vec.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ impl<T> Extend<T> for Vec<T> {
588588
}
589589
}
590590

591+
#[stable]
591592
impl<A, B> PartialEq<Vec<B>> for Vec<A> where A: PartialEq<B> {
592593
#[inline]
593594
fn eq(&self, other: &Vec<B>) -> bool { PartialEq::eq(&**self, &**other) }
@@ -597,13 +598,15 @@ impl<A, B> PartialEq<Vec<B>> for Vec<A> where A: PartialEq<B> {
597598

598599
macro_rules! impl_eq {
599600
($lhs:ty, $rhs:ty) => {
601+
#[stable]
600602
impl<'b, A, B> PartialEq<$rhs> for $lhs where A: PartialEq<B> {
601603
#[inline]
602604
fn eq(&self, other: &$rhs) -> bool { PartialEq::eq(&**self, &**other) }
603605
#[inline]
604606
fn ne(&self, other: &$rhs) -> bool { PartialEq::ne(&**self, &**other) }
605607
}
606608

609+
#[stable]
607610
impl<'b, A, B> PartialEq<$lhs> for $rhs where B: PartialEq<A> {
608611
#[inline]
609612
fn eq(&self, other: &$lhs) -> bool { PartialEq::eq(&**self, &**other) }
@@ -616,13 +619,15 @@ macro_rules! impl_eq {
616619
impl_eq! { Vec<A>, &'b [B] }
617620
impl_eq! { Vec<A>, &'b mut [B] }
618621

622+
#[stable]
619623
impl<'a, A, B> PartialEq<Vec<B>> for CowVec<'a, A> where A: PartialEq<B> + Clone {
620624
#[inline]
621625
fn eq(&self, other: &Vec<B>) -> bool { PartialEq::eq(&**self, &**other) }
622626
#[inline]
623627
fn ne(&self, other: &Vec<B>) -> bool { PartialEq::ne(&**self, &**other) }
624628
}
625629

630+
#[stable]
626631
impl<'a, A, B> PartialEq<CowVec<'a, A>> for Vec<B> where A: Clone, B: PartialEq<A> {
627632
#[inline]
628633
fn eq(&self, other: &CowVec<'a, A>) -> bool { PartialEq::eq(&**self, &**other) }
@@ -632,13 +637,15 @@ impl<'a, A, B> PartialEq<CowVec<'a, A>> for Vec<B> where A: Clone, B: PartialEq<
632637

633638
macro_rules! impl_eq_for_cowvec {
634639
($rhs:ty) => {
640+
#[stable]
635641
impl<'a, 'b, A, B> PartialEq<$rhs> for CowVec<'a, A> where A: PartialEq<B> + Clone {
636642
#[inline]
637643
fn eq(&self, other: &$rhs) -> bool { PartialEq::eq(&**self, &**other) }
638644
#[inline]
639645
fn ne(&self, other: &$rhs) -> bool { PartialEq::ne(&**self, &**other) }
640646
}
641647

648+
#[stable]
642649
impl<'a, 'b, A, B> PartialEq<CowVec<'a, A>> for $rhs where A: Clone, B: PartialEq<A> {
643650
#[inline]
644651
fn eq(&self, other: &CowVec<'a, A>) -> bool { PartialEq::eq(&**self, &**other) }
@@ -651,15 +658,15 @@ macro_rules! impl_eq_for_cowvec {
651658
impl_eq_for_cowvec! { &'b [B] }
652659
impl_eq_for_cowvec! { &'b mut [B] }
653660

654-
#[unstable = "waiting on PartialOrd stability"]
661+
#[stable]
655662
impl<T: PartialOrd> PartialOrd for Vec<T> {
656663
#[inline]
657664
fn partial_cmp(&self, other: &Vec<T>) -> Option<Ordering> {
658665
self.as_slice().partial_cmp(other.as_slice())
659666
}
660667
}
661668

662-
#[unstable = "waiting on Eq stability"]
669+
#[stable]
663670
impl<T: Eq> Eq for Vec<T> {}
664671

665672
#[allow(deprecated)]
@@ -669,7 +676,7 @@ impl<T: PartialEq, Sized? V: AsSlice<T>> Equiv<V> for Vec<T> {
669676
fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() }
670677
}
671678

672-
#[unstable = "waiting on Ord stability"]
679+
#[stable]
673680
impl<T: Ord> Ord for Vec<T> {
674681
#[inline]
675682
fn cmp(&self, other: &Vec<T>) -> Ordering {

src/libcollections/vec_map.rs

+5
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,26 @@ impl<V:Clone> VecMap<V> {
537537
}
538538
}
539539

540+
541+
#[stable]
540542
impl<V: PartialEq> PartialEq for VecMap<V> {
541543
fn eq(&self, other: &VecMap<V>) -> bool {
542544
iter::order::eq(self.iter(), other.iter())
543545
}
544546
}
545547

548+
#[stable]
546549
impl<V: Eq> Eq for VecMap<V> {}
547550

551+
#[stable]
548552
impl<V: PartialOrd> PartialOrd for VecMap<V> {
549553
#[inline]
550554
fn partial_cmp(&self, other: &VecMap<V>) -> Option<Ordering> {
551555
iter::order::partial_cmp(self.iter(), other.iter())
552556
}
553557
}
554558

559+
#[stable]
555560
impl<V: Ord> Ord for VecMap<V> {
556561
#[inline]
557562
fn cmp(&self, other: &VecMap<V>) -> Ordering {

0 commit comments

Comments
 (0)