File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -662,7 +662,7 @@ impl<T> [T] {
662
662
// SAFETY: the caller must uphold most of the safety requirements for `get_unchecked`;
663
663
// the slice is dereferenceable because `self` is a safe reference.
664
664
// The returned pointer is safe because impls of `SliceIndex` have to guarantee that it is.
665
- unsafe { & * index. get_unchecked ( self ) }
665
+ unsafe { & * index. get ( self ) . unwrap_unchecked ( ) }
666
666
}
667
667
668
668
/// Returns a mutable reference to an element or subslice, without doing
Original file line number Diff line number Diff line change
1
+ // no-system-llvm
2
+ // compile-flags: -O
3
+ // ignore-debug: the debug assertions get in the way
4
+ #![ crate_type = "lib" ]
5
+
6
+ /// Make sure no bounds checks are emitted after a `get_unchecked`.
7
+ // CHECK-LABEL: @unchecked_slice_no_bounds_check
8
+ #[ no_mangle]
9
+ pub unsafe fn unchecked_slice_no_bounds_check ( s : & [ u8 ] ) -> u8 {
10
+ let a = * s. get_unchecked ( 1 ) ;
11
+ // CHECK-NOT: panic_bounds_check
12
+ a + s[ 0 ]
13
+ }
You can’t perform that action at this time.
0 commit comments