Skip to content

core: Align cmp::le() with the other implementations #4462

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ and `Eq` to overload the `==` and `!=` operators.
*
* Eventually this may be simplified to only require
* an `eq` method, with the other generated from
* a default implementation.
* a default implementation. However it should
* remain possible to implement `ne` separately, for
* compatibility with floating-point NaN semantics
* (cf. IEEE 754-2008 section 5.11).
*/
#[lang="eq"]
pub trait Eq {
Expand All @@ -43,7 +46,10 @@ pub trait Eq {
*
* Eventually this may be simplified to only require
* an `le` method, with the others generated from
* default implementations.
* default implementations. However it should remain
* possible to implement the others separately, for
* compatibility with floating-point NaN semantics
* (cf. IEEE 754-2008 section 5.11).
*/
#[lang="ord"]
pub trait Ord {
Expand All @@ -57,8 +63,8 @@ pub pure fn lt<T: Ord>(v1: &T, v2: &T) -> bool {
(*v1).lt(v2)
}

pub pure fn le<T: Ord Eq>(v1: &T, v2: &T) -> bool {
(*v1).lt(v2) || (*v1).eq(v2)
pub pure fn le<T: Ord>(v1: &T, v2: &T) -> bool {
(*v1).le(v2)
}

pub pure fn eq<T: Eq>(v1: &T, v2: &T) -> bool {
Expand Down