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