@@ -66,12 +66,19 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
66
66
cx. ident_of( "cmp" ) ,
67
67
cx. ident_of( "Equal" ) ) ) ;
68
68
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
+
69
76
/*
70
77
Builds:
71
78
72
- let __test = self_field1. cmp(&other_field2 );
79
+ let __test = ::std:: cmp::Ord::cmp(&self_field1, &other_field1 );
73
80
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);
75
82
if __test == ::std::cmp::Ordering::Equal {
76
83
...
77
84
} else {
@@ -83,18 +90,32 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
83
90
84
91
FIXME #6449: These `if`s could/should be `match`es.
85
92
*/
86
- cs_same_method_fold (
93
+ cs_fold (
87
94
// foldr nests the if-elses correctly, leaving the first field
88
95
// as the outermost one, and the last as the innermost.
89
96
false ,
90
- |cx, span, old, new | {
97
+ |cx, span, old, self_f , other_fs | {
91
98
// let __test = new;
92
99
// if __test == ::std::cmp::Ordering::Equal {
93
100
// old
94
101
// } else {
95
102
// __test
96
103
// }
97
104
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
+
98
119
let assign = cx. stmt_let ( span, false , test_id, new) ;
99
120
100
121
let cond = cx. expr_binary ( span, ast:: BiEq ,
0 commit comments