-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Derived PartialOrd is incorrect when inner values are unordered #81373
Copy link
Copy link
Closed
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priority
Description
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
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priority
Type
Fields
Give feedbackNo fields configured for issues without a type.