@@ -66,12 +66,19 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
6666 cx. ident_of( "cmp" ) ,
6767 cx. ident_of( "Equal" ) ) ) ;
6868
69+ let cmp_path = vec ! [
70+ cx. ident_of( "std" ) ,
71+ cx. ident_of( "cmp" ) ,
72+ cx. ident_of( "Ord" ) ,
73+ cx. ident_of( "cmp" ) ,
74+ ] ;
75+
6976 /*
7077 Builds:
7178
72- let __test = self_field1. cmp(&other_field2 );
79+ let __test = ::std:: cmp::Ord::cmp(&self_field1, &other_field1 );
7380 if other == ::std::cmp::Ordering::Equal {
74- let __test = self_field2. cmp( &other_field2);
81+ let __test = ::std:: cmp::Ord::cmp(&self_field2, &other_field2);
7582 if __test == ::std::cmp::Ordering::Equal {
7683 ...
7784 } else {
@@ -83,18 +90,32 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
8390
8491 FIXME #6449: These `if`s could/should be `match`es.
8592 */
86- cs_same_method_fold (
93+ cs_fold (
8794 // foldr nests the if-elses correctly, leaving the first field
8895 // as the outermost one, and the last as the innermost.
8996 false ,
90- |cx, span, old, new | {
97+ |cx, span, old, self_f , other_fs | {
9198 // let __test = new;
9299 // if __test == ::std::cmp::Ordering::Equal {
93100 // old
94101 // } else {
95102 // __test
96103 // }
97104
105+ let new = {
106+ let other_f = match other_fs {
107+ [ ref o_f] => o_f,
108+ _ => cx. span_bug ( span, "not exactly 2 arguments in `deriving(PartialOrd)`" ) ,
109+ } ;
110+
111+ let args = vec ! [
112+ cx. expr_addr_of( span, self_f) ,
113+ cx. expr_addr_of( span, other_f. clone( ) ) ,
114+ ] ;
115+
116+ cx. expr_call_global ( span, cmp_path. clone ( ) , args)
117+ } ;
118+
98119 let assign = cx. stmt_let ( span, false , test_id, new) ;
99120
100121 let cond = cx. expr_binary ( span, ast:: BiEq ,
0 commit comments