forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrangefrom-overflow-overflow-checks.rs
More file actions
48 lines (36 loc) · 1.15 KB
/
Copy pathrangefrom-overflow-overflow-checks.rs
File metadata and controls
48 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//@ run-pass
//@ needs-unwind
//@ compile-flags: -O -C overflow-checks=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(move || {
let _ = it.remainder();
});
assert!(r.is_err());
let mut it = core::range::RangeFrom::from(u8::MAX..).into_iter();
assert_eq!(it.next().unwrap(), 255);
let r = panic::catch_unwind(move || {
let _ = it.next();
});
assert!(r.is_err());
let mut it = core::range::RangeFrom::from(u8::MAX..).into_iter();
assert_eq!(it.next().unwrap(), 255);
let r = panic::catch_unwind(move || {
let _ = it.nth(0);
});
assert!(r.is_err());
let mut it = core::range::RangeFrom::from(u8::MAX-1..).into_iter();
assert_eq!(it.nth(1).unwrap(), 255);
let r = panic::catch_unwind(move || {
let _ = it.next();
});
assert!(r.is_err());
let mut it = core::range::RangeFrom::from(u8::MAX-1..).into_iter();
let r = panic::catch_unwind(move || {
let _ = it.nth(2);
});
assert!(r.is_err());
}