]> git.lizzy.rs Git - rust.git/commitdiff
Don't have Vec<T> delegate to [T]'s bounds for indexing
authorJonathan Behrens <fintelia@gmail.com>
Sat, 3 Mar 2018 04:23:00 +0000 (23:23 -0500)
committerJonathan Behrens <fintelia@gmail.com>
Sat, 3 Mar 2018 04:25:52 +0000 (23:25 -0500)
src/liballoc/vec.rs
src/test/ui/index-help.stderr

index 83538e5acd4c1e963a2375cb9d92465358a900c9..feed7c8699a3ebf0cbb8a4822bf91fa2bb209697 100644 (file)
@@ -1527,23 +1527,27 @@ fn hash<H: hash::Hasher>(&self, state: &mut H) {
 
 #[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)
     }
 }
 
index 1b5d28d5bb1b17a17c040b4776bb8e283a13796c..ae3cd529ac42e499454f1909ed0fb1c34f79838b 100644 (file)
@@ -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