about summary refs log tree commit diff
path: root/library/core/tests/ops.rs
diff options
context:
space:
mode:
authorChristiaan Dirkx <christiaan@dirkx.email>2020-11-22 09:08:04 +0100
committerChristiaan Dirkx <christiaan@dirkx.email>2020-11-30 02:47:32 +0100
commitbe554c4101df2a9ac65d40962ee37ece85d517bf (patch)
treede404d29144c6db9c24e81a2f6f8cb8d545abbe9 /library/core/tests/ops.rs
parent349b3b324dade7ca638091db93ba08bbc443c63d (diff)
downloadrust-be554c4101df2a9ac65d40962ee37ece85d517bf.tar.gz
rust-be554c4101df2a9ac65d40962ee37ece85d517bf.zip
Make ui test that are run-pass and do not test the compiler itself library tests
Diffstat (limited to 'library/core/tests/ops.rs')
-rw-r--r--library/core/tests/ops.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/library/core/tests/ops.rs b/library/core/tests/ops.rs
index e9d595e65e2..53e5539fad9 100644
--- a/library/core/tests/ops.rs
+++ b/library/core/tests/ops.rs
@@ -1,4 +1,5 @@
 use core::ops::{Bound, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive};
+use core::ops::{Deref, DerefMut};
 
 // Test the Range structs and syntax.
 
@@ -197,3 +198,35 @@ fn range_structural_match() {
         _ => unreachable!(),
     }
 }
+
+// Test Deref implementations
+
+#[test]
+fn deref_mut_on_ref() {
+    // Test that `&mut T` implements `DerefMut<T>`
+
+    fn inc<T: Deref<Target = isize> + DerefMut>(mut t: T) {
+        *t += 1;
+    }
+
+    let mut x: isize = 5;
+    inc(&mut x);
+    assert_eq!(x, 6);
+}
+
+#[test]
+fn deref_on_ref() {
+    // Test that `&T` and `&mut T` implement `Deref<T>`
+
+    fn deref<U: Copy, T: Deref<Target = U>>(t: T) -> U {
+        *t
+    }
+
+    let x: isize = 3;
+    let y = deref(&x);
+    assert_eq!(y, 3);
+
+    let mut x: isize = 4;
+    let y = deref(&mut x);
+    assert_eq!(y, 4);
+}