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