Don't have Vec<T> delegate to [T]'s bounds for indexing
This commit is contained in:
@@ -1527,23 +1527,27 @@ impl<T: Hash> Hash for Vec<T> {
|
|||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
|
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
|
||||||
impl<T, I> Index<I> for Vec<T> where [T]: Index<I> {
|
impl<T, I> Index<I> for Vec<T>
|
||||||
type Output = <[T] as Index<I>>::Output;
|
where
|
||||||
|
I: ::core::slice::SliceIndex<[T]>,
|
||||||
|
{
|
||||||
|
type Output = I::Output;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: I) -> &Self::Output {
|
fn index(&self, index: I) -> &Self::Output {
|
||||||
// NB indexing via implementation on slice
|
Index::index(&**self, index)
|
||||||
&(**self)[index]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
|
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
|
||||||
impl<T, I> IndexMut<I> for Vec<T> where [T]: IndexMut<I> {
|
impl<T, I> IndexMut<I> for Vec<T>
|
||||||
|
where
|
||||||
|
I: ::core::slice::SliceIndex<[T]>,
|
||||||
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: I) -> &mut Self::Output {
|
fn index_mut(&mut self, index: I) -> &mut Self::Output {
|
||||||
// NB indexing via implementation on slice
|
IndexMut::index_mut(&mut **self, index)
|
||||||
&mut (**self)[index]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ LL | x[0i32]; //~ ERROR E0277
|
|||||||
| ^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
| ^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||||
|
|
|
|
||||||
= help: the trait `std::slice::SliceIndex<[{integer}]>` is not implemented for `i32`
|
= help: the trait `std::slice::SliceIndex<[{integer}]>` is not implemented for `i32`
|
||||||
= note: required because of the requirements on the impl of `std::ops::Index<i32>` for `[{integer}]`
|
= note: required because of the requirements on the impl of `std::ops::Index<i32>` for `std::vec::Vec<{integer}>`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user