-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
If a type deriving PartialOrd
wraps another type which contains incomparable elements - and therefore only defines an implementation of PartialOrd
and not a Ord
- the derived implementations of the le
and ge
functions are flawed.
The leads to a state where the internal type returns false as result of the expressions a <= b
and b >= a
for two incomparable elements a
and b
while the wrapper returns true. [playground]
If we look into the attached output of cargo-expand
it becomes clear that both implementations ignore the the underlying type only implements PartialOrd
and may contain incomparable elements which can't be checked by (a < b) || !(b < a)
or (a > b) || !(a > b)
.
Expanded: Less or Equal
#[inline]
fn le(&self, __arg_0: &StructWithoutOrd) -> bool {
match *__arg_0 {
StructWithoutOrd(ref __self_1_0) => match *self {
StructWithoutOrd(ref __self_0_0) => {
(*__self_0_0) < (*__self_1_0) || !((*__self_1_0) < (*__self_0_0)) && true
}
},
}
}
Expanded: Greater or Equal
#[inline]
fn ge(&self, __arg_0: &StructWithoutOrd) -> bool {
match *__arg_0 {
StructWithoutOrd(ref __self_1_0) => match *self {
StructWithoutOrd(ref __self_0_0) => {
(*__self_0_0) > (*__self_1_0) || !((*__self_1_0) > (*__self_0_0)) && true
}
},
}
}
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.