about summary refs log tree commit diff
path: root/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs
blob: 429f8e0bc9648a61aeecc631e91202fce4770891 (plain)
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
// run-pass
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C overflow-checks

use std::panic;

fn main() {
    let r = panic::catch_unwind(|| {
        [1, i32::max_value()].iter().sum::<i32>();
    });
    assert!(r.is_err());

    let r = panic::catch_unwind(|| {
        [2, i32::max_value()].iter().product::<i32>();
    });
    assert!(r.is_err());

    let r = panic::catch_unwind(|| {
        [1, i32::max_value()].iter().cloned().sum::<i32>();
    });
    assert!(r.is_err());

    let r = panic::catch_unwind(|| {
        [2, i32::max_value()].iter().cloned().product::<i32>();
    });
    assert!(r.is_err());
}