diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 20b2c3d3c96..52babaf9f72 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -3241,12 +3241,18 @@ unsafe impl SliceIndex<[T]> for ops::RangeFrom { #[inline] fn index(self, slice: &[T]) -> &[T] { - (self.start..slice.len()).index(slice) + if self.start > slice.len() { + slice_index_len_fail(self.start, slice.len()); + } + unsafe { &*self.get_unchecked(slice) } } #[inline] fn index_mut(self, slice: &mut [T]) -> &mut [T] { - (self.start..slice.len()).index_mut(slice) + if self.start > slice.len() { + slice_index_len_fail(self.start, slice.len()); + } + unsafe { &mut *self.get_unchecked_mut(slice) } } } diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index fba73be92be..8e240832c13 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -1088,7 +1088,7 @@ mod slice_index { good: data[6..] == []; bad: data[7..]; - message: "but ends at"; // perhaps not ideal + message: "out of range"; } in mod rangeto_len {