@@ -107,12 +107,19 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
107107 let ordering = cx. expr_path ( ordering) ;
108108 let equals_expr = cx. expr_some ( span, ordering) ;
109109
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+
110117 /*
111118 Builds:
112119
113- let __test = self_field1. partial_cmp(&other_field2 );
120+ let __test = ::std::cmp::PartialOrd:: partial_cmp(&self_field1, &other_field1 );
114121 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);
116123 if __test == ::std::option::Some(::std::cmp::Equal) {
117124 ...
118125 } else {
@@ -124,18 +131,32 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
124131
125132 FIXME #6449: These `if`s could/should be `match`es.
126133 */
127- cs_same_method_fold (
134+ cs_fold (
128135 // foldr nests the if-elses correctly, leaving the first field
129136 // as the outermost one, and the last as the innermost.
130137 false ,
131- |cx, span, old, new | {
138+ |cx, span, old, self_f , other_fs | {
132139 // let __test = new;
133140 // if __test == Some(::std::cmp::Equal) {
134141 // old
135142 // } else {
136143 // __test
137144 // }
138145
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+
139160 let assign = cx. stmt_let ( span, false , test_id, new) ;
140161
141162 let cond = cx. expr_binary ( span, ast:: BiEq ,
@@ -149,7 +170,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
149170 equals_expr. clone ( ) ,
150171 |cx, span, ( self_args, tag_tuple) , _non_self_args| {
151172 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 )`" )
153174 } else {
154175 some_ordering_collapsed ( cx, span, PartialCmpOp , tag_tuple)
155176 }
@@ -183,7 +204,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
183204 */
184205 let other_f = match other_fs {
185206 [ 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 )`" )
187208 } ;
188209
189210 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,
197218 cx. expr_bool ( span, equal) ,
198219 |cx, span, ( self_args, tag_tuple) , _non_self_args| {
199220 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 )`" )
201222 } else {
202223 let op = match ( less, equal) {
203224 ( true , true ) => LeOp , ( true , false ) => LtOp ,
0 commit comments