@@ -2,8 +2,7 @@ use crate::deriving::generic::ty::*;
22use crate :: deriving:: generic:: * ;
33use crate :: deriving:: path_std;
44
5- use rustc_ast:: ptr:: P ;
6- use rustc_ast:: { self as ast, MetaItem } ;
5+ use rustc_ast:: MetaItem ;
76use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
87use rustc_span:: symbol:: { sym, Ident } ;
98use rustc_span:: Span ;
@@ -40,43 +39,25 @@ pub fn expand_deriving_ord(
4039 trait_def. expand ( cx, mitem, item, push)
4140}
4241
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-
5442pub fn cs_cmp ( cx : & mut ExtCtxt < ' _ > , span : Span , substr : & Substructure < ' _ > ) -> BlockOrExpr {
5543 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 ] ) ) ;
5845 let cmp_path = cx. std_path ( & [ sym:: cmp, sym:: Ord , sym:: cmp] ) ;
5946
6047 // Builds:
6148 //
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,
7153 // }
72- //
7354 let expr = cs_fold (
7455 // foldr nests the if-elses correctly, leaving the first field
7556 // as the outermost one, and the last as the innermost.
7657 false ,
7758 |cx, span, old, self_expr, other_selflike_exprs| {
7859 // match new {
79- // ::std ::cmp::Ordering::Equal => old,
60+ // ::core ::cmp::Ordering::Equal => old,
8061 // cmp => cmp
8162 // }
8263 let new = {
@@ -90,7 +71,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
9071 cx. expr_call_global ( span, cmp_path. clone ( ) , args)
9172 } ;
9273
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) ;
9475 let neq_arm = cx. arm ( span, cx. pat_ident ( span, test_id) , cx. expr_ident ( span, test_id) ) ;
9576
9677 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
11091
11192 new
11293 }
113- None => cx. expr_path ( equals_path . clone ( ) ) ,
94+ None => cx. expr_path ( equal_path . clone ( ) ) ,
11495 } ,
11596 Box :: new ( |cx, span, tag_tuple| {
11697 if tag_tuple. len ( ) != 2 {
11798 cx. span_bug ( span, "not exactly 2 arguments in `derive(Ord)`" )
11899 } 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] )
120104 }
121105 } ) ,
122106 cx,
0 commit comments