Skip to content

default methods for the cmp traits #5590

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
thestinger opened this issue Mar 27, 2013 · 10 comments
Closed

default methods for the cmp traits #5590

thestinger opened this issue Mar 27, 2013 · 10 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@thestinger
Copy link
Contributor

(blocked on working default methods)

Implementing TotalOrd should implement Ord with default methods, and implementing TotalEq should provide a default Eq. Types with only a partial ordering can implement Eq/Ord, and types with two different ordering semantics (floats) can implement both.

A TotalOrd implementation can also provide TotalEq via a default, so most types would only implement one trait directly or just derive everything.

@emberian
Copy link
Member

@thestinger @msullivan do default methods work well enough for this yet?

@thestinger
Copy link
Contributor Author

Not really.

@omasanori
Copy link
Contributor

Default methods for Ord and Eq are provided. Is it ready now?

@alexcrichton
Copy link
Member

I don't think this should be closed until all the implementations of the now-default methods have been deleted (just to ensure that the default methods are working).

@huonw
Copy link
Member

huonw commented Jul 16, 2013

Also, the current default method implementation doesn't allow one to automatically get an Ord impl from a TotalOrd impl without having Ord: TotalOrd and that is definitely wrong (similarly, TotalEq: TotalOrd is wrong).

@msullivan
Copy link
Contributor

Yeah, default methods don't quite work for what you want, and are not likely to. I think I"m going to close this.

@gifnksm
Copy link
Contributor

gifnksm commented Aug 25, 2013

I think the following code works fine for this purpose.

impl<T: TotalEq> Eq for T {
    fn eq(&self, other: &T) -> bool { self.equals(other) }
}

impl<T: TotalOrd> Ord for T {
    fn lt(&self, other: &T) -> bool { self.cmp(other) == Less }
}

@huonw
Copy link
Member

huonw commented Aug 25, 2013

@gifnksm that will mean that no other types can implement Eq or Ord. (It requires some sort of precedence/specialisation, i.e. #7059.)

@catamorphism
Copy link
Contributor

@alexcrichton thinks this is done; closing

@alexcrichton
Copy link
Member

If there are specific instances which need to be switched over, there should be individual bugs for them at this point. I believe that the bulk of types which can benefit from default methods are currently benefiting from default methods.

flip1995 pushed a commit to flip1995/rust that referenced this issue May 15, 2020
Fix ICE caused in unwrap module

changelog: Fix ICE in unwrap module with unexpected number of parameters for method of Option/Result

Fixes rust-lang#5579
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

8 participants