diff options
| author | varkor <github@varkor.com> | 2018-04-11 13:19:10 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-04-11 13:19:10 +0100 |
| commit | 59ee333a0e952eb7b91d86447b489aa12efd0bd3 (patch) | |
| tree | d7d1d75f82910d04bd1c2f9c65a0538544407cdf /src/libsyntax_ext | |
| parent | 4b9b70c394e7f341b4016fce4cbf763d404b26f9 (diff) | |
| download | rust-59ee333a0e952eb7b91d86447b489aa12efd0bd3.tar.gz rust-59ee333a0e952eb7b91d86447b489aa12efd0bd3.zip | |
Fix derive(PartialOrd) implementation
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/partial_ord.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index 92183c58eb2..2f66616d73f 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -214,14 +214,18 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, span: Span, substr: &Substru _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"), }; - let cmp = cx.expr_binary(span, op, self_f.clone(), other_f.clone()); + let strict_ineq = cx.expr_binary(span, op, self_f.clone(), other_f.clone()); - let not_cmp = cx.expr_unary(span, - ast::UnOp::Not, - cx.expr_binary(span, op, other_f.clone(), self_f)); + let deleg_cmp = if !equal { + cx.expr_unary(span, + ast::UnOp::Not, + cx.expr_binary(span, op, other_f.clone(), self_f)) + } else { + cx.expr_binary(span, BinOpKind::Eq, self_f, other_f.clone()) + }; - let and = cx.expr_binary(span, BinOpKind::And, not_cmp, subexpr); - cx.expr_binary(span, BinOpKind::Or, cmp, and) + let and = cx.expr_binary(span, BinOpKind::And, deleg_cmp, subexpr); + cx.expr_binary(span, BinOpKind::Or, strict_ineq, and) }, cx.expr_bool(span, equal), Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| { |
