Skip to content

Commit 0cb2767

Browse files
committed
use assume(idx < self.len()) in [T]::get_unchecked
1 parent 341abd1 commit 0cb2767

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

core/src/slice/index.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ unsafe impl<T> SliceIndex<[T]> for usize {
233233
// cannot be longer than `isize::MAX`. They also guarantee that
234234
// `self` is in bounds of `slice` so `self` cannot overflow an `isize`,
235235
// so the call to `add` is safe.
236-
unsafe { slice.as_ptr().add(self) }
236+
unsafe {
237+
crate::intrinsics::assume(self < slice.len());
238+
slice.as_ptr().add(self)
239+
}
237240
}
238241

239242
#[inline]

0 commit comments

Comments
 (0)