@@ -658,7 +658,6 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeFull {
658658}
659659
660660/// The methods `index` and `index_mut` panic if:
661- /// - the end of the range is `usize::MAX` or
662661/// - the start of the range is greater than the end of the range or
663662/// - the end of the range is out of bounds.
664663#[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
@@ -668,12 +667,12 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeInclusive<usize> {
668667
669668 #[ inline]
670669 fn get ( self , slice : & [ T ] ) -> Option < & [ T ] > {
671- if * self . end ( ) == usize :: MAX { None } else { self . into_slice_range ( ) . get ( slice) }
670+ if * self . end ( ) >= slice . len ( ) { None } else { self . into_slice_range ( ) . get ( slice) }
672671 }
673672
674673 #[ inline]
675674 fn get_mut ( self , slice : & mut [ T ] ) -> Option < & mut [ T ] > {
676- if * self . end ( ) == usize :: MAX { None } else { self . into_slice_range ( ) . get_mut ( slice) }
675+ if * self . end ( ) >= slice . len ( ) { None } else { self . into_slice_range ( ) . get_mut ( slice) }
677676 }
678677
679678 #[ inline]
@@ -697,7 +696,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeInclusive<usize> {
697696 start = if exhausted { end } else { start } ;
698697 if let Some ( new_len) = usize:: checked_sub ( end, start) {
699698 // SAFETY: `self` is checked to be valid and in bounds above.
700- unsafe { return & * get_offset_len_noubcheck ( slice, start, new_len) }
699+ unsafe { return & * get_offset_len_noubcheck ( slice, start, new_len) } ;
701700 }
702701 }
703702 slice_index_fail ( start, end, slice. len ( ) )
@@ -712,7 +711,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeInclusive<usize> {
712711 start = if exhausted { end } else { start } ;
713712 if let Some ( new_len) = usize:: checked_sub ( end, start) {
714713 // SAFETY: `self` is checked to be valid and in bounds above.
715- unsafe { return & mut * get_offset_len_mut_noubcheck ( slice, start, new_len) }
714+ unsafe { return & mut * get_offset_len_mut_noubcheck ( slice, start, new_len) } ;
716715 }
717716 }
718717 slice_index_fail ( start, end, slice. len ( ) )
0 commit comments