Skip to content

Commit 6fda0fe

Browse files
committed
cmp: Implement all PartialOrd methods for Reverse
When making a forwarding wrapper we must in general forward all methods, so that we use the type's own `lt` for example instead of the default. Example important case: f32's partial_cmp does several operations but its lt is a primitive.
1 parent fe15119 commit 6fda0fe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libcore/cmp.rs

+9
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,15 @@ impl<T: PartialOrd> PartialOrd for Reverse<T> {
347347
fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering> {
348348
other.0.partial_cmp(&self.0)
349349
}
350+
351+
#[inline]
352+
fn lt(&self, other: &Self) -> bool { other.0 < self.0 }
353+
#[inline]
354+
fn le(&self, other: &Self) -> bool { other.0 <= self.0 }
355+
#[inline]
356+
fn ge(&self, other: &Self) -> bool { other.0 >= self.0 }
357+
#[inline]
358+
fn gt(&self, other: &Self) -> bool { other.0 > self.0 }
350359
}
351360

352361
#[unstable(feature = "reverse_cmp_key", issue = "40893")]

0 commit comments

Comments
 (0)