Repository: bevyengine/bevy
File: crates/bevy_reflect/src/enums/helpers.rs (Rust)

Code before:
            }
            Some(true)
        }
        _ => Some(true),
    }
}

/// Compares two [`Enum`] values (by variant) and returns their ordering.
///
/// Returns [`None`] if the comparison couldn't be performed (e.g., kinds mismatch
/// or an element comparison returns `None`).
///
/// The ordering is same with `derive` macro. First order by variant index, then by fields.
#[inline]
pub fn enum_partial_cmp<TEnum: Enum + ?Sized>(
    a: &TEnum,
    b: &dyn PartialReflect,
) -> Option<::core::cmp::Ordering> {
    // Both enums?
    let ReflectRef::Enum(b) = b.reflect_ref() else {
        return None;
    };

    // Same variant name?
    if a.variant_name() != b.variant_name() {
        // Different variant names, cannot compare
        return None;
    }

    // Same variant type?
    if !a.is_variant(b.variant_type()) {
        return None;
    }

    match a.variant_type() {
        VariantType::Struct => {
            if a.field_len() != b.field_len() {
                return None;
            }
            crate::structs::partial_cmp_by_field_names(
                a.field_len(),
                |i| a.name_at(i),
                |i| a.field_at(i),
                |i| b.name_at(i),
                |i| b.field_at(i),
                |name| b.field(name),
            )
        }
        VariantType::Tuple => {
            if a.field_len() != b.field_len() {
                return None;

Review comment (suggestion):
This comment could leave more breadcrumbs on why we are not comparing by variant index here
```suggestion
        // Different variant names. 
        // Ordering by variant index here can result in inconsistencies with 
        // partial_eq when comparing between two different concrete enums,
        // so we simply return None here
```

Code after:
            }
            Some(true)
        }
        _ => Some(true),
    }
}

/// Compares two [`Enum`] values (by variant) and returns their ordering.
///
/// Returns [`None`] if the comparison couldn't be performed (e.g., kinds mismatch
/// or an element comparison returns `None`).
///
/// The ordering is same with `derive` macro. First order by variant index, then by fields.
#[inline]
pub fn enum_partial_cmp<TEnum: Enum + ?Sized>(
    a: &TEnum,
    b: &dyn PartialReflect,
) -> Option<::core::cmp::Ordering> {
    // Both enums?
    let ReflectRef::Enum(b) = b.reflect_ref() else {
        return None;
    };

    // Same variant name?
    if a.variant_name() != b.variant_name() {
        // Different variant names.
        // Ordering by variant index here can result in inconsistencies with
        // partial_eq when comparing between two different concrete enums,
        // so we simply return None here
        return None;
    }

    // Same variant type?
    if !a.is_variant(b.variant_type()) {
        return None;
    }

    match a.variant_type() {
        VariantType::Struct => {
            if a.field_len() != b.field_len() {
                return None;
            }
            crate::structs::partial_cmp_by_field_names(
                a.field_len(),
                |i| a.name_at(i),
                |i| a.field_at(i),
                |i| b.name_at(i),
                |i| b.field_at(i),
                |name| b.field(name),
            )
        }