about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/etc/generate-deriving-span-tests.py2
-rw-r--r--src/libsyntax_ext/deriving/cmp/partial_ord.rs31
-rw-r--r--src/test/compile-fail/derives-span-PartialOrd-enum-struct-variant.rs1
-rw-r--r--src/test/compile-fail/derives-span-PartialOrd-enum.rs1
-rw-r--r--src/test/compile-fail/derives-span-PartialOrd-struct.rs1
-rw-r--r--src/test/compile-fail/derives-span-PartialOrd-tuple-struct.rs1
-rw-r--r--src/test/compile-fail/range_traits-1.rs6
7 files changed, 21 insertions, 22 deletions
diff --git a/src/etc/generate-deriving-span-tests.py b/src/etc/generate-deriving-span-tests.py
index e248f471395..2e9169ce5b9 100755
--- a/src/etc/generate-deriving-span-tests.py
+++ b/src/etc/generate-deriving-span-tests.py
@@ -122,7 +122,7 @@ traits = {
 
 for (trait, supers, errs) in [('Clone', [], 1),
                               ('PartialEq', [], 2),
-                              ('PartialOrd', ['PartialEq'], 2),
+                              ('PartialOrd', ['PartialEq'], 1),
                               ('Eq', ['PartialEq'], 1),
                               ('Ord', ['Eq', 'PartialOrd', 'PartialEq'], 1),
                               ('Debug', [], 1),
diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs
index b6f36582f3c..f8c27bf42a9 100644
--- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs
+++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs
@@ -201,21 +201,27 @@ fn cs_op(less: bool,
         cx.expr_path(cx.path_global(span, cx.std_path(&["cmp", "Ordering", name])))
     };
 
-    let par_cmp = |cx: &mut ExtCtxt, span: Span, self_f: P<Expr>, other_fs: &[P<Expr>]| {
+    let par_cmp = |cx: &mut ExtCtxt, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| {
         let other_f = match (other_fs.len(), other_fs.get(0)) {
             (1, Some(o_f)) => o_f,
             _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
         };
 
-        // `self.fi.partial_cmp(other.fi)`
-        let cmp = cx.expr_method_call(span,
-                                      cx.expr_addr_of(span, self_f),
-                                      Ident::from_str("partial_cmp"),
-                                      vec![cx.expr_addr_of(span, other_f.clone())]);
+        // `PartialOrd::partial_cmp(self.fi, other.fi)`
+        let cmp_path = cx.expr_path(cx.path_global(span, cx.std_path(&["cmp",
+                                                                       "PartialOrd",
+                                                                       "partial_cmp"])));
+        let cmp = cx.expr_call(span,
+                               cmp_path,
+                               vec![cx.expr_addr_of(span, self_f),
+                                    cx.expr_addr_of(span, other_f.clone())]);
 
-        let default = ordering_path(cx, "Equal");
-        // `_.unwrap_or(Ordering::Equal)`
-        cx.expr_method_call(span, cmp, Ident::from_str("unwrap_or"), vec![default])
+        let default = ordering_path(cx, default);
+        // `Option::unwrap_or(_, Ordering::Equal)`
+        let unwrap_path = cx.expr_path(cx.path_global(span, cx.std_path(&["option",
+                                                                          "Option",
+                                                                          "unwrap_or"])));
+        cx.expr_call(span, unwrap_path, vec![cmp, default])
     };
 
     let fold = cs_fold1(false, // need foldr
@@ -244,7 +250,7 @@ fn cs_op(less: bool,
             // layers of pointers, if the type includes pointers.
 
             // `self.fi.partial_cmp(other.fi).unwrap_or(Ordering::Equal)`
-            let par_cmp = par_cmp(cx, span, self_f, other_fs);
+            let par_cmp = par_cmp(cx, span, self_f, other_fs, "Equal");
 
             // `self.fi.partial_cmp(other.fi).unwrap_or(Ordering::Equal).then_with(...)`
             cx.expr_method_call(span,
@@ -254,7 +260,10 @@ fn cs_op(less: bool,
         },
         |cx, args| {
             match args {
-                Some((span, self_f, other_fs)) => par_cmp(cx, span, self_f, other_fs),
+                Some((span, self_f, other_fs)) => {
+                    let opposite = if less { "Greater" } else { "Less" };
+                    par_cmp(cx, span, self_f, other_fs, opposite)
+                },
                 None => cx.expr_bool(span, inclusive)
             }
         },
diff --git a/src/test/compile-fail/derives-span-PartialOrd-enum-struct-variant.rs b/src/test/compile-fail/derives-span-PartialOrd-enum-struct-variant.rs
index 37e638c0553..a5df717e06b 100644
--- a/src/test/compile-fail/derives-span-PartialOrd-enum-struct-variant.rs
+++ b/src/test/compile-fail/derives-span-PartialOrd-enum-struct-variant.rs
@@ -17,7 +17,6 @@ struct Error;
 enum Enum {
    A {
      x: Error //~ ERROR
-//~^ ERROR
    }
 }
 
diff --git a/src/test/compile-fail/derives-span-PartialOrd-enum.rs b/src/test/compile-fail/derives-span-PartialOrd-enum.rs
index da1281fc1c1..3411d2f3119 100644
--- a/src/test/compile-fail/derives-span-PartialOrd-enum.rs
+++ b/src/test/compile-fail/derives-span-PartialOrd-enum.rs
@@ -17,7 +17,6 @@ struct Error;
 enum Enum {
    A(
      Error //~ ERROR
-//~^ ERROR
      )
 }
 
diff --git a/src/test/compile-fail/derives-span-PartialOrd-struct.rs b/src/test/compile-fail/derives-span-PartialOrd-struct.rs
index fcc0593ab5e..1feadc2fd83 100644
--- a/src/test/compile-fail/derives-span-PartialOrd-struct.rs
+++ b/src/test/compile-fail/derives-span-PartialOrd-struct.rs
@@ -16,7 +16,6 @@ struct Error;
 #[derive(PartialOrd,PartialEq)]
 struct Struct {
     x: Error //~ ERROR
-//~^ ERROR
 }
 
 fn main() {}
diff --git a/src/test/compile-fail/derives-span-PartialOrd-tuple-struct.rs b/src/test/compile-fail/derives-span-PartialOrd-tuple-struct.rs
index 24f75213e3f..9db0fed2d9e 100644
--- a/src/test/compile-fail/derives-span-PartialOrd-tuple-struct.rs
+++ b/src/test/compile-fail/derives-span-PartialOrd-tuple-struct.rs
@@ -16,7 +16,6 @@ struct Error;
 #[derive(PartialOrd,PartialEq)]
 struct Struct(
     Error //~ ERROR
-//~^ ERROR
 );
 
 fn main() {}
diff --git a/src/test/compile-fail/range_traits-1.rs b/src/test/compile-fail/range_traits-1.rs
index 434ad3c4f07..32f9b83b6e2 100644
--- a/src/test/compile-fail/range_traits-1.rs
+++ b/src/test/compile-fail/range_traits-1.rs
@@ -15,27 +15,21 @@ struct AllTheRanges {
     a: Range<usize>,
     //~^ ERROR PartialOrd
     //~^^ ERROR Ord
-    //~^^^ the trait bound
     b: RangeTo<usize>,
     //~^ ERROR PartialOrd
     //~^^ ERROR Ord
-    //~^^^ no method named `partial_cmp`
     c: RangeFrom<usize>,
     //~^ ERROR PartialOrd
     //~^^ ERROR Ord
-    //~^^^ the trait bound
     d: RangeFull,
     //~^ ERROR PartialOrd
     //~^^ ERROR Ord
-    //~^^^ no method named `partial_cmp`
     e: RangeInclusive<usize>,
     //~^ ERROR PartialOrd
     //~^^ ERROR Ord
-    //~^^^ the trait bound
     f: RangeToInclusive<usize>,
     //~^ ERROR PartialOrd
     //~^^ ERROR Ord
-    //~^^^ no method named `partial_cmp`
 }
 
 fn main() {}