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

Derived PartialOrd is incorrect when inner values are unordered #81373

Closed
tmiasko opened this issue Jan 25, 2021 · 1 comment · Fixed by #81384
Closed

Derived PartialOrd is incorrect when inner values are unordered #81373

tmiasko opened this issue Jan 25, 2021 · 1 comment · Fixed by #81384
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. P-high High priority

Comments

@tmiasko
Copy link
Contributor

tmiasko commented Jan 25, 2021

In the derived partial_cmp the comparisons stops when inner partial_cmp returns
None. The implementation for lt, le, gt, ge are also provided, but they
continue the comparisons instead as if compared values were considered equal.

This behaviour is also inconsistent with the implementation for tuples / slices:

#[derive(PartialEq, PartialOrd)]
struct P(f64, f64);

fn main() {
    let a = (f64::NAN, 0.0);
    let b = (f64::NAN, 1.0);

    // Tuples:
    assert_eq!(PartialOrd::partial_cmp(&a, &b), None);
    assert!(!(a < b));

    // Arrays:
    let a = [f64::NAN, 0.0];
    let b = [f64::NAN, 1.0];
    assert_eq!(PartialOrd::partial_cmp(&a, &b), None);
    assert!(!(a < b));

    // Derived:
    let a = P(f64::NAN, 0.0);
    let b = P(f64::NAN, 1.0);
    assert_eq!(PartialOrd::partial_cmp(&a, &b), None);
    assert!(!(a < b)); // fails
}
@tmiasko tmiasko added the C-bug Category: This is a bug. label Jan 25, 2021
@jonas-schievink jonas-schievink added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 25, 2021
@hameerabbasi hameerabbasi added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 25, 2021
@hameerabbasi
Copy link
Contributor

Assigning P-high as discussed on Zulip.

@bors bors closed this as completed in c648bd5 Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. P-high High priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants