Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
james7132 opened this issue Apr 4, 2023 · 1 comment · Fixed by #109947
Closed
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@james7132
Copy link

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?

@james7132 james7132 added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Apr 4, 2023
@asquared31415
Copy link
Contributor

The trait docs specify the way that the derive works. These docs should probably be duplicated on the derive macro too.

@Noratrieb Noratrieb added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Apr 5, 2023
@bors bors closed this as completed in 4b8351f Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants