]> git.lizzy.rs Git - rust.git/blob - src/test/ui/deriving/deriving-cmp-shortcircuit.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / deriving / deriving-cmp-shortcircuit.rs
1 // run-pass
2 // check that the derived impls for the comparison traits shortcircuit
3 // where possible, by having a type that panics when compared as the
4 // second element, so this passes iff the instances shortcircuit.
5
6
7 use std::cmp::Ordering;
8
9 pub struct FailCmp;
10 impl PartialEq for FailCmp {
11     fn eq(&self, _: &FailCmp) -> bool { panic!("eq") }
12 }
13
14 impl PartialOrd for FailCmp {
15     fn partial_cmp(&self, _: &FailCmp) -> Option<Ordering> { panic!("partial_cmp") }
16 }
17
18 impl Eq for FailCmp {}
19
20 impl Ord for FailCmp {
21     fn cmp(&self, _: &FailCmp) -> Ordering { panic!("cmp") }
22 }
23
24 #[derive(PartialEq,PartialOrd,Eq,Ord)]
25 struct ShortCircuit {
26     x: isize,
27     y: FailCmp
28 }
29
30 pub fn main() {
31     let a = ShortCircuit { x: 1, y: FailCmp };
32     let b = ShortCircuit { x: 2, y: FailCmp };
33
34     assert!(a != b);
35     assert!(a < b);
36     assert_eq!(a.cmp(&b), ::std::cmp::Ordering::Less);
37 }