Skip to content

Commit 6330bf2

Browse files
committed
Fix handling of None
1 parent 6eb4f0f commit 6330bf2

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/libsyntax_ext/deriving/cmp/partial_ord.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ fn cs_op(less: bool,
213213
Ident::from_str("partial_cmp"),
214214
vec![cx.expr_addr_of(span, other_f.clone())]);
215215

216-
let default = ordering_path(cx, if less { "Greater" } else { "Less" });
217-
// `_.unwrap_or(Ordering::Greater/Less)`
216+
let default = ordering_path(cx, "Equal");
217+
// `_.unwrap_or(Ordering::Equal)`
218218
cx.expr_method_call(span, cmp, Ident::from_str("unwrap_or"), vec![default])
219219
};
220220

@@ -225,28 +225,28 @@ fn cs_op(less: bool,
225225
// `ast::lt`
226226
//
227227
// ```
228-
// self.f1.partial_cmp(other.f1).unwrap_or(Ordering::Greater)
229-
// .then_with(|| self.f2.partial_cmp(other.f2).unwrap_or(Ordering::Greater))
228+
// self.f1.partial_cmp(other.f1).unwrap_or(Ordering::Equal)
229+
// .then_with(|| self.f2.partial_cmp(other.f2).unwrap_or(Ordering::Equal))
230230
// == Ordering::Less
231231
// ```
232232
//
233233
// and for op ==
234234
// `ast::le`
235235
//
236236
// ```
237-
// self.f1.partial_cmp(other.f1).unwrap_or(Ordering::Greater)
238-
// .then_with(|| self.f2.partial_cmp(other.f2).unwrap_or(Ordering::Greater))
237+
// self.f1.partial_cmp(other.f1).unwrap_or(Ordering::Equal)
238+
// .then_with(|| self.f2.partial_cmp(other.f2).unwrap_or(Ordering::Equal))
239239
// != Ordering::Greater
240240
// ```
241241
//
242242
// The optimiser should remove the redundancy. We explicitly
243243
// get use the binops to avoid auto-deref dereferencing too many
244244
// layers of pointers, if the type includes pointers.
245245

246-
// `self.fi.partial_cmp(other.fi).unwrap_or(Ordering::Greater/Less)`
246+
// `self.fi.partial_cmp(other.fi).unwrap_or(Ordering::Equal)`
247247
let par_cmp = par_cmp(cx, span, self_f, other_fs);
248248

249-
// `self.fi.partial_cmp(other.fi).unwrap_or(Ordering::Greater/Less).then_with(...)`
249+
// `self.fi.partial_cmp(other.fi).unwrap_or(Ordering::Equal).then_with(...)`
250250
cx.expr_method_call(span,
251251
par_cmp,
252252
Ident::from_str("then_with"),
@@ -255,7 +255,7 @@ fn cs_op(less: bool,
255255
|cx, args| {
256256
match args {
257257
Some((span, self_f, other_fs)) => par_cmp(cx, span, self_f, other_fs),
258-
None => ordering_path(cx, if less { "Less" } else { "Equal" })
258+
None => cx.expr_bool(span, inclusive)
259259
}
260260
},
261261
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
@@ -276,8 +276,8 @@ fn cs_op(less: bool,
276276
substr);
277277

278278
match *substr.fields {
279-
EnumMatching(..) |
280-
Struct(..) => {
279+
EnumMatching(.., ref all_fields) |
280+
Struct(.., ref all_fields) if !all_fields.is_empty() => {
281281
let ordering = ordering_path(cx, if less ^ inclusive { "Less" } else { "Greater" });
282282
let comp_op = if inclusive { BinOpKind::Ne } else { BinOpKind::Eq };
283283

0 commit comments

Comments
 (0)