diff options
| author | bors <bors@rust-lang.org> | 2014-03-23 08:36:51 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-23 08:36:51 -0700 |
| commit | 903e83889ade166bf62f1ee74df8bf8331ea17d1 (patch) | |
| tree | 2d2c838f7adc52628632948a8b37820c4f03ed75 /src/libsyntax | |
| parent | cafb7ed6f671a0102c4df9abad43b747c00f5cdf (diff) | |
| parent | f6db0ef9464a17fa6e547e755b1b5dfa09af9499 (diff) | |
| download | rust-903e83889ade166bf62f1ee74df8bf8331ea17d1.tar.gz rust-903e83889ade166bf62f1ee74df8bf8331ea17d1.zip | |
auto merge of #13102 : huonw/rust/totaleq-deriving, r=thestinger
std: remove the `equals` method from `TotalEq`. `TotalEq` is now just an assertion about the `Eq` impl of a type (i.e. `==` is a total equality if a type implements `TotalEq`) so the extra method is just confusing. Also, a new method magically appeared as a hack to allow deriving to assert that the contents of a struct/enum are also TotalEq, because the deriving infrastructure makes it very hard to do anything but create a trait method. (You didn't hear about this horrible work-around from me :(.)
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/deriving/cmp/totaleq.rs | 23 | ||||
| -rw-r--r-- | src/libsyntax/util/interner.rs | 6 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index ffabed95db5..33512b3df5e 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -19,9 +19,18 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, mitem: @MetaItem, item: @Item, push: |@Item|) { - fn cs_equals(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr { - cs_and(|cx, span, _, _| cx.expr_bool(span, false), - cx, span, substr) + fn cs_total_eq_assert(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr { + cs_same_method(|cx, span, exprs| { + // create `a.<method>(); b.<method>(); c.<method>(); ...` + // (where method is `assert_receiver_is_total_eq`) + let stmts = exprs.move_iter().map(|e| cx.stmt_expr(e)).collect(); + let block = cx.block(span, stmts, None); + cx.expr_block(block) + }, + |cx, sp, _, _| cx.span_bug(sp, "non matching enums in deriving(TotalEq)?"), + cx, + span, + substr) } let trait_def = TraitDef { @@ -32,14 +41,14 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, generics: LifetimeBounds::empty(), methods: vec!( MethodDef { - name: "equals", + name: "assert_receiver_is_total_eq", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), - args: vec!(borrowed_self()), - ret_ty: Literal(Path::new(vec!("bool"))), + args: vec!(), + ret_ty: nil_ty(), inline: true, const_nonmatching: true, - combine_substructure: cs_equals + combine_substructure: cs_total_eq_assert } ) }; diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 9b73cf533a7..969b9f81785 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -95,11 +95,7 @@ pub struct RcStr { priv string: Rc<~str>, } -impl TotalEq for RcStr { - fn equals(&self, other: &RcStr) -> bool { - self.as_slice().equals(&other.as_slice()) - } -} +impl TotalEq for RcStr {} impl TotalOrd for RcStr { fn cmp(&self, other: &RcStr) -> Ordering { |
