Skip to content

Commit 59ee333

Browse files
committed
Fix derive(PartialOrd) implementation
1 parent 4b9b70c commit 59ee333

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/libsyntax_ext/deriving/cmp/partial_ord.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,18 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, span: Span, substr: &Substru
214214
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
215215
};
216216

217-
let cmp = cx.expr_binary(span, op, self_f.clone(), other_f.clone());
217+
let strict_ineq = cx.expr_binary(span, op, self_f.clone(), other_f.clone());
218218

219-
let not_cmp = cx.expr_unary(span,
220-
ast::UnOp::Not,
221-
cx.expr_binary(span, op, other_f.clone(), self_f));
219+
let deleg_cmp = if !equal {
220+
cx.expr_unary(span,
221+
ast::UnOp::Not,
222+
cx.expr_binary(span, op, other_f.clone(), self_f))
223+
} else {
224+
cx.expr_binary(span, BinOpKind::Eq, self_f, other_f.clone())
225+
};
222226

223-
let and = cx.expr_binary(span, BinOpKind::And, not_cmp, subexpr);
224-
cx.expr_binary(span, BinOpKind::Or, cmp, and)
227+
let and = cx.expr_binary(span, BinOpKind::And, deleg_cmp, subexpr);
228+
cx.expr_binary(span, BinOpKind::Or, strict_ineq, and)
225229
},
226230
cx.expr_bool(span, equal),
227231
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {

0 commit comments

Comments
 (0)