summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/const-int-conversion-rpass.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/consts/const-int-conversion-rpass.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/consts/const-int-conversion-rpass.rs')
-rw-r--r--src/test/ui/consts/const-int-conversion-rpass.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-int-conversion-rpass.rs b/src/test/ui/consts/const-int-conversion-rpass.rs
new file mode 100644
index 000000000..4aaeeaa38
--- /dev/null
+++ b/src/test/ui/consts/const-int-conversion-rpass.rs
@@ -0,0 +1,19 @@
+// run-pass
+
+const REVERSE: u32 = 0x12345678_u32.reverse_bits();
+const FROM_BE_BYTES: i32 = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]);
+const FROM_LE_BYTES: i32 = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]);
+const FROM_NE_BYTES: i32 = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
+const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes();
+const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes();
+const TO_NE_BYTES: [u8; 4] = i32::MIN.to_be().to_ne_bytes();
+
+fn main() {
+ assert_eq!(REVERSE, 0x1e6a2c48);
+ assert_eq!(FROM_BE_BYTES, 0x12_34_56_78);
+ assert_eq!(FROM_LE_BYTES, 0x78_56_34_12);
+ assert_eq!(FROM_NE_BYTES, i32::MIN);
+ assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]);
+ assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]);
+ assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]);
+}