From fbf47d17845cc3df5b116e45ecfea71005b61735 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 19 Apr 2020 09:21:00 +0200 Subject: [PATCH 1/2] note source of test values --- tests/run-pass/float.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-pass/float.rs b/tests/run-pass/float.rs index c56d12a0c00..fc513ead8dd 100644 --- a/tests/run-pass/float.rs +++ b/tests/run-pass/float.rs @@ -114,6 +114,8 @@ fn basic() { assert_eq(y, 42.0_f32); } +/// Many of these test values are taken from +/// https://github.com/WebAssembly/testsuite/blob/master/conversions.wast. fn casts() { // f32 -> i8 test_both_cast::(127.99, 127); From 70c828b76125bc5f469e5e776f2e984708876974 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 19 Apr 2020 09:34:54 +0200 Subject: [PATCH 2/2] test some more extreme cast cases --- .../intrinsics/float_to_int_64_too_big6.rs | 10 ++++++++++ .../intrinsics/float_to_int_64_too_big7.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/compile-fail/intrinsics/float_to_int_64_too_big6.rs create mode 100644 tests/compile-fail/intrinsics/float_to_int_64_too_big7.rs diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_big6.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_big6.rs new file mode 100644 index 00000000000..f008131a6e5 --- /dev/null +++ b/tests/compile-fail/intrinsics/float_to_int_64_too_big6.rs @@ -0,0 +1,10 @@ +#![feature(intrinsics)] + +// Directly call intrinsic to avoid debug assertions in libstd +extern "rust-intrinsic" { + fn float_to_int_unchecked(value: Float) -> Int; +} + +fn main() { + unsafe { float_to_int_unchecked::(f64::MAX); } //~ ERROR: cannot be represented in target type `u128` +} diff --git a/tests/compile-fail/intrinsics/float_to_int_64_too_big7.rs b/tests/compile-fail/intrinsics/float_to_int_64_too_big7.rs new file mode 100644 index 00000000000..69922e60a6b --- /dev/null +++ b/tests/compile-fail/intrinsics/float_to_int_64_too_big7.rs @@ -0,0 +1,10 @@ +#![feature(intrinsics)] + +// Directly call intrinsic to avoid debug assertions in libstd +extern "rust-intrinsic" { + fn float_to_int_unchecked(value: Float) -> Int; +} + +fn main() { + unsafe { float_to_int_unchecked::(f64::MIN); } //~ ERROR: cannot be represented in target type `i128` +}