]> git.proxmox.com Git - rustc.git/blobdiff - library/core/tests/cmp.rs
New upstream version 1.59.0+dfsg1
[rustc.git] / library / core / tests / cmp.rs
index 11cf7add07ada9076ec3c9e1533343bf17c0ce95..58fee19ca7490d3e2251fe3e8ad40a101bcac1f0 100644 (file)
@@ -203,3 +203,36 @@ fn cmp_default() {
     assert!(Fool(false) != Fool(false));
     assert_eq!(Fool(false), Fool(true));
 }
+
+#[cfg(not(bootstrap))]
+mod const_cmp {
+    use super::*;
+
+    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));
+}