]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-int-conversion-rpass.rs
Rollup merge of #64603 - gilescope:unused-lifetime-warning, r=matthewjasper
[rust.git] / src / test / ui / consts / const-int-conversion-rpass.rs
1 // run-pass
2
3 #![feature(const_int_conversion)]
4
5 const REVERSE: u32 = 0x12345678_u32.reverse_bits();
6 const FROM_BE_BYTES: i32 = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]);
7 const FROM_LE_BYTES: i32 = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]);
8 const FROM_NE_BYTES: i32 = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
9 const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes();
10 const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes();
11 const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes();
12
13 fn main() {
14     assert_eq!(REVERSE, 0x1e6a2c48);
15     assert_eq!(FROM_BE_BYTES, 0x12_34_56_78);
16     assert_eq!(FROM_LE_BYTES, 0x78_56_34_12);
17     assert_eq!(FROM_NE_BYTES, i32::min_value());
18     assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]);
19     assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]);
20     assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]);
21 }