We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f43c022 commit c9d04c2Copy full SHA for c9d04c2
src/test/codegen/binary-search-index-no-bound-check.rs
@@ -0,0 +1,19 @@
1
+// min-llvm-version: 11.0.0
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 when slicing or indexing
7
+// with an index from `binary_search`.
8
9
+// CHECK-LABEL: @binary_search_index_no_bounds_check
10
+#[no_mangle]
11
+pub fn binary_search_index_no_bounds_check(s: &[u8]) -> u8 {
12
+ // CHECK-NOT: panic
13
+ // CHECK-NOT: slice_index_len_fail
14
+ if let Ok(idx) = s.binary_search(&b'\\') {
15
+ s[idx]
16
+ } else {
17
+ 42
18
+ }
19
+}
0 commit comments