about summary refs log tree commit diff
path: root/src/test/run-pass
diff options
context:
space:
mode:
authorEh2406 <YeomanYaacov@gmail.com>2017-09-02 22:50:01 -0400
committerEh2406 <YeomanYaacov@gmail.com>2017-09-03 09:12:22 -0400
commitf65bb2a051a6362b3e2dcdf3e081b8c76f5ef1a7 (patch)
treeef1d07d8a56438332b62ebc198b54f54073c7d6f /src/test/run-pass
parent23ade23cbcab35371ceade1649b5cc9fd13d3b5e (diff)
downloadrust-f65bb2a051a6362b3e2dcdf3e081b8c76f5ef1a7.tar.gz
rust-f65bb2a051a6362b3e2dcdf3e081b8c76f5ef1a7.zip
Manuall rebase of @Migi pull/41336
Diffstat (limited to 'src/test/run-pass')
-rw-r--r--src/test/run-pass/num-wrapping.rs9
-rw-r--r--src/test/run-pass/op-assign-builtins-by-ref.rs84
2 files changed, 93 insertions, 0 deletions
diff --git a/src/test/run-pass/num-wrapping.rs b/src/test/run-pass/num-wrapping.rs
index 143759e2715..20c7f27336e 100644
--- a/src/test/run-pass/num-wrapping.rs
+++ b/src/test/run-pass/num-wrapping.rs
@@ -173,6 +173,15 @@ fn test_op_assigns() {
                 tmp.$op(Wrapping($rhs));
                 assert_eq!(black_box(tmp), Wrapping($ans));
             }
+
+            // also test that a &Wrapping<T> right-hand side is possible
+            {
+                let mut tmp = Wrapping($initial);
+                tmp = black_box(tmp);
+                tmp.$op(&Wrapping($rhs));
+                assert_eq!(black_box(tmp), Wrapping($ans));
+            }
+
             // FIXME(30524): Uncomment this test
             /*
             {
diff --git a/src/test/run-pass/op-assign-builtins-by-ref.rs b/src/test/run-pass/op-assign-builtins-by-ref.rs
new file mode 100644
index 00000000000..77023a56679
--- /dev/null
+++ b/src/test/run-pass/op-assign-builtins-by-ref.rs
@@ -0,0 +1,84 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+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);
+    }
+}
\ No newline at end of file