summaryrefslogtreecommitdiffstats
path: root/tests/ui/bitwise.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/bitwise.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/bitwise.rs')
-rw-r--r--tests/ui/bitwise.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/ui/bitwise.rs b/tests/ui/bitwise.rs
new file mode 100644
index 000000000..f79ff3c6e
--- /dev/null
+++ b/tests/ui/bitwise.rs
@@ -0,0 +1,34 @@
+// 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();
+}