about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2021-12-01 14:37:51 -0800
committerDylan MacKenzie <ecstaticmorse@gmail.com>2021-12-16 21:35:25 -0800
commit1606335a93a2c0ab218ffc1c776ed7ddd9515520 (patch)
tree34afafbe7acd888fadff7620f25e88d7fcee4064
parent9c83b56056860fe6efcb2dc8b731c8532f1e57b7 (diff)
downloadrust-1606335a93a2c0ab218ffc1c776ed7ddd9515520.tar.gz
rust-1606335a93a2c0ab218ffc1c776ed7ddd9515520.zip
Test const impl of `cmp` traits
-rw-r--r--library/core/tests/cmp.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/library/core/tests/cmp.rs b/library/core/tests/cmp.rs
index 11cf7add07a..c9d29ed3a83 100644
--- a/library/core/tests/cmp.rs
+++ b/library/core/tests/cmp.rs
@@ -203,3 +203,31 @@ fn cmp_default() {
     assert!(Fool(false) != Fool(false));
     assert_eq!(Fool(false), Fool(true));
 }
+
+struct S(i32);
+
+impl const PartialEq for S {
+    fn eq(&self, other: &Self) -> bool {
+        self.0 == other.0
+    }
+}
+
+impl const PartialOrd for S {
+    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+        let ret = match (self.0, other.0) {
+            (a, b) if a > b => Ordering::Greater,
+            (a, b) if a < b => Ordering::Less,
+            _ => Ordering::Equal,
+        };
+
+        Some(ret)
+    }
+}
+
+const _: () = assert!(S(1) == S(1));
+const _: () = assert!(S(0) != S(1));
+
+const _: () = assert!(S(1) <= S(1));
+const _: () = assert!(S(1) >= S(1));
+const _: () = assert!(S(0) <  S(1));
+const _: () = assert!(S(1) >  S(0));