Skip to content

Commit 4155fb6

Browse files
committed
Auto merge of #1351 - RalfJung:float-test-source, r=RalfJung
note source of float cast test values, and some more UB tests
2 parents fac9d22 + 70c828b commit 4155fb6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(intrinsics)]
2+
3+
// Directly call intrinsic to avoid debug assertions in libstd
4+
extern "rust-intrinsic" {
5+
fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
6+
}
7+
8+
fn main() {
9+
unsafe { float_to_int_unchecked::<f64, u128>(f64::MAX); } //~ ERROR: cannot be represented in target type `u128`
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(intrinsics)]
2+
3+
// Directly call intrinsic to avoid debug assertions in libstd
4+
extern "rust-intrinsic" {
5+
fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
6+
}
7+
8+
fn main() {
9+
unsafe { float_to_int_unchecked::<f64, i128>(f64::MIN); } //~ ERROR: cannot be represented in target type `i128`
10+
}

tests/run-pass/float.rs

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ fn basic() {
114114
assert_eq(y, 42.0_f32);
115115
}
116116

117+
/// Many of these test values are taken from
118+
/// https://github.com/WebAssembly/testsuite/blob/master/conversions.wast.
117119
fn casts() {
118120
// f32 -> i8
119121
test_both_cast::<f32, i8>(127.99, 127);

0 commit comments

Comments
 (0)