diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-12-09 09:24:51 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-12-09 09:24:51 -0800 |
| commit | 2a244ce7f40fdbb66052545cda8de8d4d2582e2a (patch) | |
| tree | e7d466dbf2d9ee1c24cae4a629e98f2e0616a349 /src/libsyntax | |
| parent | d0ad3c7f933d575d3700d8f5124e5474dfcdbd63 (diff) | |
| parent | 8dcdd1e76a6524de7da8423bc9f224fe8a822bc8 (diff) | |
| download | rust-2a244ce7f40fdbb66052545cda8de8d4d2582e2a.tar.gz rust-2a244ce7f40fdbb66052545cda8de8d4d2582e2a.zip | |
rollup merge of #19598: japaric/ord
cc #18755 r? @alexcrichton cc @bjz
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/deriving/cmp/totalord.rs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 83af45462ec..6900773f44d 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -66,12 +66,19 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, cx.ident_of("cmp"), cx.ident_of("Equal"))); + let cmp_path = vec![ + cx.ident_of("std"), + cx.ident_of("cmp"), + cx.ident_of("Ord"), + cx.ident_of("cmp"), + ]; + /* Builds: - let __test = self_field1.cmp(&other_field2); + let __test = ::std::cmp::Ord::cmp(&self_field1, &other_field1); if other == ::std::cmp::Ordering::Equal { - let __test = self_field2.cmp(&other_field2); + let __test = ::std::cmp::Ord::cmp(&self_field2, &other_field2); if __test == ::std::cmp::Ordering::Equal { ... } else { @@ -83,11 +90,11 @@ pub fn cs_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 == ::std::cmp::Ordering::Equal { // old @@ -95,6 +102,20 @@ pub fn cs_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, cmp_path.clone(), args) + }; + let assign = cx.stmt_let(span, false, test_id, new); let cond = cx.expr_binary(span, ast::BiEq, |
