@@ -107,12 +107,19 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
107
107
let ordering = cx. expr_path ( ordering) ;
108
108
let equals_expr = cx. expr_some ( span, ordering) ;
109
109
110
+ let partial_cmp_path = vec ! [
111
+ cx. ident_of( "std" ) ,
112
+ cx. ident_of( "cmp" ) ,
113
+ cx. ident_of( "PartialOrd" ) ,
114
+ cx. ident_of( "partial_cmp" ) ,
115
+ ] ;
116
+
110
117
/*
111
118
Builds:
112
119
113
- let __test = self_field1. partial_cmp(&other_field2 );
120
+ let __test = ::std::cmp::PartialOrd:: partial_cmp(&self_field1, &other_field1 );
114
121
if __test == ::std::option::Some(::std::cmp::Equal) {
115
- let __test = self_field2. partial_cmp(&other_field2);
122
+ let __test = ::std::cmp::PartialOrd:: partial_cmp(&self_field2, &other_field2);
116
123
if __test == ::std::option::Some(::std::cmp::Equal) {
117
124
...
118
125
} else {
@@ -124,18 +131,32 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
124
131
125
132
FIXME #6449: These `if`s could/should be `match`es.
126
133
*/
127
- cs_same_method_fold (
134
+ cs_fold (
128
135
// foldr nests the if-elses correctly, leaving the first field
129
136
// as the outermost one, and the last as the innermost.
130
137
false ,
131
- |cx, span, old, new | {
138
+ |cx, span, old, self_f , other_fs | {
132
139
// let __test = new;
133
140
// if __test == Some(::std::cmp::Equal) {
134
141
// old
135
142
// } else {
136
143
// __test
137
144
// }
138
145
146
+ let new = {
147
+ let other_f = match other_fs {
148
+ [ ref o_f] => o_f,
149
+ _ => cx. span_bug ( span, "not exactly 2 arguments in `deriving(PartialOrd)`" ) ,
150
+ } ;
151
+
152
+ let args = vec ! [
153
+ cx. expr_addr_of( span, self_f) ,
154
+ cx. expr_addr_of( span, other_f. clone( ) ) ,
155
+ ] ;
156
+
157
+ cx. expr_call_global ( span, partial_cmp_path. clone ( ) , args)
158
+ } ;
159
+
139
160
let assign = cx. stmt_let ( span, false , test_id, new) ;
140
161
141
162
let cond = cx. expr_binary ( span, ast:: BiEq ,
@@ -149,7 +170,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
149
170
equals_expr. clone ( ) ,
150
171
|cx, span, ( self_args, tag_tuple) , _non_self_args| {
151
172
if self_args. len ( ) != 2 {
152
- cx. span_bug ( span, "not exactly 2 arguments in `deriving(Ord )`" )
173
+ cx. span_bug ( span, "not exactly 2 arguments in `deriving(PartialOrd )`" )
153
174
} else {
154
175
some_ordering_collapsed ( cx, span, PartialCmpOp , tag_tuple)
155
176
}
@@ -183,7 +204,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
183
204
*/
184
205
let other_f = match other_fs {
185
206
[ ref o_f] => o_f,
186
- _ => cx. span_bug ( span, "not exactly 2 arguments in `deriving(Ord )`" )
207
+ _ => cx. span_bug ( span, "not exactly 2 arguments in `deriving(PartialOrd )`" )
187
208
} ;
188
209
189
210
let cmp = cx. expr_binary ( span, op, self_f. clone ( ) , other_f. clone ( ) ) ;
@@ -197,7 +218,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
197
218
cx. expr_bool ( span, equal) ,
198
219
|cx, span, ( self_args, tag_tuple) , _non_self_args| {
199
220
if self_args. len ( ) != 2 {
200
- cx. span_bug ( span, "not exactly 2 arguments in `deriving(Ord )`" )
221
+ cx. span_bug ( span, "not exactly 2 arguments in `deriving(PartialOrd )`" )
201
222
} else {
202
223
let op = match ( less, equal) {
203
224
( true , true ) => LeOp , ( true , false ) => LtOp ,
0 commit comments