@@ -15,6 +15,7 @@ use deriving::generic::*;
15
15
use deriving:: generic:: ty:: * ;
16
16
17
17
use syntax:: ast:: { self , BinOpKind , Expr , MetaItem } ;
18
+ use syntax:: codemap:: respan;
18
19
use syntax:: ext:: base:: { Annotatable , ExtCtxt } ;
19
20
use syntax:: ext:: build:: AstBuilder ;
20
21
use syntax:: ptr:: P ;
@@ -123,7 +124,7 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt,
123
124
}
124
125
125
126
pub fn cs_partial_cmp ( cx : & mut ExtCtxt , span : Span , substr : & Substructure ) -> P < Expr > {
126
- let test_id = cx. ident_of ( "__cmp " ) ;
127
+ let test_id = cx. ident_of ( "cmp " ) ;
127
128
let ordering = cx. path_global ( span, cx. std_path ( & [ "cmp" , "Ordering" , "Equal" ] ) ) ;
128
129
let ordering_expr = cx. expr_path ( ordering. clone ( ) ) ;
129
130
let equals_expr = cx. expr_some ( span, ordering_expr) ;
@@ -138,18 +139,19 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<
138
139
// ::std::option::Option::Some(::std::cmp::Ordering::Equal) => {
139
140
// ...
140
141
// }
141
- // __cmp => __cmp
142
+ // cmp @ _ => cmp
142
143
// },
143
- // __cmp => __cmp
144
+ // cmp @ _ => cmp
144
145
// }
145
146
//
147
+ // We use the `cmp @ _` form so it will not conflict with constants named `cmp`
146
148
cs_fold ( // foldr nests the if-elses correctly, leaving the first field
147
149
// as the outermost one, and the last as the innermost.
148
150
false ,
149
151
|cx, span, old, self_f, other_fs| {
150
152
// match new {
151
153
// Some(::std::cmp::Ordering::Equal) => old,
152
- // __cmp => __cmp
154
+ // cmp @ _ => cmp
153
155
// }
154
156
155
157
let new = {
@@ -169,8 +171,11 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<
169
171
let eq_arm = cx. arm ( span,
170
172
vec ! [ cx. pat_some( span, cx. pat_path( span, ordering. clone( ) ) ) ] ,
171
173
old) ;
174
+ // cmp @ _
175
+ let kind = ast:: PatKind :: Ident ( ast:: BindingMode :: ByValue ( ast:: Mutability :: Immutable ) ,
176
+ respan ( span, test_id) , Some ( cx. pat_wild ( span) ) ) ;
172
177
let neq_arm = cx. arm ( span,
173
- vec ! [ cx. pat_ident ( span, test_id ) ] ,
178
+ vec ! [ cx. pat ( span, kind ) ] ,
174
179
cx. expr_ident ( span, test_id) ) ;
175
180
176
181
cx. expr_match ( span, new, vec ! [ eq_arm, neq_arm] )
0 commit comments