@@ -2,8 +2,7 @@ use crate::deriving::generic::ty::*;
2
2
use crate :: deriving:: generic:: * ;
3
3
use crate :: deriving:: path_std;
4
4
5
- use rustc_ast:: ptr:: P ;
6
- use rustc_ast:: { self as ast, MetaItem } ;
5
+ use rustc_ast:: MetaItem ;
7
6
use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
8
7
use rustc_span:: symbol:: { sym, Ident } ;
9
8
use rustc_span:: Span ;
@@ -40,43 +39,25 @@ pub fn expand_deriving_ord(
40
39
trait_def. expand ( cx, mitem, item, push)
41
40
}
42
41
43
- pub fn ordering_collapsed (
44
- cx : & mut ExtCtxt < ' _ > ,
45
- span : Span ,
46
- self_arg_tags : & [ Ident ] ,
47
- ) -> P < ast:: Expr > {
48
- let lft = cx. expr_addr_of ( span, cx. expr_ident ( span, self_arg_tags[ 0 ] ) ) ;
49
- let rgt = cx. expr_addr_of ( span, cx. expr_ident ( span, self_arg_tags[ 1 ] ) ) ;
50
- let fn_cmp_path = cx. std_path ( & [ sym:: cmp, sym:: Ord , sym:: cmp] ) ;
51
- cx. expr_call_global ( span, fn_cmp_path, vec ! [ lft, rgt] )
52
- }
53
-
54
42
pub fn cs_cmp ( cx : & mut ExtCtxt < ' _ > , span : Span , substr : & Substructure < ' _ > ) -> BlockOrExpr {
55
43
let test_id = Ident :: new ( sym:: cmp, span) ;
56
- let equals_path = cx. path_global ( span, cx. std_path ( & [ sym:: cmp, sym:: Ordering , sym:: Equal ] ) ) ;
57
-
44
+ let equal_path = cx. path_global ( span, cx. std_path ( & [ sym:: cmp, sym:: Ordering , sym:: Equal ] ) ) ;
58
45
let cmp_path = cx. std_path ( & [ sym:: cmp, sym:: Ord , sym:: cmp] ) ;
59
46
60
47
// Builds:
61
48
//
62
- // match ::std::cmp::Ord::cmp(&self_field1, &other_field1) {
63
- // ::std::cmp::Ordering::Equal =>
64
- // match ::std::cmp::Ord::cmp(&self_field2, &other_field2) {
65
- // ::std::cmp::Ordering::Equal => {
66
- // ...
67
- // }
68
- // cmp => cmp
69
- // },
70
- // cmp => cmp
49
+ // match ::core::cmp::Ord::cmp(&self.x, &other.x) {
50
+ // ::std::cmp::Ordering::Equal =>
51
+ // ::core::cmp::Ord::cmp(&self.y, &other.y),
52
+ // cmp => cmp,
71
53
// }
72
- //
73
54
let expr = cs_fold (
74
55
// foldr nests the if-elses correctly, leaving the first field
75
56
// as the outermost one, and the last as the innermost.
76
57
false ,
77
58
|cx, span, old, self_expr, other_selflike_exprs| {
78
59
// match new {
79
- // ::std ::cmp::Ordering::Equal => old,
60
+ // ::core ::cmp::Ordering::Equal => old,
80
61
// cmp => cmp
81
62
// }
82
63
let new = {
@@ -90,7 +71,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
90
71
cx. expr_call_global ( span, cmp_path. clone ( ) , args)
91
72
} ;
92
73
93
- let eq_arm = cx. arm ( span, cx. pat_path ( span, equals_path . clone ( ) ) , old) ;
74
+ let eq_arm = cx. arm ( span, cx. pat_path ( span, equal_path . clone ( ) ) , old) ;
94
75
let neq_arm = cx. arm ( span, cx. pat_ident ( span, test_id) , cx. expr_ident ( span, test_id) ) ;
95
76
96
77
cx. expr_match ( span, new, vec ! [ eq_arm, neq_arm] )
@@ -110,13 +91,16 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
110
91
111
92
new
112
93
}
113
- None => cx. expr_path ( equals_path . clone ( ) ) ,
94
+ None => cx. expr_path ( equal_path . clone ( ) ) ,
114
95
} ,
115
96
Box :: new ( |cx, span, tag_tuple| {
116
97
if tag_tuple. len ( ) != 2 {
117
98
cx. span_bug ( span, "not exactly 2 arguments in `derive(Ord)`" )
118
99
} else {
119
- ordering_collapsed ( cx, span, tag_tuple)
100
+ let lft = cx. expr_addr_of ( span, cx. expr_ident ( span, tag_tuple[ 0 ] ) ) ;
101
+ let rgt = cx. expr_addr_of ( span, cx. expr_ident ( span, tag_tuple[ 1 ] ) ) ;
102
+ let fn_cmp_path = cx. std_path ( & [ sym:: cmp, sym:: Ord , sym:: cmp] ) ;
103
+ cx. expr_call_global ( span, fn_cmp_path, vec ! [ lft, rgt] )
120
104
}
121
105
} ) ,
122
106
cx,
0 commit comments