You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #22320 - petrochenkov:eq, r=alexcrichton
All types that are "slices in disguise" - `[T]`, `[T; N]`, `Vec<T>` etc and sometimes references to them (see #21725) should be equality comparable to each other.
Many of them are already comparable, but some are not and this PR patches the holes in the impls of `PartialEq` for slice-like entities.
Ideally, the problem could be solved by an impl roughly looking like
```
impl<T, U, A, B> PartialEq<U> for T where T: BorrowSlice<A>,
U: BorrowSlice<B>,
A: PartialEq<B> {
fn eq(&self, other: &U) -> bool { self.borrow_slice() == other.borrow_slice() }
fn ne(&self, other: &U) -> bool { self.borrow_slice() != other.borrow_slice() }
}
```
, but the type system would never allow such a simple and obvious solution.
Therefore, the patch follows this approach, but implements it with macros and not generics.
The applied changes are conservative, in particular, the smart pointers aren't touched at all.
But the comparisons for `Box<[T]>`, `Rc<[T]>` and `Arc<[T]>` seem trivial to add. (Should I do it?)
This PR partially address #21725
Technically this is a [breaking-change], because the impls for fixed-size arrays are more conservative now.
Note: There are blanket impls of `PartialEq` in libcore/cmp.rs (see https://github.com/rust-lang/rust/blob/master/src/libcore/cmp.rs#L432 and below), they strip an *equal* number of references from both operands and then compare the remains. It would be much better to strip *all* the references before the comparison in the blanket impls to reduce the number of concrete impls, but I haven't found a way to do it without specialization/negative bounds.
r? @aturon
cc @gankro
0 commit comments