Skip to content

Commit 2fd68fb

Browse files
committed
Avoid regression in derive(PartialOrd) for zero-variant enums
1 parent 76ac16f commit 2fd68fb

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ pub(crate) fn expand_deriving_partial_ord(
5757
}));
5858
let (is_simple, substructure) = match item {
5959
Annotatable::Item(annitem) => match &annitem.kind {
60-
// For unit structs, the default generated code is better.
60+
// For unit structs/zero-variant enums, the default generated code is better.
6161
ItemKind::Struct(.., ast::VariantData::Unit(..)) => (false, default_substructure),
62+
ItemKind::Enum(.., enum_def) if enum_def.variants.is_empty() => {
63+
(false, default_substructure)
64+
}
6265
ItemKind::Struct(_, ast::Generics { params, .. }, _)
6366
| ItemKind::Enum(_, ast::Generics { params, .. }, _)
6467
if is_simple_candidate(params) =>

tests/ui/deriving/deriving-all-codegen.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ impl ::core::cmp::PartialOrd for Enum0 {
10161016
#[inline]
10171017
fn partial_cmp(&self, other: &Enum0)
10181018
-> ::core::option::Option<::core::cmp::Ordering> {
1019-
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
1019+
match *self {}
10201020
}
10211021
}
10221022
#[automatically_derived]

0 commit comments

Comments
 (0)