rust/tests/ui/iterators/rangefrom-overflow-debug.rs
Peter Jaszkowiak 0e5c96c3ec IterRangeFrom: overflow panic after yielding MAX
check overflow after yielding MAX value
new `0_u8..` will yield `255` and only panic on the subsequent `next()`
2025-11-15 21:29:59 -07:00

17 lines
350 B
Rust

//@ run-pass
//@ needs-unwind
//@ compile-flags: -O -C debug_assertions=yes
#![feature(new_range_api)]
use std::panic;
fn main() {
let mut it = core::range::RangeFrom::from(u8::MAX..).into_iter();
assert_eq!(it.next().unwrap(), 255);
let r = panic::catch_unwind(|| {
let _ = it.remainder();
});
assert!(r.is_err());
}