about summary refs log tree commit diff
path: root/src/test/run-pass/iter-sum-overflow-overflow-checks.rs
diff options
context:
space:
mode:
authorNathan Froyd <froydnj@gmail.com>2017-02-17 16:00:08 -0500
committerNathan Froyd <froydnj@gmail.com>2017-02-22 10:08:57 -0500
commitffc6ddd51b960469ffee8d2fb80d5a664e2a6c21 (patch)
treeb4e0227d64b599ffddd14542c53791e654ba7873 /src/test/run-pass/iter-sum-overflow-overflow-checks.rs
parentfc6f092c21a7a7249a9f8860f3cd10160aa36c02 (diff)
downloadrust-ffc6ddd51b960469ffee8d2fb80d5a664e2a6c21.tar.gz
rust-ffc6ddd51b960469ffee8d2fb80d5a664e2a6c21.zip
add `-C overflow-checks` option
In addition to defining and handling the new option, we also add a
method on librustc::Session for determining the necessity of overflow
checks.  This method provides a single point to sort out the three (!)
different ways for turning on overflow checks: -C debug-assertions, -C
overflow-checks, and -Z force-overflow-checks.

Fixes #33134.
Diffstat (limited to 'src/test/run-pass/iter-sum-overflow-overflow-checks.rs')
-rw-r--r--src/test/run-pass/iter-sum-overflow-overflow-checks.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/run-pass/iter-sum-overflow-overflow-checks.rs b/src/test/run-pass/iter-sum-overflow-overflow-checks.rs
new file mode 100644
index 00000000000..a3a7179fb71
--- /dev/null
+++ b/src/test/run-pass/iter-sum-overflow-overflow-checks.rs
@@ -0,0 +1,35 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// 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());
+}