]> git.lizzy.rs Git - rust.git/commitdiff
add tests for invalid float-to-int casts
authorRalf Jung <post@ralfj.de>
Sun, 12 Apr 2020 10:01:07 +0000 (12:01 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 12 Apr 2020 10:01:20 +0000 (12:01 +0200)
21 files changed:
tests/compile-fail/intrinsics/float_to_int_32_inf1.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_32_infneg1.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_32_nan.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_32_nanneg.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_32_neg.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_32_too_big1.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_32_too_big2.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_32_too_small1.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_inf1.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_infneg1.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_infneg2.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_nan.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_neg.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_too_big1.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_too_big2.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_too_big3.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_too_big4.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_too_big5.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_too_small1.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_too_small2.rs [new file with mode: 0644]
tests/compile-fail/intrinsics/float_to_int_64_too_small3.rs [new file with mode: 0644]

diff --git a/tests/compile-fail/intrinsics/float_to_int_32_inf1.rs b/tests/compile-fail/intrinsics/float_to_int_32_inf1.rs
new file mode 100644 (file)
index 0000000..a56f4ae
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f32, i32>(f32::INFINITY); } //~ ERROR: cannot be represented in target type `i32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_32_infneg1.rs b/tests/compile-fail/intrinsics/float_to_int_32_infneg1.rs
new file mode 100644 (file)
index 0000000..d18f75f
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f32, i32>(f32::NEG_INFINITY); } //~ ERROR: cannot be represented in target type `i32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_32_nan.rs b/tests/compile-fail/intrinsics/float_to_int_32_nan.rs
new file mode 100644 (file)
index 0000000..e1fe8c7
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f32, u32>(f32::NAN); } //~ ERROR: cannot be represented in target type `u32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_32_nanneg.rs b/tests/compile-fail/intrinsics/float_to_int_32_nanneg.rs
new file mode 100644 (file)
index 0000000..3889904
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f32, u32>(-f32::NAN); } //~ ERROR: cannot be represented in target type `u32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_32_neg.rs b/tests/compile-fail/intrinsics/float_to_int_32_neg.rs
new file mode 100644 (file)
index 0000000..f15cf9a
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f32, u32>(-1.000000001f32); } //~ ERROR: cannot be represented in target type `u32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_32_too_big1.rs b/tests/compile-fail/intrinsics/float_to_int_32_too_big1.rs
new file mode 100644 (file)
index 0000000..ccbf917
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f32, i32>(2147483648.0f32); } //~ ERROR: cannot be represented in target type `i32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_32_too_big2.rs b/tests/compile-fail/intrinsics/float_to_int_32_too_big2.rs
new file mode 100644 (file)
index 0000000..6598fd3
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f32, u32>((u32::MAX-127) as f32); } //~ ERROR: cannot be represented in target type `u32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_32_too_small1.rs b/tests/compile-fail/intrinsics/float_to_int_32_too_small1.rs
new file mode 100644 (file)
index 0000000..89f09e1
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f32, i32>(-2147483904.0f32); } //~ ERROR: cannot be represented in target type `i32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_inf1.rs b/tests/compile-fail/intrinsics/float_to_int_64_inf1.rs
new file mode 100644 (file)
index 0000000..e1a7b81
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, u128>(f64::INFINITY); } //~ ERROR: cannot be represented in target type `u128`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_infneg1.rs b/tests/compile-fail/intrinsics/float_to_int_64_infneg1.rs
new file mode 100644 (file)
index 0000000..a1d757b
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, u128>(f64::NEG_INFINITY); } //~ ERROR: cannot be represented in target type `u128`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_infneg2.rs b/tests/compile-fail/intrinsics/float_to_int_64_infneg2.rs
new file mode 100644 (file)
index 0000000..e48d19f
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, i128>(f64::NEG_INFINITY); } //~ ERROR: cannot be represented in target type `i128`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_nan.rs b/tests/compile-fail/intrinsics/float_to_int_64_nan.rs
new file mode 100644 (file)
index 0000000..03f378f
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, u32>(f64::NAN); } //~ ERROR: cannot be represented in target type `u32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_neg.rs b/tests/compile-fail/intrinsics/float_to_int_64_neg.rs
new file mode 100644 (file)
index 0000000..d0b5a3e
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, u128>(-1.0000000000001f64); } //~ ERROR: cannot be represented in target type `u128`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_big1.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_big1.rs
new file mode 100644 (file)
index 0000000..f928f16
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, i32>(2147483648.0f64); } //~ ERROR: cannot be represented in target type `i32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_big2.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_big2.rs
new file mode 100644 (file)
index 0000000..feb24c3
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, i64>(9223372036854775808.0f64); } //~ ERROR: cannot be represented in target type `i64`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_big3.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_big3.rs
new file mode 100644 (file)
index 0000000..cd491bf
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, u64>(18446744073709551616.0f64); } //~ ERROR: cannot be represented in target type `u64`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_big4.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_big4.rs
new file mode 100644 (file)
index 0000000..d5b2434
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, u128>(340282366920938463463374607431768211455.0f64); } //~ ERROR: cannot be represented in target type `u128`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_big5.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_big5.rs
new file mode 100644 (file)
index 0000000..9c31c69
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, i128>(240282366920938463463374607431768211455.0f64); } //~ ERROR: cannot be represented in target type `i128`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_small1.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_small1.rs
new file mode 100644 (file)
index 0000000..08f2f9e
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, i32>(-2147483649.0f64); } //~ ERROR: cannot be represented in target type `i32`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_small2.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_small2.rs
new file mode 100644 (file)
index 0000000..f7b205d
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, i64>(-9223372036854777856.0f64); } //~ ERROR: cannot be represented in target type `i64`
+}
diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_small3.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_small3.rs
new file mode 100644 (file)
index 0000000..779441f
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
+}
+
+fn main() {
+    unsafe { float_to_int_unchecked::<f64, i128>(-240282366920938463463374607431768211455.0f64); } //~ ERROR: cannot be represented in target type `i128`
+}