]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/binary-search-index-no-bound-check.rs
Auto merge of #99612 - yanchen4791:issue-95079-fix, r=compiler-errors
[rust.git] / src / test / codegen / binary-search-index-no-bound-check.rs
1 // compile-flags: -O
2 // ignore-debug: the debug assertions get in the way
3 #![crate_type = "lib"]
4
5 // Make sure no bounds checks are emitted when slicing or indexing
6 // with an index from `binary_search`.
7
8 // CHECK-LABEL: @binary_search_index_no_bounds_check
9 #[no_mangle]
10 pub fn binary_search_index_no_bounds_check(s: &[u8]) -> u8 {
11     // CHECK-NOT: panic
12     // CHECK-NOT: slice_index_len_fail
13     if let Ok(idx) = s.binary_search(&b'\\') {
14         s[idx]
15     } else {
16         42
17     }
18 }