]> git.lizzy.rs Git - rust.git/blob - src/test/ui/numbers-arithmetic/float-int-invalid-const-cast.rs
Auto merge of #65129 - andjo403:cargo_args, r=alexcrichton
[rust.git] / src / test / ui / numbers-arithmetic / float-int-invalid-const-cast.rs
1 // run-pass
2 // ignore-emscripten no i128 support
3
4 #![deny(const_err)]
5
6 use std::{f32, f64};
7
8 // Forces evaluation of constants, triggering hard error
9 fn force<T>(_: T) {}
10
11 fn main() {
12     { const X: u16 = -1. as u16; force(X); }
13     { const X: u128 = -100. as u128; force(X); }
14
15     { const X: i8 = f32::NAN as i8; force(X); }
16     { const X: i32 = f32::NAN as i32; force(X); }
17     { const X: u64 = f32::NAN as u64; force(X); }
18     { const X: u128 = f32::NAN as u128; force(X); }
19
20     { const X: i8 = f32::INFINITY as i8; force(X); }
21     { const X: u32 = f32::INFINITY as u32; force(X); }
22     { const X: i128 = f32::INFINITY as i128; force(X); }
23     { const X: u128 = f32::INFINITY as u128; force(X); }
24
25     { const X: u8 = f32::NEG_INFINITY as u8; force(X); }
26     { const X: u16 = f32::NEG_INFINITY as u16; force(X); }
27     { const X: i64 = f32::NEG_INFINITY as i64; force(X); }
28     { const X: i128 = f32::NEG_INFINITY as i128; force(X); }
29
30     { const X: i8 = f64::NAN as i8; force(X); }
31     { const X: i32 = f64::NAN as i32; force(X); }
32     { const X: u64 = f64::NAN as u64; force(X); }
33     { const X: u128 = f64::NAN as u128; force(X); }
34
35     { const X: i8 = f64::INFINITY as i8; force(X); }
36     { const X: u32 = f64::INFINITY as u32; force(X); }
37     { const X: i128 = f64::INFINITY as i128; force(X); }
38     { const X: u128 = f64::INFINITY as u128; force(X); }
39
40     { const X: u8 = f64::NEG_INFINITY as u8; force(X); }
41     { const X: u16 = f64::NEG_INFINITY as u16; force(X); }
42     { const X: i64 = f64::NEG_INFINITY as i64; force(X); }
43     { const X: i128 = f64::NEG_INFINITY as i128; force(X); }
44
45     { const X: u8 = 256. as u8; force(X); }
46     { const X: i8 = -129. as i8; force(X); }
47     { const X: i8 = 128. as i8; force(X); }
48     { const X: i32 = 2147483648. as i32; force(X); }
49     { const X: i32 = -2147483904. as i32; force(X); }
50     { const X: u32 = 4294967296. as u32; force(X); }
51     { const X: u128 = 1e40 as u128; force(X); }
52     { const X: i128 = 1e40 as i128; force(X); }
53 }