Skip to content

Commit 370df40

Browse files
committed
Don't have Vec<T> delegate to [T]'s bounds for indexing
1 parent ae73a21 commit 370df40

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/liballoc/vec.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1527,23 +1527,27 @@ impl<T: Hash> Hash for Vec<T> {
15271527

15281528
#[stable(feature = "rust1", since = "1.0.0")]
15291529
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
1530-
impl<T, I> Index<I> for Vec<T> where [T]: Index<I> {
1531-
type Output = <[T] as Index<I>>::Output;
1530+
impl<T, I> Index<I> for Vec<T>
1531+
where
1532+
I: ::core::slice::SliceIndex<[T]>,
1533+
{
1534+
type Output = I::Output;
15321535

15331536
#[inline]
15341537
fn index(&self, index: I) -> &Self::Output {
1535-
// NB indexing via implementation on slice
1536-
&(**self)[index]
1538+
Index::index(&**self, index)
15371539
}
15381540
}
15391541

15401542
#[stable(feature = "rust1", since = "1.0.0")]
15411543
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
1542-
impl<T, I> IndexMut<I> for Vec<T> where [T]: IndexMut<I> {
1544+
impl<T, I> IndexMut<I> for Vec<T>
1545+
where
1546+
I: ::core::slice::SliceIndex<[T]>,
1547+
{
15431548
#[inline]
15441549
fn index_mut(&mut self, index: I) -> &mut Self::Output {
1545-
// NB indexing via implementation on slice
1546-
&mut (**self)[index]
1550+
IndexMut::index_mut(&mut **self, index)
15471551
}
15481552
}
15491553

src/test/ui/index-help.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | x[0i32]; //~ ERROR E0277
55
| ^^^^^^^ slice indices are of type `usize` or ranges of `usize`
66
|
77
= help: the trait `std::slice::SliceIndex<[{integer}]>` is not implemented for `i32`
8-
= note: required because of the requirements on the impl of `std::ops::Index<i32>` for `[{integer}]`
8+
= note: required because of the requirements on the impl of `std::ops::Index<i32>` for `std::vec::Vec<{integer}>`
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)