mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
72800d3b89
Except for `simd-intrinsic/`, which has a lot of files containing multiple types like `u8x64` which really are better when hand-formatted. There is a surprising amount of two-space indenting in this directory. Non-trivial changes: - `rustfmt::skip` needed in `debug-column.rs` to preserve meaning of the test. - `rustfmt::skip` used in a few places where hand-formatting read more nicely: `enum/enum-match.rs` - Line number adjustments needed for the expected output of `debug-column.rs` and `coroutine-debug.rs`.
36 lines
1.1 KiB
Rust
36 lines
1.1 KiB
Rust
//@ compile-flags: -O
|
|
#![crate_type = "lib"]
|
|
|
|
// Make sure no bounds checks are emitted when slicing or indexing
|
|
// with an index from `binary_search`.
|
|
|
|
// CHECK-LABEL: @binary_search_index_no_bounds_check
|
|
#[no_mangle]
|
|
pub fn binary_search_index_no_bounds_check(s: &[u8]) -> u8 {
|
|
// CHECK-NOT: panic
|
|
// CHECK-NOT: slice_start_index_len_fail
|
|
// CHECK-NOT: slice_end_index_len_fail
|
|
// CHECK-NOT: panic_bounds_check
|
|
if let Ok(idx) = s.binary_search(&b'\\') { s[idx] } else { 42 }
|
|
}
|
|
|
|
// Similarly, check that `partition_point` is known to return a valid fencepost.
|
|
|
|
// CHECK-LABEL: @unknown_split
|
|
#[no_mangle]
|
|
pub fn unknown_split(x: &[i32], i: usize) -> (&[i32], &[i32]) {
|
|
// This just makes sure that the subsequent function is looking for the
|
|
// absence of something that might actually be there.
|
|
|
|
// CHECK: call core::panicking::panic
|
|
x.split_at(i)
|
|
}
|
|
|
|
// CHECK-LABEL: @partition_point_split_no_bounds_check
|
|
#[no_mangle]
|
|
pub fn partition_point_split_no_bounds_check(x: &[i32], needle: i32) -> (&[i32], &[i32]) {
|
|
// CHECK-NOT: call core::panicking::panic
|
|
let i = x.partition_point(|p| p < &needle);
|
|
x.split_at(i)
|
|
}
|