Skip to content

Cheap derive(PartialOrd) for non-generic types #155537

@nnethercote

Description

@nnethercote

If a non-generic type derives both PartialOrd and Ord, the PartialOrd impl can just do this:

impl PartialOrd for T {
    fn_partial_cmp(&self, other: &T) {
        Some(self.cmp(other))
    }
}

(It won't work for generic types because the trait bounds on the generic parameters won't be right.)

This will likely be faster to compiler than a full implementation. It might also be a little easier for the backend to optimize.

Some futher discussion is on Zulip here.

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions