Skip to content

Ord and PartialOrd derives do not specify ordering behavior types with multiple fields #109946

Closed
@james7132

Description

@james7132

Location

Derive macros for Ord and PartialOrd.

Summary

The derive macros for Ord and PartialOrd do not specify what the order of precedence it generates in the resulting implementation. This order matters, and makes reordering fields on a type with this derive a semver-incompatible breaking change.

Examples

#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub struct MyStruct {
   field_1: u32,
   field_2: i32,
}

Does field_1 take precedence over field_2 when comparing two MyStructs?

#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub enum MyEnum {
   Variant_1 {
     field_1: u32,
     field_2: i32,
   },
   Variant_2 {
     field_1: i32,
     field_2: u32,
   }
   Variant_3(MyStruct),
}

Do all Variant_1 come before or after Variant_2?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions