mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-03 02:40:40 +00:00

Consolidate all the panicking functions in `slice/index.rs` to use a single `slice_index_fail` function, similar to how it is done in `str/traits.rs`.
19 lines
423 B
Rust
19 lines
423 B
Rust
// in Rust 1.73, -O and opt-level=3 optimizes differently
|
|
//@ compile-flags: -C opt-level=3
|
|
#![crate_type = "lib"]
|
|
|
|
use std::cmp::max;
|
|
|
|
// CHECK-LABEL: @foo
|
|
// CHECK-NOT: slice_index_fail
|
|
// CHECK-NOT: unreachable
|
|
#[no_mangle]
|
|
pub fn foo(v: &mut Vec<u8>, size: usize) -> Option<&mut [u8]> {
|
|
if v.len() > max(1, size) {
|
|
let start = v.len() - size;
|
|
Some(&mut v[start..])
|
|
} else {
|
|
None
|
|
}
|
|
}
|