summaryrefslogtreecommitdiffstats
path: root/tests/ui/numbers-arithmetic
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/numbers-arithmetic')
-rw-r--r--tests/ui/numbers-arithmetic/overflow-attribute-works-1.rs19
-rw-r--r--tests/ui/numbers-arithmetic/overflow-attribute-works-2.rs19
-rw-r--r--tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs12
-rw-r--r--tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs2
4 files changed, 51 insertions, 1 deletions
diff --git a/tests/ui/numbers-arithmetic/overflow-attribute-works-1.rs b/tests/ui/numbers-arithmetic/overflow-attribute-works-1.rs
new file mode 100644
index 000000000..318be2a64
--- /dev/null
+++ b/tests/ui/numbers-arithmetic/overflow-attribute-works-1.rs
@@ -0,0 +1,19 @@
+// run-pass
+// compile-flags: -C overflow_checks=true
+
+#![feature(cfg_overflow_checks)]
+
+fn main() {
+ assert!(cfg!(overflow_checks));
+ assert!(compiles_differently());
+}
+
+#[cfg(overflow_checks)]
+fn compiles_differently()->bool {
+ true
+}
+
+#[cfg(not(overflow_checks))]
+fn compiles_differently()->bool {
+ false
+}
diff --git a/tests/ui/numbers-arithmetic/overflow-attribute-works-2.rs b/tests/ui/numbers-arithmetic/overflow-attribute-works-2.rs
new file mode 100644
index 000000000..0367d980a
--- /dev/null
+++ b/tests/ui/numbers-arithmetic/overflow-attribute-works-2.rs
@@ -0,0 +1,19 @@
+// run-pass
+// compile-flags: -C overflow_checks=false
+
+#![feature(cfg_overflow_checks)]
+
+fn main() {
+ assert!(!cfg!(overflow_checks));
+ assert!(!compiles_differently());
+}
+
+#[cfg(overflow_checks)]
+fn compiles_differently()->bool {
+ true
+}
+
+#[cfg(not(overflow_checks))]
+fn compiles_differently()->bool {
+ false
+}
diff --git a/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs b/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs
new file mode 100644
index 000000000..565b7e86f
--- /dev/null
+++ b/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs
@@ -0,0 +1,12 @@
+// run-fail
+// error-pattern:thread 'main' panicked at 'attempt to negate with overflow'
+// ignore-emscripten no processes
+// compile-flags: -C debug-assertions
+
+#![allow(arithmetic_overflow)]
+
+use std::num::NonZeroI8;
+
+fn main() {
+ let _x = -NonZeroI8::new(i8::MIN).unwrap();
+}
diff --git a/tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs b/tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs
index 4c6929d66..088b2fcdd 100644
--- a/tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs
+++ b/tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs
@@ -1,4 +1,4 @@
-// ignore-test
+// ignore-test (auxiliary, used by other tests)
// Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction.
//