Skip to content

Commit

Permalink
Test const impl of cmp traits
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Dec 17, 2021
1 parent 9c83b56 commit 1606335
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions library/core/tests/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit 1606335

Please sign in to comment.