mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-04 17:22:19 +00:00
45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
// `0..slice.len()` should propagate the same upper bound as
|
|
// `slice.iter().enumerate()`, allowing the checked index conversion to be
|
|
// removed inside the loop.
|
|
|
|
//@ compile-flags: -Copt-level=3
|
|
//@ only-64bit
|
|
//@ ignore-s390x OPT missing on s390x https://github.com/llvm/llvm-project/issues/208712
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
use std::convert::TryFrom;
|
|
use std::hint::black_box;
|
|
|
|
// CHECK-LABEL: @score_round_enumerate
|
|
#[no_mangle]
|
|
pub fn score_round_enumerate(candidates: &[bool]) {
|
|
// The length check itself can still fail.
|
|
// CHECK: tail call {{.*}}unwrap_failed
|
|
// But the checked conversion inside the loop should not add another panic path.
|
|
// CHECK-NOT: tail call {{.*}}unwrap_failed
|
|
// CHECK: ret void
|
|
u32::try_from(candidates.len()).unwrap();
|
|
|
|
for (i, _) in candidates.iter().enumerate() {
|
|
u32::try_from(i).unwrap();
|
|
black_box(42);
|
|
}
|
|
}
|
|
|
|
// CHECK-LABEL: @score_round_range
|
|
#[no_mangle]
|
|
pub fn score_round_range(candidates: &[bool]) {
|
|
// The length check itself can still fail.
|
|
// CHECK: tail call {{.*}}unwrap_failed
|
|
// But the checked conversion inside the loop should not add another panic path.
|
|
// CHECK-NOT: tail call {{.*}}unwrap_failed
|
|
// CHECK: ret void
|
|
u32::try_from(candidates.len()).unwrap();
|
|
|
|
for i in 0..candidates.len() {
|
|
u32::try_from(i).unwrap();
|
|
black_box(42);
|
|
}
|
|
}
|