Skip to content

Commit 11217da

Browse files
committed
Auto merge of rust-lang#116915 - bend-n:unwet, r=saethlin
Add an assume that the index is inbounds to slice::get_unchecked Fixes rust-lang#116878
2 parents 0456f56 + 5547e8d commit 11217da

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)