mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
085dff4944
stabilizes `core::range::RangeFrom` stabilizes `core::range::RangeFromIter` add examples for `remainder` method on range iterators `RangeFromIter::remainder` was not stabilized (see issue 154458)
36 lines
1.3 KiB
Rust
36 lines
1.3 KiB
Rust
// With -Coverflow-checks=yes (enabled by default by -Cdebug-assertions=yes) we will produce a
|
|
// runtime check that panics after yielding the maximum value of the range bound type. That is
|
|
// tested for by tests/ui/iterators/rangefrom-overflow-overflow-checks.rs
|
|
//
|
|
// This test ensures such runtime checks are optimized out when debug-assertions are
|
|
// enabled, but overflow-checks are explicitly disabled.
|
|
|
|
//@ revisions: DEBUG NOCHECKS
|
|
//@ compile-flags: -O -Cdebug-assertions=yes
|
|
//@ [NOCHECKS] compile-flags: -Coverflow-checks=no
|
|
|
|
#![crate_type = "lib"]
|
|
#![feature(new_range_api)]
|
|
|
|
use std::range::RangeFrom;
|
|
|
|
// CHECK-LABEL: @rangefrom_increments(
|
|
#[no_mangle]
|
|
pub unsafe fn rangefrom_increments(range: RangeFrom<i32>) -> RangeFrom<i32> {
|
|
// Iterator is contained entirely within this function, so the optimizer should
|
|
// be able to see that `exhausted` is never set and optimize out any branches.
|
|
|
|
// CHECK: i32 noundef %range
|
|
// DEBUG: switch i32 %range
|
|
// DEBUG: call core::panicking::panic_const::panic_const_add_overflow
|
|
// DEBUG: unreachable
|
|
// NOCHECKS-NOT: unreachable
|
|
// NOCHECKS: [[REM:%[a-z_0-9.]+]] = add i32 %range, 2
|
|
// NOCHECKS-NEXT: ret i32 [[REM]]
|
|
|
|
let mut iter = range.into_iter();
|
|
let _ = iter.next();
|
|
let _ = iter.next();
|
|
iter.remainder()
|
|
}
|