Skip to content

very slow derived PartialEq/PartialOrd implementation of enum #31886

Closed
@oli-obk

Description

@oli-obk

The following code goes into an infinite loop or at least takes more than 10 seconds without optimizations. With optimizations it runs and the assertion fails. If anything but 0 and 0x8000_0000_0000_0000 are chosen for the discriminants, the code finishes instantly even in debug mode. Playground

#[derive(PartialEq, PartialOrd)]
enum Eu64 {
    Au64 = 0,
    Bu64 = 0x8000_0000_0000_0000
}

fn main() {
    assert!(Eu64::Bu64 > Eu64::Au64);
}

There's something odd going on anyway, as the discriminant is inferred to be isize instead of u64 (This unit test seems to suggest it should be u64)

cc #24290 @pnkfelix

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions