add tests for invalid float-to-int casts
This commit is contained in:
parent
25c71e5c0e
commit
17c52d47e7
10
tests/compile-fail/intrinsics/float_to_int_32_inf1.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_32_inf1.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_32_infneg1.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_32_infneg1.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_32_nan.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_32_nan.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_32_nanneg.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_32_nanneg.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_32_neg.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_32_neg.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_32_too_big1.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_32_too_big1.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_32_too_big2.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_32_too_big2.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_32_too_small1.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_32_too_small1.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_inf1.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_inf1.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_infneg1.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_infneg1.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_infneg2.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_infneg2.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_nan.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_nan.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_neg.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_neg.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_too_big1.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_too_big1.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_too_big2.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_too_big2.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_too_big3.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_too_big3.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_too_big4.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_too_big4.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_too_big5.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_too_big5.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_too_small1.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_too_small1.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_too_small2.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_too_small2.rs
Normal file
@ -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`
|
||||
}
|
10
tests/compile-fail/intrinsics/float_to_int_64_too_small3.rs
Normal file
10
tests/compile-fail/intrinsics/float_to_int_64_too_small3.rs
Normal file
@ -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`
|
||||
}
|
Loading…
Reference in New Issue
Block a user