Skip to content

Commit 2a244ce

Browse files
committed
rollup merge of rust-lang#19598: japaric/ord
cc rust-lang#18755 r? @alexcrichton cc @bjz
2 parents d0ad3c7 + 8dcdd1e commit 2a244ce

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/libsyntax/ext/deriving/cmp/totalord.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,19 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
6666
cx.ident_of("cmp"),
6767
cx.ident_of("Equal")));
6868

69+
let cmp_path = vec![
70+
cx.ident_of("std"),
71+
cx.ident_of("cmp"),
72+
cx.ident_of("Ord"),
73+
cx.ident_of("cmp"),
74+
];
75+
6976
/*
7077
Builds:
7178
72-
let __test = self_field1.cmp(&other_field2);
79+
let __test = ::std::cmp::Ord::cmp(&self_field1, &other_field1);
7380
if other == ::std::cmp::Ordering::Equal {
74-
let __test = self_field2.cmp(&other_field2);
81+
let __test = ::std::cmp::Ord::cmp(&self_field2, &other_field2);
7582
if __test == ::std::cmp::Ordering::Equal {
7683
...
7784
} else {
@@ -83,18 +90,32 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
8390
8491
FIXME #6449: These `if`s could/should be `match`es.
8592
*/
86-
cs_same_method_fold(
93+
cs_fold(
8794
// foldr nests the if-elses correctly, leaving the first field
8895
// as the outermost one, and the last as the innermost.
8996
false,
90-
|cx, span, old, new| {
97+
|cx, span, old, self_f, other_fs| {
9198
// let __test = new;
9299
// if __test == ::std::cmp::Ordering::Equal {
93100
// old
94101
// } else {
95102
// __test
96103
// }
97104

105+
let new = {
106+
let other_f = match other_fs {
107+
[ref o_f] => o_f,
108+
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`"),
109+
};
110+
111+
let args = vec![
112+
cx.expr_addr_of(span, self_f),
113+
cx.expr_addr_of(span, other_f.clone()),
114+
];
115+
116+
cx.expr_call_global(span, cmp_path.clone(), args)
117+
};
118+
98119
let assign = cx.stmt_let(span, false, test_id, new);
99120

100121
let cond = cx.expr_binary(span, ast::BiEq,

src/test/run-pass/issue-18738.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(PartialEq, PartialOrd)]
11+
#[deriving(Eq, PartialEq, PartialOrd, Ord)]
1212
enum Test<'a> {
1313
Int(&'a int),
1414
Slice(&'a [u8]),
1515
}
1616

17-
#[deriving(PartialEq, PartialOrd)]
17+
#[deriving(Eq, PartialEq, PartialOrd, Ord)]
1818
struct Version {
1919
vendor_info: &'static str
2020
}
2121

22-
#[deriving(PartialEq, PartialOrd)]
22+
#[deriving(Eq, PartialEq, PartialOrd, Ord)]
2323
struct Foo(&'static str);
2424

2525
fn main() {}

0 commit comments

Comments
 (0)