@@ -3,7 +3,7 @@ use crate::deriving::generic::*;
3
3
use crate :: deriving:: path_std;
4
4
5
5
use rustc_ast:: ptr:: P ;
6
- use rustc_ast:: { self as ast, Expr , MetaItem } ;
6
+ use rustc_ast:: { self as ast, MetaItem } ;
7
7
use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
8
8
use rustc_span:: symbol:: { sym, Ident } ;
9
9
use rustc_span:: Span ;
@@ -51,7 +51,7 @@ pub fn ordering_collapsed(
51
51
cx. expr_call_global ( span, fn_cmp_path, vec ! [ lft, rgt] )
52
52
}
53
53
54
- pub fn cs_cmp ( cx : & mut ExtCtxt < ' _ > , span : Span , substr : & Substructure < ' _ > ) -> P < Expr > {
54
+ pub fn cs_cmp ( cx : & mut ExtCtxt < ' _ > , span : Span , substr : & Substructure < ' _ > ) -> BlockOrExpr {
55
55
let test_id = Ident :: new ( sym:: cmp, span) ;
56
56
let equals_path = cx. path_global ( span, cx. std_path ( & [ sym:: cmp, sym:: Ordering , sym:: Equal ] ) ) ;
57
57
@@ -70,7 +70,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<
70
70
// cmp => cmp
71
71
// }
72
72
//
73
- cs_fold (
73
+ let expr = cs_fold (
74
74
// foldr nests the if-elses correctly, leaving the first field
75
75
// as the outermost one, and the last as the innermost.
76
76
false ,
@@ -79,15 +79,12 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<
79
79
// ::std::cmp::Ordering::Equal => old,
80
80
// cmp => cmp
81
81
// }
82
-
83
82
let new = {
84
83
let [ other_f] = other_fs else {
85
84
cx. span_bug ( span, "not exactly 2 arguments in `derive(Ord)`" ) ;
86
85
} ;
87
-
88
86
let args =
89
87
vec ! [ cx. expr_addr_of( span, self_f) , cx. expr_addr_of( span, other_f. clone( ) ) ] ;
90
-
91
88
cx. expr_call_global ( span, cmp_path. clone ( ) , args)
92
89
} ;
93
90
@@ -96,7 +93,21 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<
96
93
97
94
cx. expr_match ( span, new, vec ! [ eq_arm, neq_arm] )
98
95
} ,
99
- cx. expr_path ( equals_path. clone ( ) ) ,
96
+ |cx, args| match args {
97
+ Some ( ( span, self_f, other_fs) ) => {
98
+ let new = {
99
+ let [ other_f] = other_fs else {
100
+ cx. span_bug ( span, "not exactly 2 arguments in `derive(Ord)`" ) ;
101
+ } ;
102
+ let args =
103
+ vec ! [ cx. expr_addr_of( span, self_f) , cx. expr_addr_of( span, other_f. clone( ) ) ] ;
104
+ cx. expr_call_global ( span, cmp_path. clone ( ) , args)
105
+ } ;
106
+
107
+ new
108
+ }
109
+ None => cx. expr_path ( equals_path. clone ( ) ) ,
110
+ } ,
100
111
Box :: new ( |cx, span, tag_tuple| {
101
112
if tag_tuple. len ( ) != 2 {
102
113
cx. span_bug ( span, "not exactly 2 arguments in `derive(Ord)`" )
@@ -107,5 +118,6 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<
107
118
cx,
108
119
span,
109
120
substr,
110
- )
121
+ ) ;
122
+ BlockOrExpr :: new_expr ( expr)
111
123
}
0 commit comments