about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-09 12:31:40 +0000
committerbors <bors@rust-lang.org>2014-11-09 12:31:40 +0000
commit946225d77f65e307de3c216cbc2c686b880a6791 (patch)
tree9c59ba3a3c98527c91baf65aa3e0e8dcf5567893 /src/libsyntax
parenta6b70914b6d74eed4bcaf040efbfdb33844f21c9 (diff)
parent54068eea42ae51a05b500e68a3cc283486cb00d4 (diff)
downloadrust-946225d77f65e307de3c216cbc2c686b880a6791.tar.gz
rust-946225d77f65e307de3c216cbc2c686b880a6791.zip
auto merge of #18755 : japaric/rust/ord, r=alexcrichton
Closes #18738
cc #15689

r? @alexcrichton 
cc @cmr 
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/deriving/cmp/eq.rs4
-rw-r--r--src/libsyntax/ext/deriving/cmp/ord.rs35
-rw-r--r--src/libsyntax/ext/deriving/cmp/totalord.rs2
3 files changed, 31 insertions, 10 deletions
diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs
index c3b1a52925d..7727bb824db 100644
--- a/src/libsyntax/ext/deriving/cmp/eq.rs
+++ b/src/libsyntax/ext/deriving/cmp/eq.rs
@@ -30,7 +30,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
             |cx, span, subexpr, self_f, other_fs| {
                 let other_f = match other_fs {
                     [ref o_f] => o_f,
-                    _ => cx.span_bug(span, "not exactly 2 arguments in `deriving(Eq)`")
+                    _ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialEq)`")
                 };
 
                 let eq = cx.expr_binary(span, ast::BiEq, self_f, other_f.clone());
@@ -47,7 +47,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
             |cx, span, subexpr, self_f, other_fs| {
                 let other_f = match other_fs {
                     [ref o_f] => o_f,
-                    _ => cx.span_bug(span, "not exactly 2 arguments in `deriving(Eq)`")
+                    _ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialEq)`")
                 };
 
                 let eq = cx.expr_binary(span, ast::BiNe, self_f, other_f.clone());
diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs
index 7cb61d295c0..cd44dde7004 100644
--- a/src/libsyntax/ext/deriving/cmp/ord.rs
+++ b/src/libsyntax/ext/deriving/cmp/ord.rs
@@ -107,12 +107,19 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
     let ordering = cx.expr_path(ordering);
     let equals_expr = cx.expr_some(span, ordering);
 
+    let partial_cmp_path = vec![
+        cx.ident_of("std"),
+        cx.ident_of("cmp"),
+        cx.ident_of("PartialOrd"),
+        cx.ident_of("partial_cmp"),
+    ];
+
     /*
     Builds:
 
-    let __test = self_field1.partial_cmp(&other_field2);
+    let __test = ::std::cmp::PartialOrd::partial_cmp(&self_field1, &other_field1);
     if __test == ::std::option::Some(::std::cmp::Equal) {
-        let __test = self_field2.partial_cmp(&other_field2);
+        let __test = ::std::cmp::PartialOrd::partial_cmp(&self_field2, &other_field2);
         if __test == ::std::option::Some(::std::cmp::Equal) {
             ...
         } else {
@@ -124,11 +131,11 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
 
     FIXME #6449: These `if`s could/should be `match`es.
     */
-    cs_same_method_fold(
+    cs_fold(
         // foldr nests the if-elses correctly, leaving the first field
         // as the outermost one, and the last as the innermost.
         false,
-        |cx, span, old, new| {
+        |cx, span, old, self_f, other_fs| {
             // let __test = new;
             // if __test == Some(::std::cmp::Equal) {
             //    old
@@ -136,6 +143,20 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
             //    __test
             // }
 
+            let new = {
+                let other_f = match other_fs {
+                    [ref o_f] => o_f,
+                    _ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`"),
+                };
+
+                let args = vec![
+                    cx.expr_addr_of(span, self_f),
+                    cx.expr_addr_of(span, other_f.clone()),
+                ];
+
+                cx.expr_call_global(span, partial_cmp_path.clone(), args)
+            };
+
             let assign = cx.stmt_let(span, false, test_id, new);
 
             let cond = cx.expr_binary(span, ast::BiEq,
@@ -149,7 +170,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
         equals_expr.clone(),
         |cx, span, (self_args, tag_tuple), _non_self_args| {
             if self_args.len() != 2 {
-                cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
+                cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
             } else {
                 some_ordering_collapsed(cx, span, PartialCmpOp, tag_tuple)
             }
@@ -183,7 +204,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
             */
             let other_f = match other_fs {
                 [ref o_f] => o_f,
-                _ => cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
+                _ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
             };
 
             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,
         cx.expr_bool(span, equal),
         |cx, span, (self_args, tag_tuple), _non_self_args| {
             if self_args.len() != 2 {
-                cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
+                cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
             } else {
                 let op = match (less, equal) {
                     (true,  true) => LeOp, (true,  false) => LtOp,
diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs
index 9ef463f9c63..d84ad677e5d 100644
--- a/src/libsyntax/ext/deriving/cmp/totalord.rs
+++ b/src/libsyntax/ext/deriving/cmp/totalord.rs
@@ -108,7 +108,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
         cx.expr_path(equals_path.clone()),
         |cx, span, (self_args, tag_tuple), _non_self_args| {
             if self_args.len() != 2 {
-                cx.span_bug(span, "not exactly 2 arguments in `deriving(TotalOrd)`")
+                cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
             } else {
                 ordering_collapsed(cx, span, tag_tuple)
             }