@@ -27,40 +27,70 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
27
27
// structures are equal if all fields are equal, and non equal, if
28
28
// any fields are not equal or if the enum variants are different
29
29
fn cs_eq ( cx : & mut ExtCtxt , span : Span , substr : & Substructure ) -> P < Expr > {
30
- cs_fold ( true , // use foldl
31
- |cx, span, subexpr, self_f, other_fs| {
32
- let other_f = match ( other_fs. len ( ) , other_fs. get ( 0 ) ) {
33
- ( 1 , Some ( o_f) ) => o_f,
34
- _ => cx. span_bug ( span, "not exactly 2 arguments in `derive(PartialEq)`" ) ,
35
- } ;
30
+ cs_fold1 ( true , // use foldl
31
+ |cx, span, subexpr, self_f, other_fs| {
32
+ let other_f = match ( other_fs. len ( ) , other_fs. get ( 0 ) ) {
33
+ ( 1 , Some ( o_f) ) => o_f,
34
+ _ => cx. span_bug ( span, "not exactly 2 arguments in `derive(PartialEq)`" ) ,
35
+ } ;
36
36
37
- let eq = cx. expr_binary ( span, BinOpKind :: Eq , self_f, other_f. clone ( ) ) ;
37
+ let eq = cx. expr_binary ( span, BinOpKind :: Eq , self_f, other_f. clone ( ) ) ;
38
38
39
- cx. expr_binary ( span, BinOpKind :: And , subexpr, eq)
40
- } ,
41
- cx. expr_bool ( span, true ) ,
42
- Box :: new ( |cx, span, _, _| cx. expr_bool ( span, false ) ) ,
43
- cx,
44
- span,
45
- substr)
39
+ cx. expr_binary ( span, BinOpKind :: And , subexpr, eq)
40
+ } ,
41
+ |cx, args| {
42
+ match args {
43
+ Some ( ( span, self_f, other_fs) ) => {
44
+ // Special-case the base case to generate cleaner code.
45
+ let other_f = match ( other_fs. len ( ) , other_fs. get ( 0 ) ) {
46
+ ( 1 , Some ( o_f) ) => o_f,
47
+ _ => {
48
+ cx. span_bug ( span, "not exactly 2 arguments in `derive(PartialEq)`" )
49
+ }
50
+ } ;
51
+
52
+ cx. expr_binary ( span, BinOpKind :: Eq , self_f, other_f. clone ( ) )
53
+ }
54
+ None => cx. expr_bool ( span, true ) ,
55
+ }
56
+ } ,
57
+ Box :: new ( |cx, span, _, _| cx. expr_bool ( span, false ) ) ,
58
+ cx,
59
+ span,
60
+ substr)
46
61
}
47
62
fn cs_ne ( cx : & mut ExtCtxt , span : Span , substr : & Substructure ) -> P < Expr > {
48
- cs_fold ( true , // use foldl
49
- |cx, span, subexpr, self_f, other_fs| {
50
- let other_f = match ( other_fs. len ( ) , other_fs. get ( 0 ) ) {
51
- ( 1 , Some ( o_f) ) => o_f,
52
- _ => cx. span_bug ( span, "not exactly 2 arguments in `derive(PartialEq)`" ) ,
53
- } ;
63
+ cs_fold1 ( true , // use foldl
64
+ |cx, span, subexpr, self_f, other_fs| {
65
+ let other_f = match ( other_fs. len ( ) , other_fs. get ( 0 ) ) {
66
+ ( 1 , Some ( o_f) ) => o_f,
67
+ _ => cx. span_bug ( span, "not exactly 2 arguments in `derive(PartialEq)`" ) ,
68
+ } ;
69
+
70
+ let eq = cx. expr_binary ( span, BinOpKind :: Ne , self_f, other_f. clone ( ) ) ;
54
71
55
- let eq = cx. expr_binary ( span, BinOpKind :: Ne , self_f, other_f. clone ( ) ) ;
72
+ cx. expr_binary ( span, BinOpKind :: Or , subexpr, eq)
73
+ } ,
74
+ |cx, args| {
75
+ match args {
76
+ Some ( ( span, self_f, other_fs) ) => {
77
+ // Special-case the base case to generate cleaner code.
78
+ let other_f = match ( other_fs. len ( ) , other_fs. get ( 0 ) ) {
79
+ ( 1 , Some ( o_f) ) => o_f,
80
+ _ => {
81
+ cx. span_bug ( span, "not exactly 2 arguments in `derive(PartialEq)`" )
82
+ }
83
+ } ;
56
84
57
- cx. expr_binary ( span, BinOpKind :: Or , subexpr, eq)
58
- } ,
59
- cx. expr_bool ( span, false ) ,
60
- Box :: new ( |cx, span, _, _| cx. expr_bool ( span, true ) ) ,
61
- cx,
62
- span,
63
- substr)
85
+ cx. expr_binary ( span, BinOpKind :: Ne , self_f, other_f. clone ( ) )
86
+ }
87
+ None => cx. expr_bool ( span, false ) ,
88
+ }
89
+ } ,
90
+ Box :: new ( |cx, span, _, _| cx. expr_bool ( span, true ) ) ,
91
+ cx,
92
+ span,
93
+ substr)
64
94
}
65
95
66
96
macro_rules! md {
0 commit comments