@@ -22,15 +22,15 @@ pub fn expand_deriving_ord(cx: @ExtCtxt,
22
22
mitem : @meta_item ,
23
23
in_items: ~[ @item] ) -> ~[ @item] {
24
24
macro_rules! md (
25
- ( $name: expr, $func : expr, $op : expr) => {
25
+ ( $name: expr, $op : expr, $equal : expr) => {
26
26
MethodDef {
27
27
name : $name,
28
28
generics : LifetimeBounds :: empty( ) ,
29
29
explicit_self : borrowed_explicit_self( ) ,
30
30
args : ~[ borrowed_self( ) ] ,
31
31
ret_ty : Literal ( Path :: new( ~[ "bool" ] ) ) ,
32
32
const_nonmatching : false ,
33
- combine_substructure : |cx, span, substr | $func ( $op, cx, span, substr)
33
+ combine_substructure : |cx, span, substr | cs_op ( $op, $equal , cx, span, substr)
34
34
}
35
35
}
36
36
) ;
@@ -40,17 +40,17 @@ pub fn expand_deriving_ord(cx: @ExtCtxt,
40
40
additional_bounds : ~[ ] ,
41
41
generics : LifetimeBounds :: empty ( ) ,
42
42
methods : ~[
43
- md ! ( "lt" , cs_strict , true ) ,
44
- md ! ( "le" , cs_nonstrict , true ) , // inverse operation
45
- md ! ( "gt" , cs_strict , false ) ,
46
- md ! ( "ge" , cs_nonstrict , false )
43
+ md ! ( "lt" , true , false ) ,
44
+ md ! ( "le" , true , true ) ,
45
+ md ! ( "gt" , false , false ) ,
46
+ md ! ( "ge" , false , true )
47
47
]
48
48
} ;
49
49
trait_def. expand ( cx, span, mitem, in_items)
50
50
}
51
51
52
52
/// Strict inequality.
53
- fn cs_strict ( less: bool, cx: @ExtCtxt , span: span, substr: & Substructure ) -> @expr {
53
+ fn cs_op ( less: bool , equal : bool , cx: @ExtCtxt , span: span, substr: & Substructure ) -> @expr {
54
54
let op = if less { ast:: lt} else { ast:: gt} ;
55
55
cs_fold (
56
56
false , // need foldr,
@@ -81,16 +81,15 @@ fn cs_strict(less: bool, cx: @ExtCtxt, span: span, substr: &Substructure) -> @ex
81
81
cx. expr_deref ( span, self_f) ,
82
82
cx. expr_deref ( span, other_f) ) ;
83
83
84
- let not_cmp = cx. expr_binary ( span, op ,
85
- cx. expr_deref ( span, other_f ) ,
86
- cx. expr_deref ( span, self_f ) ) ;
87
- let not_cmp = cx. expr_unary ( span, ast :: not , not_cmp ) ;
84
+ let not_cmp = cx. expr_unary ( span, ast :: not ,
85
+ cx. expr_binary ( span, op ,
86
+ cx. expr_deref ( span, other_f ) ,
87
+ cx. expr_deref ( span, self_f ) ) ) ;
88
88
89
- let and = cx. expr_binary ( span, ast:: and,
90
- not_cmp, subexpr) ;
89
+ let and = cx. expr_binary ( span, ast:: and, not_cmp, subexpr) ;
91
90
cx. expr_binary ( span, ast:: or, cmp, and)
92
91
} ,
93
- cx. expr_bool ( span, false ) ,
92
+ cx. expr_bool ( span, equal ) ,
94
93
|cx, span, args, _| {
95
94
// nonmatching enums, order by the order the variants are
96
95
// written
@@ -108,19 +107,3 @@ fn cs_strict(less: bool, cx: @ExtCtxt, span: span, substr: &Substructure) -> @ex
108
107
} ,
109
108
cx, span, substr)
110
109
}
111
-
112
- fn cs_nonstrict( less: bool, cx: @ExtCtxt , span: span, substr: & Substructure ) -> @expr {
113
- // Example: ge becomes !(*self < *other), le becomes !(*self > *other)
114
-
115
- let inverse_op = if less { ast:: gt} else { ast:: lt} ;
116
- match substr. self_args {
117
- [ self_, other] => {
118
- let inverse_cmp = cx. expr_binary ( span, inverse_op,
119
- cx. expr_deref ( span, self_) ,
120
- cx. expr_deref ( span, other) ) ;
121
-
122
- cx. expr_unary ( span, ast:: not, inverse_cmp)
123
- }
124
- _ => cx. span_bug ( span, "Not exactly 2 arguments in `deriving(Ord)`" )
125
- }
126
- }
0 commit comments