summaryrefslogtreecommitdiffstats
path: root/src/test/ui/op-assign-builtins-by-ref.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/op-assign-builtins-by-ref.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/op-assign-builtins-by-ref.rs')
-rw-r--r--src/test/ui/op-assign-builtins-by-ref.rs76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/test/ui/op-assign-builtins-by-ref.rs b/src/test/ui/op-assign-builtins-by-ref.rs
new file mode 100644
index 000000000..96853854d
--- /dev/null
+++ b/src/test/ui/op-assign-builtins-by-ref.rs
@@ -0,0 +1,76 @@
+// run-pass
+
+fn main() {
+ // test compound assignment operators with ref as right-hand side,
+ // for each operator, with various types as operands.
+
+ // test AddAssign
+ {
+ let mut x = 3i8;
+ x += &2i8;
+ assert_eq!(x, 5i8);
+ }
+
+ // test SubAssign
+ {
+ let mut x = 7i16;
+ x -= &4;
+ assert_eq!(x, 3i16);
+ }
+
+ // test MulAssign
+ {
+ let mut x = 3f32;
+ x *= &3f32;
+ assert_eq!(x, 9f32);
+ }
+
+ // test DivAssign
+ {
+ let mut x = 6f64;
+ x /= &2f64;
+ assert_eq!(x, 3f64);
+ }
+
+ // test RemAssign
+ {
+ let mut x = 7i64;
+ x %= &4i64;
+ assert_eq!(x, 3i64);
+ }
+
+ // test BitOrAssign
+ {
+ let mut x = 0b1010u8;
+ x |= &0b1100u8;
+ assert_eq!(x, 0b1110u8);
+ }
+
+ // test BitAndAssign
+ {
+ let mut x = 0b1010u16;
+ x &= &0b1100u16;
+ assert_eq!(x, 0b1000u16);
+ }
+
+ // test BitXorAssign
+ {
+ let mut x = 0b1010u32;
+ x ^= &0b1100u32;
+ assert_eq!(x, 0b0110u32);
+ }
+
+ // test ShlAssign
+ {
+ let mut x = 0b1010u64;
+ x <<= &2u32;
+ assert_eq!(x, 0b101000u64);
+ }
+
+ // test ShrAssign
+ {
+ let mut x = 0b1010u64;
+ x >>= &2i16;
+ assert_eq!(x, 0b10u64);
+ }
+}