Skip to content

Commit 8b57f68

Browse files
committed
Use const generics for some Vec/CCow impls.
1 parent c798dff commit 8b57f68

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

Diff for: src/liballoc/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
#![feature(cfg_target_has_atomic)]
7979
#![feature(coerce_unsized)]
8080
#![cfg_attr(not(bootstrap), feature(const_in_array_repeat_expressions))]
81+
#![feature(const_generic_impls_guard)]
82+
#![feature(const_generics)]
8183
#![feature(dispatch_from_dyn)]
8284
#![feature(core_intrinsics)]
8385
#![feature(dropck_eyepatch)]

Diff for: src/liballoc/vec.rs

+23-33
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
5757
#![stable(feature = "rust1", since = "1.0.0")]
5858

59+
use core::array::LengthAtMost32;
5960
use core::cmp::{self, Ordering};
6061
use core::fmt;
6162
use core::hash::{self, Hash};
@@ -2171,47 +2172,36 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
21712172
}
21722173

21732174
macro_rules! __impl_slice_eq1 {
2174-
($Lhs: ty, $Rhs: ty) => {
2175-
__impl_slice_eq1! { $Lhs, $Rhs, Sized }
2176-
};
2177-
($Lhs: ty, $Rhs: ty, $Bound: ident) => {
2175+
([$($vars:tt)*] $lhs:ty, $rhs:ty, $($constraints:tt)*) => {
21782176
#[stable(feature = "rust1", since = "1.0.0")]
2179-
impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> {
2177+
impl<A, B, $($vars)*> PartialEq<$rhs> for $lhs
2178+
where
2179+
A: PartialEq<B>,
2180+
$($constraints)*
2181+
{
21802182
#[inline]
2181-
fn eq(&self, other: &$Rhs) -> bool { self[..] == other[..] }
2183+
fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] }
21822184
#[inline]
2183-
fn ne(&self, other: &$Rhs) -> bool { self[..] != other[..] }
2185+
fn ne(&self, other: &$rhs) -> bool { self[..] != other[..] }
21842186
}
21852187
}
21862188
}
21872189

2188-
__impl_slice_eq1! { Vec<A>, Vec<B> }
2189-
__impl_slice_eq1! { Vec<A>, &'b [B] }
2190-
__impl_slice_eq1! { Vec<A>, &'b mut [B] }
2191-
__impl_slice_eq1! { Cow<'a, [A]>, &'b [B], Clone }
2192-
__impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B], Clone }
2193-
__impl_slice_eq1! { Cow<'a, [A]>, Vec<B>, Clone }
2190+
__impl_slice_eq1! { [] Vec<A>, Vec<B>, }
2191+
__impl_slice_eq1! { [] Vec<A>, &[B], }
2192+
__impl_slice_eq1! { [] Vec<A>, &mut [B], }
2193+
__impl_slice_eq1! { [] Cow<'_, [A]>, &[B], A: Clone }
2194+
__impl_slice_eq1! { [] Cow<'_, [A]>, &mut [B], A: Clone }
2195+
__impl_slice_eq1! { [] Cow<'_, [A]>, Vec<B>, A: Clone }
2196+
__impl_slice_eq1! { [const N: usize] Vec<A>, [B; N], [B; N]: LengthAtMost32 }
2197+
__impl_slice_eq1! { [const N: usize] Vec<A>, &[B; N], [B; N]: LengthAtMost32 }
21942198

2195-
macro_rules! array_impls {
2196-
($($N: expr)+) => {
2197-
$(
2198-
// NOTE: some less important impls are omitted to reduce code bloat
2199-
__impl_slice_eq1! { Vec<A>, [B; $N] }
2200-
__impl_slice_eq1! { Vec<A>, &'b [B; $N] }
2201-
// __impl_slice_eq1! { Vec<A>, &'b mut [B; $N] }
2202-
// __impl_slice_eq1! { Cow<'a, [A]>, [B; $N], Clone }
2203-
// __impl_slice_eq1! { Cow<'a, [A]>, &'b [B; $N], Clone }
2204-
// __impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B; $N], Clone }
2205-
)+
2206-
}
2207-
}
2208-
2209-
array_impls! {
2210-
0 1 2 3 4 5 6 7 8 9
2211-
10 11 12 13 14 15 16 17 18 19
2212-
20 21 22 23 24 25 26 27 28 29
2213-
30 31 32
2214-
}
2199+
// NOTE: some less important impls are omitted to reduce code bloat
2200+
// FIXME(Centril): Reconsider this?
2201+
//__impl_slice_eq1! { [const N: usize] Vec<A>, &mut [B; N], [B; N]: LengthAtMost32 }
2202+
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], [B; N]: LengthAtMost32 }
2203+
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], [B; N]: LengthAtMost32 }
2204+
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], [B; N]: LengthAtMost32 }
22152205

22162206
/// Implements comparison of vectors, lexicographically.
22172207
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)