Skip to content

Commit 5cf126a

Browse files
committed
std: Remove #[old_orphan_check] from PartialEq
This is a deprecated attribute that is slated for removal, and it also affects all implementors of the trait. This commit removes the attribute and fixes up implementors accordingly. The primary implementation which was lost was the ability to compare `&[T]` and `Vec<T>` (in that order). This change also modifies the `assert_eq!` macro to not consider both directions of equality, only the one given in the left/right forms to the macro. This modification is motivated due to the fact that `&[T] == Vec<T>` no longer compiles, causing hundreds of errors in unit tests in the standard library (and likely throughout the community as well). cc rust-lang#19470 [breaking-change]
1 parent 80bf31d commit 5cf126a

File tree

19 files changed

+77
-86
lines changed

19 files changed

+77
-86
lines changed

src/doc/trpl/macros.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ number of elements.
3737

3838
```rust
3939
let x: Vec<u32> = vec![1, 2, 3];
40-
# assert_eq!(&[1,2,3], &x);
40+
# assert_eq!(x, [1, 2, 3]);
4141
```
4242

4343
This can't be an ordinary function, because it takes any number of arguments.
@@ -51,7 +51,7 @@ let x: Vec<u32> = {
5151
temp_vec.push(3);
5252
temp_vec
5353
};
54-
# assert_eq!(&[1,2,3], &x);
54+
# assert_eq!(x, [1, 2, 3]);
5555
```
5656

5757
We can implement this shorthand, using a macro: [^actual]
@@ -73,7 +73,7 @@ macro_rules! vec {
7373
};
7474
}
7575
# fn main() {
76-
# assert_eq!([1,2,3], vec![1,2,3]);
76+
# assert_eq!(vec![1,2,3], [1, 2, 3]);
7777
# }
7878
```
7979

src/libcollections/linked_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ mod test {
10791079
thread::spawn(move || {
10801080
check_links(&n);
10811081
let a: &[_] = &[&1,&2,&3];
1082-
assert_eq!(a, n.iter().collect::<Vec<_>>());
1082+
assert_eq!(a, &n.iter().collect::<Vec<_>>()[..]);
10831083
}).join().ok().unwrap();
10841084
}
10851085

src/libcollections/vec.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1533,22 +1533,22 @@ impl<T> Extend<T> for Vec<T> {
15331533
}
15341534

