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

Code before:

        let a = MyEnum::Top;
        let b = MyEnum::Center;
        let c = MyEnum::Bottom;

        // Variant ordering of different variant name cannot be compared.
        assert_eq!(PartialReflect::reflect_partial_cmp(&a, &b), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&b, &a), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&b, &c), None);
        assert_eq!(
            PartialReflect::reflect_partial_cmp(&a, &a),
            Some(Ordering::Equal)
        );

        #[derive(PartialEq, PartialOrd, Reflect, Debug)]
        enum MyEnum2 {
            A,
            B,
            Center,
        }
        let a1 = MyEnum2::A;
        let c1 = MyEnum2::Center;

        assert_eq!(PartialReflect::reflect_partial_cmp(&a1, &a), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&a1, &b), None);
        // Variant name same, even different type, should be comparable
        assert_eq!(
            PartialReflect::reflect_partial_cmp(&c1, &b),
            Some(Ordering::Equal)
        );
    }

    #[test]
    fn reflect_partial_cmp_array_length_difference() {
        use core::cmp::Ordering;

        let a = [1i32, 2i32];
        let b = [1i32, 2i32, 3i32];

        let ord = PartialReflect::reflect_partial_cmp(&a, &b);
        assert_eq!(ord, Some(Ordering::Less));
    }

    #[test]
    fn reflect_partial_cmp_nested_none() {
        // inner NaN should cause overall None
        let a = (1i32, (1f32, f32::NAN));
        let b = (1i32, (1f32, 2f32));

        assert_eq!(PartialReflect::reflect_partial_cmp(&a, &b), None);
    }

Review comment (security):
I would be sensitive around using the word “should” here since we currently do not know if behavior is intended across all cases.
```suggestion
        // Two enums with the same variant name across different types are currently comparable
```

Code after:

        let a = MyEnum::Top;
        let b = MyEnum::Center;
        let c = MyEnum::Bottom;

        // Variant ordering of different variant name cannot be compared.
        assert_eq!(PartialReflect::reflect_partial_cmp(&a, &b), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&b, &a), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&b, &c), None);
        assert_eq!(
            PartialReflect::reflect_partial_cmp(&a, &a),
            Some(Ordering::Equal)
        );

        #[derive(PartialEq, PartialOrd, Reflect, Debug)]
        enum MyEnum2 {
            A,
            B,
            Center,
        }
        let a1 = MyEnum2::A;
        let c1 = MyEnum2::Center;

        assert_eq!(PartialReflect::reflect_partial_cmp(&a1, &a), None);
        assert_eq!(PartialReflect::reflect_partial_cmp(&a1, &b), None);
        // Two enums with the same variant name across different types are currently comparable
        assert_eq!(
            PartialReflect::reflect_partial_cmp(&c1, &b),
            Some(Ordering::Equal)
        );
    }

    #[test]
    fn reflect_partial_cmp_array_length_difference() {
        use core::cmp::Ordering;

        let a = [1i32, 2i32];
        let b = [1i32, 2i32, 3i32];

        let ord = PartialReflect::reflect_partial_cmp(&a, &b);
        assert_eq!(ord, Some(Ordering::Less));
    }

    #[test]
    fn reflect_partial_cmp_nested_none() {
        // inner NaN should cause overall None
        let a = (1i32, (1f32, f32::NAN));
        let b = (1i32, (1f32, 2f32));

        assert_eq!(PartialReflect::reflect_partial_cmp(&a, &b), None);
    }