Skip to content

Commit dc18d50

Browse files
Test const impl of cmp traits
1 parent 911736d commit dc18d50

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

library/core/tests/cmp.rs

+28
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,31 @@ fn cmp_default() {
203203
assert!(Fool(false) != Fool(false));
204204
assert_eq!(Fool(false), Fool(true));
205205
}
206+
207+
struct S(i32);
208+
209+
impl const PartialEq for S {
210+
fn eq(&self, other: &Self) -> bool {
211+
self.0 == other.0
212+
}
213+
}
214+
215+
impl const PartialOrd for S {
216+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
217+
let ret = match (self.0, other.0) {
218+
(a, b) if a > b => Ordering::Greater,
219+
(a, b) if a < b => Ordering::Less,
220+
_ => Ordering::Equal,
221+
};
222+
223+
Some(ret)
224+
}
225+
}
226+
227+
const _: () = assert!(S(1) == S(1));
228+
const _: () = assert!(S(0) != S(1));
229+
230+
const _: () = assert!(S(1) <= S(1));
231+
const _: () = assert!(S(1) >= S(1));
232+
const _: () = assert!(S(0) < S(1));
233+
const _: () = assert!(S(1) > S(0));

0 commit comments

Comments
 (0)