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