about summary refs log tree commit diff
path: root/tests/ui/numbers-arithmetic/bitwise-ops-platform.rs
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-03 15:00:33 +0200
committerGitHub <noreply@github.com>2025-06-03 15:00:33 +0200
commit4fa33eb8d03138609093c84dad58de3dc501f347 (patch)
tree997c383d54e962f504aec8e0464e89c8d70acafc /tests/ui/numbers-arithmetic/bitwise-ops-platform.rs
parent19437666d9d6b38534a6b7bb575003033c180bff (diff)
parente7e884b0a4b5f012864562b0bb550d80d3e5f03b (diff)
downloadrust-4fa33eb8d03138609093c84dad58de3dc501f347.tar.gz
rust-4fa33eb8d03138609093c84dad58de3dc501f347.zip
Rollup merge of #141833 - Kivooeo:test-reform1, r=jieyouxu
`tests/ui`: A New Order [2/N]

part of rust-lang/rust#133895

r? `@jieyouxu`

let's try this kind of commits, one for each file, commit's name shows what i did, hope this is not harder to review than previous
Diffstat (limited to 'tests/ui/numbers-arithmetic/bitwise-ops-platform.rs')
-rw-r--r--tests/ui/numbers-arithmetic/bitwise-ops-platform.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/numbers-arithmetic/bitwise-ops-platform.rs b/tests/ui/numbers-arithmetic/bitwise-ops-platform.rs
new file mode 100644
index 00000000000..60d552e904b
--- /dev/null
+++ b/tests/ui/numbers-arithmetic/bitwise-ops-platform.rs
@@ -0,0 +1,36 @@
+//! Tests bitwise operations with platform-specific and negative number behavior.
+
+//@ run-pass
+
+#[cfg(any(target_pointer_width = "32"))]
+fn target() {
+    assert_eq!(-1000isize as usize >> 3_usize, 536870787_usize);
+}
+
+#[cfg(any(target_pointer_width = "64"))]
+fn target() {
+    assert_eq!(-1000isize as usize >> 3_usize, 2305843009213693827_usize);
+}
+
+fn general() {
+    let mut a: isize = 1;
+    let mut b: isize = 2;
+    a ^= b;
+    b ^= a;
+    a = a ^ b;
+    println!("{}", a);
+    println!("{}", b);
+    assert_eq!(b, 1);
+    assert_eq!(a, 2);
+    assert_eq!(!0xf0_isize & 0xff, 0xf);
+    assert_eq!(0xf0_isize | 0xf, 0xff);
+    assert_eq!(0xf_isize << 4, 0xf0);
+    assert_eq!(0xf0_isize >> 4, 0xf);
+    assert_eq!(-16 >> 2, -4);
+    assert_eq!(0b1010_1010_isize | 0b0101_0101, 0xff);
+}
+
+pub fn main() {
+    general();
+    target();
+}