2013-08-05 04:09:15 -05:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// 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
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
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
|
|
|
}
|