mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 12:36:35 +03:00
0e5c96c3ec
check overflow after yielding MAX value new `0_u8..` will yield `255` and only panic on the subsequent `next()`
28 lines
1.1 KiB
Rust
28 lines
1.1 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 that such a runtime check is *not* emitted 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::{IterRangeFrom, RangeFrom};
|
|
|
|
// CHECK-LABEL: @iterrangefrom_remainder(
|
|
#[no_mangle]
|
|
pub unsafe fn iterrangefrom_remainder(x: IterRangeFrom<i32>) -> RangeFrom<i32> {
|
|
// DEBUG: i32 noundef %x
|
|
// NOCHECKS: i32 noundef returned %x
|
|
// DEBUG: br i1
|
|
// DEBUG: call core::panicking::panic_const::panic_const_add_overflow
|
|
// DEBUG: unreachable
|
|
// NOCHECKS-NOT: unreachable
|
|
// NOCHECKS: ret i32 %x
|
|
x.remainder()
|
|
}
|