Avoid regression in derive(PartialOrd) for zero-variant enums

This commit is contained in:
Makai
2026-04-22 15:11:07 +08:00
parent d436194c35
commit caabc4b695
2 changed files with 5 additions and 2 deletions
@@ -57,8 +57,11 @@ pub(crate) fn expand_deriving_partial_ord(
}));
let (is_simple, substructure) = match item {
Annotatable::Item(annitem) => match &annitem.kind {
// For unit structs, the default generated code is better.
// For unit structs/zero-variant enums, the default generated code is better.
ItemKind::Struct(.., ast::VariantData::Unit(..)) => (false, default_substructure),
ItemKind::Enum(.., enum_def) if enum_def.variants.is_empty() => {
(false, default_substructure)
}
ItemKind::Struct(_, ast::Generics { params, .. }, _)
| ItemKind::Enum(_, ast::Generics { params, .. }, _)
if is_simple_candidate(params) =>
+1 -1
View File
@@ -1016,7 +1016,7 @@ impl ::core::cmp::PartialOrd for Enum0 {
#[inline]
fn partial_cmp(&self, other: &Enum0)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
match *self {}
}
}
#[automatically_derived]