Use const generics for some Vec/CCow impls.
This commit is contained in:
parent
c798dffac9
commit
8b57f689d5
2 changed files with 25 additions and 33 deletions
|
@ -78,6 +78,8 @@
|
||||||
#![feature(cfg_target_has_atomic)]
|
#![feature(cfg_target_has_atomic)]
|
||||||
#![feature(coerce_unsized)]
|
#![feature(coerce_unsized)]
|
||||||
#![cfg_attr(not(bootstrap), feature(const_in_array_repeat_expressions))]
|
#![cfg_attr(not(bootstrap), feature(const_in_array_repeat_expressions))]
|
||||||
|
#![feature(const_generic_impls_guard)]
|
||||||
|
#![feature(const_generics)]
|
||||||
#![feature(dispatch_from_dyn)]
|
#![feature(dispatch_from_dyn)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(dropck_eyepatch)]
|
#![feature(dropck_eyepatch)]
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
|
use core::array::LengthAtMost32;
|
||||||
use core::cmp::{self, Ordering};
|
use core::cmp::{self, Ordering};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::hash::{self, Hash};
|
use core::hash::{self, Hash};
|
||||||
|
@ -2171,47 +2172,36 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! __impl_slice_eq1 {
|
macro_rules! __impl_slice_eq1 {
|
||||||
($Lhs: ty, $Rhs: ty) => {
|
([$($vars:tt)*] $lhs:ty, $rhs:ty, $($constraints:tt)*) => {
|
||||||
__impl_slice_eq1! { $Lhs, $Rhs, Sized }
|
|
||||||
};
|
|
||||||
($Lhs: ty, $Rhs: ty, $Bound: ident) => {
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> {
|
impl<A, B, $($vars)*> PartialEq<$rhs> for $lhs
|
||||||
|
where
|
||||||
|
A: PartialEq<B>,
|
||||||
|
$($constraints)*
|
||||||
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &$Rhs) -> bool { self[..] == other[..] }
|
fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] }
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ne(&self, other: &$Rhs) -> bool { self[..] != other[..] }
|
fn ne(&self, other: &$rhs) -> bool { self[..] != other[..] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__impl_slice_eq1! { Vec<A>, Vec<B> }
|
__impl_slice_eq1! { [] Vec<A>, Vec<B>, }
|
||||||
__impl_slice_eq1! { Vec<A>, &'b [B] }
|
__impl_slice_eq1! { [] Vec<A>, &[B], }
|
||||||
__impl_slice_eq1! { Vec<A>, &'b mut [B] }
|
__impl_slice_eq1! { [] Vec<A>, &mut [B], }
|
||||||
__impl_slice_eq1! { Cow<'a, [A]>, &'b [B], Clone }
|
__impl_slice_eq1! { [] Cow<'_, [A]>, &[B], A: Clone }
|
||||||
__impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B], Clone }
|
__impl_slice_eq1! { [] Cow<'_, [A]>, &mut [B], A: Clone }
|
||||||
__impl_slice_eq1! { Cow<'a, [A]>, Vec<B>, Clone }
|
__impl_slice_eq1! { [] Cow<'_, [A]>, Vec<B>, A: Clone }
|
||||||
|
__impl_slice_eq1! { [const N: usize] Vec<A>, [B; N], [B; N]: LengthAtMost32 }
|
||||||
|
__impl_slice_eq1! { [const N: usize] Vec<A>, &[B; N], [B; N]: LengthAtMost32 }
|
||||||
|
|
||||||
macro_rules! array_impls {
|
// NOTE: some less important impls are omitted to reduce code bloat
|
||||||
($($N: expr)+) => {
|
// FIXME(Centril): Reconsider this?
|
||||||
$(
|
//__impl_slice_eq1! { [const N: usize] Vec<A>, &mut [B; N], [B; N]: LengthAtMost32 }
|
||||||
// NOTE: some less important impls are omitted to reduce code bloat
|
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], [B; N]: LengthAtMost32 }
|
||||||
__impl_slice_eq1! { Vec<A>, [B; $N] }
|
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], [B; N]: LengthAtMost32 }
|
||||||
__impl_slice_eq1! { Vec<A>, &'b [B; $N] }
|
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], [B; N]: LengthAtMost32 }
|
||||||
// __impl_slice_eq1! { Vec<A>, &'b mut [B; $N] }
|
|
||||||
// __impl_slice_eq1! { Cow<'a, [A]>, [B; $N], Clone }
|
|
||||||
// __impl_slice_eq1! { Cow<'a, [A]>, &'b [B; $N], Clone }
|
|
||||||
// __impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B; $N], Clone }
|
|
||||||
)+
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
array_impls! {
|
|
||||||
0 1 2 3 4 5 6 7 8 9
|
|
||||||
10 11 12 13 14 15 16 17 18 19
|
|
||||||
20 21 22 23 24 25 26 27 28 29
|
|
||||||
30 31 32
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implements comparison of vectors, lexicographically.
|
/// Implements comparison of vectors, lexicographically.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue