]> git.lizzy.rs Git - rust.git/blob - tests/codegen/slice-position-bounds-check.rs
Rollup merge of #106625 - Swatinem:ref/cov6, r=nagisa
[rust.git] / tests / codegen / slice-position-bounds-check.rs
1 // no-system-llvm
2 // compile-flags: -O -C panic=abort
3 #![crate_type = "lib"]
4
5 fn search<T: Ord + Eq>(arr: &mut [T], a: &T) -> Result<usize, ()> {
6     match arr.iter().position(|x| x == a) {
7         Some(p) => {
8             Ok(p)
9         },
10         None => Err(()),
11     }
12 }
13
14 // CHECK-LABEL: @position_no_bounds_check
15 #[no_mangle]
16 pub fn position_no_bounds_check(y: &mut [u32], x: &u32, z: &u32) -> bool {
17     // This contains "call assume" so we cannot just rule out all calls
18     // CHECK-NOT: panic_bounds_check
19     if let Ok(p) = search(y, x) {
20       y[p] == *z
21     } else {
22       false
23     }
24 }
25
26 // just to make sure that panicking really emits "panic_bounds_check" somewhere in the IR
27 // CHECK-LABEL: @test_check
28 #[no_mangle]
29 pub fn test_check(y: &[i32]) -> i32 {
30     // CHECK: panic_bounds_check
31     y[12]
32 }