Skip to content

Commit 6805e5a

Browse files
committed
Update comments to UFCS style
1 parent 98e3e82 commit 6805e5a

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/libsyntax_ext/deriving/cmp/partial_ord.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use deriving::{path_local, pathvec_std, path_std};
1414
use deriving::generic::*;
1515
use deriving::generic::ty::*;
1616

17-
use syntax::ast::{self, BinOpKind, Expr, MetaItem, Ident};
17+
use syntax::ast::{self, BinOpKind, Expr, MetaItem};
1818
use syntax::ext::base::{Annotatable, ExtCtxt};
1919
use syntax::ext::build::AstBuilder;
2020
use syntax::ptr::P;
@@ -231,32 +231,45 @@ fn cs_op(less: bool,
231231
// `ast::lt`
232232
//
233233
// ```
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+
// )
236242
// == Ordering::Less
237243
// ```
238244
//
239245
// and for op ==
240246
// `ast::le`
241247
//
242248
// ```
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+
// )
245257
// != Ordering::Greater
246258
// ```
247259
//
248260
// The optimiser should remove the redundancy. We explicitly
249261
// get use the binops to avoid auto-deref dereferencing too many
250262
// layers of pointers, if the type includes pointers.
251263

252-
// `self.fi.partial_cmp(other.fi).unwrap_or(Ordering::Equal)`
264+
// `Option::unwrap_or(PartialOrd::partial_cmp(self.fi, other.fi), Ordering::Equal)`
253265
let par_cmp = par_cmp(cx, span, self_f, other_fs, "Equal");
254266

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)])
260273
},
261274
|cx, args| {
262275
match args {

0 commit comments

Comments
 (0)