Skip to content

Commit 3422be3

Browse files
committed
rollup merge of rust-lang#23288: alexcrichton/issue-19470
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). Closes rust-lang#19470 [breaking-change]
2 parents 30283d4 + 608fff8 commit 3422be3

28 files changed

+96
-127
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
@@ -1076,7 +1076,7 @@ mod test {
10761076
thread::spawn(move || {
10771077
check_links(&n);
10781078
let a: &[_] = &[&1,&2,&3];
1079-
assert_eq!(a, n.iter().collect::<Vec<_>>());
1079+
assert_eq!(a, &n.iter().collect::<Vec<_>>()[..]);
10801080
}).join().ok().unwrap();
10811081
}
10821082

src/libcollections/vec.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1540,22 +1540,22 @@ impl<T> Extend<T> for Vec<T> {
15401540
}
15411541

15421542
__impl_slice_eq1! { Vec<A>, Vec<B> }
1543-
__impl_slice_eq2! { Vec<A>, &'b [B] }
1544-
__impl_slice_eq2! { Vec<A>, &'b mut [B] }
1545-
__impl_slice_eq2! { Cow<'a, [A]>, &'b [B], Clone }
1546-
__impl_slice_eq2! { Cow<'a, [A]>, &'b mut [B], Clone }
1547-
__impl_slice_eq2! { Cow<'a, [A]>, Vec<B>, Clone }
1543+
__impl_slice_eq1! { Vec<A>, &'b [B] }
1544+
__impl_slice_eq1! { Vec<A>, &'b mut [B] }
1545+
__impl_slice_eq1! { Cow<'a, [A]>, &'b [B], Clone }
1546+
__impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B], Clone }
1547+
__impl_slice_eq1! { Cow<'a, [A]>, Vec<B>, Clone }
15481548

15491549
macro_rules! array_impls {
15501550
($($N: expr)+) => {
15511551
$(
15521552
// NOTE: some less important impls are omitted to reduce code bloat
1553-
__impl_slice_eq2! { Vec<A>, [B; $N] }
1554-
__impl_slice_eq2! { Vec<A>, &'b [B; $N] }
1555-
// __impl_slice_eq2! { Vec<A>, &'b mut [B; $N] }
1556-
// __impl_slice_eq2! { Cow<'a, [A]>, [B; $N], Clone }
1557-
// __impl_slice_eq2! { Cow<'a, [A]>, &'b [B; $N], Clone }
1558-
// __impl_slice_eq2! { Cow<'a, [A]>, &'b mut [B; $N], Clone }
1553+
__impl_slice_eq1! { Vec<A>, [B; $N] }
1554+
__impl_slice_eq1! { Vec<A>, &'b [B; $N] }
1555+
// __impl_slice_eq1! { Vec<A>, &'b mut [B; $N] }
1556+
// __impl_slice_eq1! { Cow<'a, [A]>, [B; $N], Clone }
1557+
// __impl_slice_eq1! { Cow<'a, [A]>, &'b [B; $N], Clone }
1558+
// __impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B; $N], Clone }
15591559
)+
15601560
}
15611561
}

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
@@ -820,7 +820,7 @@ fn test_as_slices() {
820820

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

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

836836
assert_eq!(ring.len() as i32, cap);
@@ -848,7 +848,7 @@ fn test_as_mut_slices() {
848848

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

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

864864
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
@@ -532,10 +532,9 @@ pub trait Iterator {
532532
/// # Examples
533533
///
534534
/// ```
535-
/// # #![feature(core)]
536-
/// let a = [1, 2, 3, 4, 5];
537-
/// let b: Vec<_> = a.iter().cloned().collect();
538-
/// assert_eq!(a, b);
535+
/// let expected = [1, 2, 3, 4, 5];
536+
/// let actual: Vec<_> = expected.iter().cloned().collect();
537+
/// assert_eq!(actual, expected);
539538
/// ```
540539
#[inline]
541540
#[stable(feature = "rust1", since = "1.0.0")]
@@ -943,8 +942,8 @@ pub trait Iterator {
943942
/// # #![feature(core)]
944943
/// let a = [(1, 2), (3, 4)];
945944
/// let (left, right): (Vec<_>, Vec<_>) = a.iter().cloned().unzip();
946-
/// assert_eq!([1, 3], left);
947-
/// assert_eq!([2, 4], right);
945+
/// assert_eq!(left, [1, 3]);
946+
/// assert_eq!(right, [2, 4]);
948947
/// ```
949948
#[stable(feature = "rust1", since = "1.0.0")]
950949
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/librustc_typeck/coherence/orphan.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -215,25 +215,21 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
215215
match traits::orphan_check(self.tcx, def_id) {
216216
Ok(()) => { }
217217
Err(traits::OrphanCheckErr::NoLocalInputType) => {
218-
if !ty::has_attr(self.tcx, trait_def_id, "old_orphan_check") {
219-
span_err!(
220-
self.tcx.sess, item.span, E0117,
221-
"the impl does not reference any \
222-
types defined in this crate; \
223-
only traits defined in the current crate can be \
224-
implemented for arbitrary types");
225-
return;
226-
}
218+
span_err!(
219+
self.tcx.sess, item.span, E0117,
220+
"the impl does not reference any \
221+
types defined in this crate; \
222+
only traits defined in the current crate can be \
223+
implemented for arbitrary types");
224+
return;
227225
}
228226
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {
229-
if !ty::has_attr(self.tcx, trait_def_id, "old_orphan_check") {
230-
span_err!(self.tcx.sess, item.span, E0210,
231-
"type parameter `{}` must be used as the type parameter for \
232-
some local type (e.g. `MyStruct<T>`); only traits defined in \
233-
the current crate can be implemented for a type parameter",
234-
param_ty.user_string(self.tcx));
235-
return;
236-
}
227+
span_err!(self.tcx.sess, item.span, E0210,
228+
"type parameter `{}` must be used as the type parameter for \
229+
some local type (e.g. `MyStruct<T>`); only traits defined in \
230+
the current crate can be implemented for a type parameter",
231+
param_ty.user_string(self.tcx));
232+
return;
237233
}
238234
}
239235

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)