2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2013-08-05 09:09:15 +00:00
|
|
|
// check that the derived impls for the comparison traits shortcircuit
|
2014-10-09 19:17:22 +00:00
|
|
|
// where possible, by having a type that panics when compared as the
|
2013-08-05 09:09:15 +00:00
|
|
|
// second element, so this passes iff the instances shortcircuit.
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2014-12-22 17:04:23 +00:00
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
2013-08-05 09:09:15 +00:00
|
|
|
pub struct FailCmp;
|
2014-05-30 00:45:07 +00:00
|
|
|
impl PartialEq for FailCmp {
|
2014-10-09 19:17:22 +00:00
|
|
|
fn eq(&self, _: &FailCmp) -> bool { panic!("eq") }
|
2013-08-05 09:09:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 00:45:07 +00:00
|
|
|
impl PartialOrd for FailCmp {
|
2014-10-09 19:17:22 +00:00
|
|
|
fn partial_cmp(&self, _: &FailCmp) -> Option<Ordering> { panic!("partial_cmp") }
|
2013-08-05 09:09:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 17:43:52 +00:00
|
|
|
impl Eq for FailCmp {}
|
2013-08-05 09:09:15 +00:00
|
|
|
|
2014-05-31 17:43:52 +00:00
|
|
|
impl Ord for FailCmp {
|
2014-10-09 19:17:22 +00:00
|
|
|
fn cmp(&self, _: &FailCmp) -> Ordering { panic!("cmp") }
|
2013-08-05 09:09:15 +00:00
|
|
|
}
|
|
|
|
|
2014-12-31 04:32:49 +00:00
|
|
|
#[derive(PartialEq,PartialOrd,Eq,Ord)]
|
2013-08-05 09:09:15 +00:00
|
|
|
struct ShortCircuit {
|
2015-03-26 00:06:52 +00:00
|
|
|
x: isize,
|
2013-08-05 09:09:15 +00:00
|
|
|
y: FailCmp
|
|
|
|
}
|
|
|
|
|
2013-09-25 07:43:37 +00:00
|
|
|
pub fn main() {
|
2013-08-05 09:09:15 +00:00
|
|
|
let a = ShortCircuit { x: 1, y: FailCmp };
|
|
|
|
let b = ShortCircuit { x: 2, y: FailCmp };
|
|
|
|
|
|
|
|
assert!(a != b);
|
|
|
|
assert!(a < b);
|
2014-11-28 16:57:41 +00:00
|
|
|
assert_eq!(a.cmp(&b), ::std::cmp::Ordering::Less);
|
2013-08-05 09:09:15 +00:00
|
|
|
}
|