@@ -14,7 +14,7 @@ use deriving::{path_local, pathvec_std, path_std};
14
14
use deriving:: generic:: * ;
15
15
use deriving:: generic:: ty:: * ;
16
16
17
- use syntax:: ast:: { self , BinOpKind , Expr , MetaItem , Ident } ;
17
+ use syntax:: ast:: { self , BinOpKind , Expr , MetaItem } ;
18
18
use syntax:: ext:: base:: { Annotatable , ExtCtxt } ;
19
19
use syntax:: ext:: build:: AstBuilder ;
20
20
use syntax:: ptr:: P ;
@@ -231,32 +231,45 @@ fn cs_op(less: bool,
231
231
// `ast::lt`
232
232
//
233
233
// ```
234
- // self.f1.partial_cmp(other.f1).unwrap_or(Ordering::Equal)
235
- // .then_with(|| self.f2.partial_cmp(other.f2).unwrap_or(Ordering::Equal))
234
+ // Ordering::then_with(
235
+ // Option::unwrap_or(
236
+ // PartialOrd::partial_cmp(self.f1, other.f1), Ordering::Equal)
237
+ // ),
238
+ // Option::unwrap_or(
239
+ // PartialOrd::partial_cmp(self.f2, other.f2), Ordering::Greater)
240
+ // )
241
+ // )
236
242
// == Ordering::Less
237
243
// ```
238
244
//
239
245
// and for op ==
240
246
// `ast::le`
241
247
//
242
248
// ```
243
- // self.f1.partial_cmp(other.f1).unwrap_or(Ordering::Equal)
244
- // .then_with(|| self.f2.partial_cmp(other.f2).unwrap_or(Ordering::Equal))
249
+ // Ordering::then_with(
250
+ // Option::unwrap_or(
251
+ // PartialOrd::partial_cmp(self.f1, other.f1), Ordering::Equal)
252
+ // ),
253
+ // Option::unwrap_or(
254
+ // PartialOrd::partial_cmp(self.f2, other.f2), Ordering::Greater)
255
+ // )
256
+ // )
245
257
// != Ordering::Greater
246
258
// ```
247
259
//
248
260
// The optimiser should remove the redundancy. We explicitly
249
261
// get use the binops to avoid auto-deref dereferencing too many
250
262
// layers of pointers, if the type includes pointers.
251
263
252
- // `self.fi.partial_cmp( other.fi).unwrap_or( Ordering::Equal)`
264
+ // `Option::unwrap_or(PartialOrd::partial_cmp( self.fi, other.fi), Ordering::Equal)`
253
265
let par_cmp = par_cmp ( cx, span, self_f, other_fs, "Equal" ) ;
254
266
255
- // `self.fi.partial_cmp(other.fi).unwrap_or(Ordering::Equal).then_with(...)`
256
- cx. expr_method_call ( span,
257
- par_cmp,
258
- Ident :: from_str ( "then_with" ) ,
259
- vec ! [ cx. lambda0( span, subexpr) ] )
267
+ // `Ordering::then_with(Option::unwrap_or(..), ..)`
268
+ let then_with_path = cx. expr_path ( cx. path_global ( span,
269
+ cx. std_path ( & [ "cmp" ,
270
+ "Ordering" ,
271
+ "then_with" ] ) ) ) ;
272
+ cx. expr_call ( span, then_with_path, vec ! [ par_cmp, cx. lambda0( span, subexpr) ] )
260
273
} ,
261
274
|cx, args| {
262
275
match args {
0 commit comments