summaryrefslogtreecommitdiffstats
path: root/tests/ui/deriving/deriving-cmp-generic-struct.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/deriving/deriving-cmp-generic-struct.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/deriving/deriving-cmp-generic-struct.rs')
-rw-r--r--tests/ui/deriving/deriving-cmp-generic-struct.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/ui/deriving/deriving-cmp-generic-struct.rs b/tests/ui/deriving/deriving-cmp-generic-struct.rs
new file mode 100644
index 000000000..538caf439
--- /dev/null
+++ b/tests/ui/deriving/deriving-cmp-generic-struct.rs
@@ -0,0 +1,40 @@
+// run-pass
+#[derive(PartialEq, Eq, PartialOrd, Ord)]
+struct S<T> {
+ x: T,
+ y: T
+}
+
+pub fn main() {
+ let s1 = S {x: 1, y: 1};
+ let s2 = S {x: 1, y: 2};
+
+ // in order for both PartialOrd and Ord
+ let ss = [s1, s2];
+
+ for (i, s1) in ss.iter().enumerate() {
+ for (j, s2) in ss.iter().enumerate() {
+ let ord = i.cmp(&j);
+
+ let eq = i == j;
+ let lt = i < j;
+ let le = i <= j;
+ let gt = i > j;
+ let ge = i >= j;
+
+ // PartialEq
+ assert_eq!(*s1 == *s2, eq);
+ assert_eq!(*s1 != *s2, !eq);
+
+ // PartialOrd
+ assert_eq!(*s1 < *s2, lt);
+ assert_eq!(*s1 > *s2, gt);
+
+ assert_eq!(*s1 <= *s2, le);
+ assert_eq!(*s1 >= *s2, ge);
+
+ // Ord
+ assert_eq!(s1.cmp(s2), ord);
+ }
+ }
+}