diff options
| author | Jonathan Behrens <fintelia@gmail.com> | 2018-03-02 23:23:00 -0500 |
|---|---|---|
| committer | Jonathan Behrens <fintelia@gmail.com> | 2018-03-02 23:25:52 -0500 |
| commit | 370df40dab8df9f3c0b10bb7396225b8d24869b3 (patch) | |
| tree | e124a618b0938099723894b23325eb1bbf1e8c87 | |
| parent | ae73a210814bdf50d72a95568eb8c9c96772c641 (diff) | |
| download | rust-370df40dab8df9f3c0b10bb7396225b8d24869b3.tar.gz rust-370df40dab8df9f3c0b10bb7396225b8d24869b3.zip | |
Don't have Vec<T> delegate to [T]'s bounds for indexing
| -rw-r--r-- | src/liballoc/vec.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/index-help.stderr | 2 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 83538e5acd4..feed7c8699a 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1527,23 +1527,27 @@ impl<T: Hash> Hash for Vec<T> { #[stable(feature = "rust1", since = "1.0.0")] #[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> { - type Output = <[T] as Index<I>>::Output; +impl<T, I> Index<I> for Vec<T> +where + I: ::core::slice::SliceIndex<[T]>, +{ + type Output = I::Output; #[inline] fn index(&self, index: I) -> &Self::Output { - // NB indexing via implementation on slice - &(**self)[index] + Index::index(&**self, index) } } #[stable(feature = "rust1", since = "1.0.0")] #[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] fn index_mut(&mut self, index: I) -> &mut Self::Output { - // NB indexing via implementation on slice - &mut (**self)[index] + IndexMut::index_mut(&mut **self, index) } } diff --git a/src/test/ui/index-help.stderr b/src/test/ui/index-help.stderr index 1b5d28d5bb1..ae3cd529ac4 100644 --- a/src/test/ui/index-help.stderr +++ b/src/test/ui/index-help.stderr @@ -5,7 +5,7 @@ LL | x[0i32]; //~ ERROR E0277 | ^^^^^^^ slice indices are of type `usize` or ranges of `usize` | = 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 |
