@@ -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(Ord)`" ) ,
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 ,
0 commit comments