about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-06 08:06:50 +0000
committerbors <bors@rust-lang.org>2014-11-06 08:06:50 +0000
commite84e7a00ddec76570bbaa9afea385d544f616814 (patch)
tree5757b1eec689ab03459c9f2518cc602284c44733 /src/libsyntax
parent0e2f9b948564708085373fc28d91b4524c821fa3 (diff)
parent11f4baeafb83459befd0196b2b82cda7ed5ea2f1 (diff)
downloadrust-e84e7a00ddec76570bbaa9afea385d544f616814.tar.gz
rust-e84e7a00ddec76570bbaa9afea385d544f616814.zip
auto merge of #18467 : japaric/rust/eq, r=alexcrichton
`eq`, `ne`, `cmp`, etc methods now require one less level of indirection when dealing with `&str`/`&[T]`

``` rust
"foo".ne(&"bar") -> "foo".ne("bar")
slice.cmp(&another_slice) -> slice.cmp(another_slice)
// slice and another_slice have type `&[T]`
```

[breaking-change]
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/deriving/cmp/eq.rs36
-rw-r--r--src/libsyntax/util/interner.rs6
2 files changed, 37 insertions, 5 deletions
diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs
index a27016fde61..c3b1a52925d 100644
--- a/src/libsyntax/ext/deriving/cmp/eq.rs
+++ b/src/libsyntax/ext/deriving/cmp/eq.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use ast::{MetaItem, Item, Expr};
+use ast::{MetaItem, Item, Expr, mod};
 use codemap::Span;
 use ext::base::ExtCtxt;
 use ext::build::AstBuilder;
@@ -25,12 +25,38 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
     // structures are equal if all fields are equal, and non equal, if
     // any fields are not equal or if the enum variants are different
     fn cs_eq(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
-        cs_and(|cx, span, _, _| cx.expr_bool(span, false),
-                                 cx, span, substr)
+        cs_fold(
+            true,  // use foldl
+            |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)`")
+                };
+
+                let eq = cx.expr_binary(span, ast::BiEq, self_f, other_f.clone());
+
+                cx.expr_binary(span, ast::BiAnd, subexpr, eq)
+            },
+            cx.expr_bool(span, true),
+            |cx, span, _, _| cx.expr_bool(span, false),
+            cx, span, substr)
     }
     fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
-        cs_or(|cx, span, _, _| cx.expr_bool(span, true),
-              cx, span, substr)
+        cs_fold(
+            true,  // use foldl
+            |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)`")
+                };
+
+                let eq = cx.expr_binary(span, ast::BiNe, self_f, other_f.clone());
+
+                cx.expr_binary(span, ast::BiOr, subexpr, eq)
+            },
+            cx.expr_bool(span, false),
+            |cx, span, _, _| cx.expr_bool(span, true),
+            cx, span, substr)
     }
 
     macro_rules! md (
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs
index 105118ff76a..e6c98a9e3d0 100644
--- a/src/libsyntax/util/interner.rs
+++ b/src/libsyntax/util/interner.rs
@@ -97,9 +97,15 @@ pub struct RcStr {
 impl Eq for RcStr {}
 
 impl Ord for RcStr {
+    // NOTE(stage0): remove method after a snapshot
+    #[cfg(stage0)]
     fn cmp(&self, other: &RcStr) -> Ordering {
         self.as_slice().cmp(&other.as_slice())
     }
+    #[cfg(not(stage0))]  // NOTE(stage0): remove cfg after a snapshot
+    fn cmp(&self, other: &RcStr) -> Ordering {
+        self.as_slice().cmp(other.as_slice())
+    }
 }
 
 impl Str for RcStr {