15351535
__impl_slice_eq1! { Vec<A>, Vec<B> }
1536-
__impl_slice_eq2! { Vec<A>, &'b [B] }
1537-
__impl_slice_eq2! { Vec<A>, &'b mut [B] }
1538-
__impl_slice_eq2! { Cow<'a, [A]>, &'b [B], Clone }
1539-
__impl_slice_eq2! { Cow<'a, [A]>, &'b mut [B], Clone }
1540-
__impl_slice_eq2! { Cow<'a, [A]>, Vec<B>, Clone }
1536+
__impl_slice_eq1! { Vec<A>, &'b [B] }
1537+
__impl_slice_eq1! { Vec<A>, &'b mut [B] }
1538+
__impl_slice_eq1! { Cow<'a, [A]>, &'b [B], Clone }
1539+
__impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B], Clone }
1540+
__impl_slice_eq1! { Cow<'a, [A]>, Vec<B>, Clone }
15411541

15421542
macro_rules! array_impls {
15431543
($($N: expr)+) => {
15441544
$(
15451545
// NOTE: some less important impls are omitted to reduce code bloat
1546-
__impl_slice_eq2! { Vec<A>, [B; $N] }
1547-
__impl_slice_eq2! { Vec<A>, &'b [B; $N] }
1548-
// __impl_slice_eq2! { Vec<A>, &'b mut [B; $N] }
1549-
// __impl_slice_eq2! { Cow<'a, [A]>, [B; $N], Clone }
1550-
// __impl_slice_eq2! { Cow<'a, [A]>, &'b [B; $N], Clone }
1551-
// __impl_slice_eq2! { Cow<'a, [A]>, &'b mut [B; $N], Clone }
1546+
__impl_slice_eq1! { Vec<A>, [B; $N] }
1547+
__impl_slice_eq1! { Vec<A>, &'b [B; $N] }
1548+
// __impl_slice_eq1! { Vec<A>, &'b mut [B; $N] }
1549+
// __impl_slice_eq1! { Cow<'a, [A]>, [B; $N], Clone }
1550+
// __impl_slice_eq1! { Cow<'a, [A]>, &'b [B; $N], Clone }
1551+
// __impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B; $N], Clone }
15521552
)+
15531553
}
15541554
}

src/libcollectionstest/enum_set.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,19 @@ fn test_iterator() {
153153

154154
e1.insert(A);
155155
let elems: Vec<_> = e1.iter().collect();
156-
assert_eq!([A], elems);
156+
assert_eq!(elems, [A]);
157157

158158
e1.insert(C);
159159
let elems: Vec<_> = e1.iter().collect();
160-
assert_eq!([A,C], elems);
160+
assert_eq!(elems, [A,C]);
161161

162162
e1.insert(C);
163163
let elems: Vec<_> = e1.iter().collect();
164-
assert_eq!([A,C], elems);
164+
assert_eq!(elems, [A,C]);
165165

166166
e1.insert(B);
167167
let elems: Vec<_> = e1.iter().collect();
168-
assert_eq!([A,B,C], elems);
168+
assert_eq!(elems, [A,B,C]);
169169
}
170170

171171
///////////////////////////////////////////////////////////////////////////
@@ -183,35 +183,35 @@ fn test_operators() {
183183

184184
let e_union = e1 | e2;
185185
let elems: Vec<_> = e_union.iter().collect();
186-
assert_eq!([A,B,C], elems);
186+
assert_eq!(elems, [A,B,C]);
187187

188188
let e_intersection = e1 & e2;
189189
let elems: Vec<_> = e_intersection.iter().collect();
190-
assert_eq!([C], elems);
190+
assert_eq!(elems, [C]);
191191

192192
// Another way to express intersection
193193
let e_intersection = e1 - (e1 - e2);
194194
let elems: Vec<_> = e_intersection.iter().collect();
195-
assert_eq!([C], elems);
195+
assert_eq!(elems, [C]);
196196

197197
let e_subtract = e1 - e2;
198198
let elems: Vec<_> = e_subtract.iter().collect();
199-
assert_eq!([A], elems);
199+
assert_eq!(elems, [A]);
200200

201201
// Bitwise XOR of two sets, aka symmetric difference
202202
let e_symmetric_diff = e1 ^ e2;
203203
let elems: Vec<_> = e_symmetric_diff.iter().collect();
204-
assert_eq!([A,B], elems);
204+
assert_eq!(elems, [A,B]);
205205

206206
// Another way to express symmetric difference
207207
let e_symmetric_diff = (e1 - e2) | (e2 - e1);
208208
let elems: Vec<_> = e_symmetric_diff.iter().collect();
209-
assert_eq!([A,B], elems);
209+
assert_eq!(elems, [A,B]);
210210

211211
// Yet another way to express symmetric difference
212212
let e_symmetric_diff = (e1 | e2) - (e1 & e2);
213213
let elems: Vec<_> = e_symmetric_diff.iter().collect();
214-
assert_eq!([A,B], elems);
214+
assert_eq!(elems, [A,B]);
215215
}
216216

217217
#[test]

src/libcollectionstest/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn test_collect() {
8383
fn test_into_bytes() {
8484
let data = String::from_str("asdf");
8585
let buf = data.into_bytes();
86-
assert_eq!(b"asdf", buf);
86+
assert_eq!(buf, b"asdf");
8787
}
8888

8989
#[test]

src/libcollectionstest/vec_deque.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ fn test_as_slices() {
821821

822822
let (left, right) = ring.as_slices();
823823
let expected: Vec<_> = (0..i+1).collect();
824-
assert_eq!(left, expected);
824+
assert_eq!(left, &expected[..]);
825825
assert_eq!(right, []);
826826
}
827827

@@ -830,8 +830,8 @@ fn test_as_slices() {
830830
let (left, right) = ring.as_slices();
831831
let expected_left: Vec<_> = (-last..j+1).rev().collect();
832832
let expected_right: Vec<_> = (0..first).collect();
833-
assert_eq!(left, expected_left);
834-
assert_eq!(right, expected_right);
833+
assert_eq!(left, &expected_left[..]);
834+
assert_eq!(right, &expected_right[..]);
835835
}
836836

837837
assert_eq!(ring.len() as i32, cap);
@@ -849,7 +849,7 @@ fn test_as_mut_slices() {
849849

850850
let (left, right) = ring.as_mut_slices();
851851
let expected: Vec<_> = (0..i+1).collect();
852-
assert_eq!(left, expected);
852+
assert_eq!(left, &expected[..]);
853853
assert_eq!(right, []);
854854
}
855855

@@ -858,8 +858,8 @@ fn test_as_mut_slices() {
858858
let (left, right) = ring.as_mut_slices();
859859
let expected_left: Vec<_> = (-last..j+1).rev().collect();
860860
let expected_right: Vec<_> = (0..first).collect();
861-
assert_eq!(left, expected_left);
862-
assert_eq!(right, expected_right);
861+
assert_eq!(left, &expected_left[..]);
862+
assert_eq!(right, &expected_right[..]);
863863
}
864864

865865
assert_eq!(ring.len() as i32, cap);

src/libcore/cmp.rs

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ use option::Option::{self, Some, None};
6464
/// inverse of `ne`; that is, `!(a == b)` if and only if `a != b`.
6565
#[lang="eq"]
6666
#[stable(feature = "rust1", since = "1.0.0")]
67-
#[old_orphan_check]
6867
pub trait PartialEq<Rhs: ?Sized = Self> {
6968
/// This method tests for `self` and `other` values to be equal, and is used by `==`.
7069
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/cmp_macros.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
#[macro_export]
1616
macro_rules! __impl_slice_eq1 {
1717
($Lhs: ty, $Rhs: ty) => {
18+
__impl_slice_eq1! { $Lhs, $Rhs, Sized }
19+
};
20+
($Lhs: ty, $Rhs: ty, $Bound: ident) => {
1821
#[stable(feature = "rust1", since = "1.0.0")]
19-
impl<'a, 'b, A, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> {
22+
impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> {
2023
#[inline]
2124
fn eq(&self, other: &$Rhs) -> bool { &self[..] == &other[..] }
2225
#[inline]
@@ -31,13 +34,7 @@ macro_rules! __impl_slice_eq2 {
3134
__impl_slice_eq2! { $Lhs, $Rhs, Sized }
3235
};
3336
($Lhs: ty, $Rhs: ty, $Bound: ident) => {
34-
#[stable(feature = "rust1", since = "1.0.0")]
35-
impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> {
36-
#[inline]
37-
fn eq(&self, other: &$Rhs) -> bool { &self[..] == &other[..] }
38-
#[inline]
39-
fn ne(&self, other: &$Rhs) -> bool { &self[..] != &other[..] }
40-
}
37+
__impl_slice_eq1!($Lhs, $Rhs, $Bound);
4138

4239
#[stable(feature = "rust1", since = "1.0.0")]
4340
impl<'a, 'b, A: $Bound, B> PartialEq<$Lhs> for $Rhs where B: PartialEq<A> {

src/libcore/iter.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,9 @@ pub trait Iterator {
530530
/// # Examples
531531
///
532532
/// ```
533-
/// # #![feature(core)]
534-
/// let a = [1, 2, 3, 4, 5];
535-
/// let b: Vec<_> = a.iter().cloned().collect();
536-
/// assert_eq!(a, b);
533+
/// let expected = [1, 2, 3, 4, 5];
534+
/// let actual: Vec<_> = expected.iter().cloned().collect();
535+
/// assert_eq!(actual, expected);
537536
/// ```
538537
#[inline]
539538
#[stable(feature = "rust1", since = "1.0.0")]
@@ -927,8 +926,8 @@ pub trait Iterator {
927926
/// # #![feature(core)]
928927
/// let a = [(1, 2), (3, 4)];
929928
/// let (left, right): (Vec<_>, Vec<_>) = a.iter().cloned().unzip();
930-
/// assert_eq!([1, 3], left);
931-
/// assert_eq!([2, 4], right);
929+
/// assert_eq!(left, [1, 3]);
930+
/// assert_eq!(right, [2, 4]);
932931
/// ```
933932
#[unstable(feature = "core", reason = "recent addition")]
934933
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where

src/libcore/macros.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ macro_rules! assert {
6666
);
6767
}
6868

69-
/// Asserts that two expressions are equal to each other, testing equality in
70-
/// both directions.
69+
/// Asserts that two expressions are equal to each other.
7170
///
72-
/// On panic, this macro will print the values of the expressions.
71+
/// On panic, this macro will print the values of the expressions with their
72+
/// debug representations.
7373
///
7474
/// # Examples
7575
///
@@ -84,10 +84,8 @@ macro_rules! assert_eq {
8484
($left:expr , $right:expr) => ({
8585
match (&($left), &($right)) {
8686
(left_val, right_val) => {
87-
// check both directions of equality....
88-
if !((*left_val == *right_val) &&
89-
(*right_val == *left_val)) {
90-
panic!("assertion failed: `(left == right) && (right == left)` \
87+
if !(*left_val == *right_val) {
88+
panic!("assertion failed: `(left == right)` \
9189
(left: `{:?}`, right: `{:?}`)", *left_val, *right_val)
9290
}
9391
}

src/libcoretest/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn test_transmute() {
103103
}
104104

105105
unsafe {
106-
assert_eq!([76], transmute::<_, Vec<u8>>("L".to_string()));
106+
assert_eq!(transmute::<_, Vec<u8>>("L".to_string()), [76]);
107107
}
108108
}
109109

src/libfmt_macros/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ mod tests {
446446

447447
fn same(fmt: &'static str, p: &[Piece<'static>]) {
448448
let parser = Parser::new(fmt);
449-
assert!(p == parser.collect::<Vec<Piece<'static>>>());
449+
assert!(parser.collect::<Vec<Piece<'static>>>() == p);
450450
}
451451

452452
fn fmtdflt() -> FormatSpec<'static> {

src/librustc_driver/test.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -808,12 +808,11 @@ fn walk_ty() {
808808
let tup2_ty = ty::mk_tup(tcx, vec!(tup1_ty, tup1_ty, uint_ty));
809809
let uniq_ty = ty::mk_uniq(tcx, tup2_ty);
810810
let walked: Vec<_> = uniq_ty.walk().collect();
811-
assert_eq!([uniq_ty,
812-
tup2_ty,
813-
tup1_ty, int_ty, uint_ty, int_ty, uint_ty,
814-
tup1_ty, int_ty, uint_ty, int_ty, uint_ty,
815-
uint_ty],
816-
walked);
811+
assert_eq!(walked, [uniq_ty,
812+
tup2_ty,
813+
tup1_ty, int_ty, uint_ty, int_ty, uint_ty,
814+
tup1_ty, int_ty, uint_ty, int_ty, uint_ty,
815+
uint_ty]);
817816
})
818817
}
819818

src/libstd/collections/hash/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ mod test_set {
11921192
};
11931193

11941194
let v = hs.into_iter().collect::<Vec<char>>();
1195-
assert!(['a', 'b'] == v || ['b', 'a'] == v);
1195+
assert!(v == ['a', 'b'] || v == ['b', 'a']);
11961196
}
11971197

11981198
#[test]

src/libstd/old_io/buffered.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ mod test {
548548
let mut w = BufferedWriter::with_capacity(3, Vec::new());
549549
w.write_all(&[0, 1]).unwrap();
550550
let a: &[_] = &[];
551-
assert_eq!(a, &w.get_ref()[..]);
551+
assert_eq!(&w.get_ref()[..], a);
552552
let w = w.into_inner();
553553
let a: &[_] = &[0, 1];
554554
assert_eq!(a, &w[..]);

0 commit comments

Comments
 (0)