-
Notifications
You must be signed in to change notification settings - Fork 13.3k
There should be some way to generate default implementations of the cmp::Eq and cmp::Ord traits (deriving?). #3434
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
Comments
+1. I think the syntax should just be |
+1. This would help a lot for Servo. I hope to avoid writing 100+ |
Agree we'll need to do something here; wondering if it can be done without having to hack the compiler a ton. For example: if we finish default methods, and make the default eq method acquire a tydesc and reflect on it and compare that way, then the |
@graydon That sounds neat. |
@graydon I don't think it'll be much effort to hack the compiler. This only needs to work for enums and structs; for all the other types the stdlib provides implementations. |
I would really like something more flexible than what Haskell has. In particular, I'd like to be sure it is extensible to user-defined interfaces. For example, it should cover deserializing and the |
We discussed on IRC today and decided (tentatively) on a scheme for automatically marking an impl as deriving either an all- or any-element structure/wise and enum-wise impl from sub-impls. IRC conversation is over here: http://irclog.gr/#show/irc.mozilla.org/rust/239500 |
I found myself wishing for this last night. Does github not have a way to star or +1 an issue? odd. |
Superseded by the syntax-extension-based implementation of deriving, which works now. |
…ency, r=RalfJung cotrol stacked borrows consistency check with its own feature flag Fixes rust-lang/miri#3431
Now that rust uses the cmp::Eq and cmp::Ord traits for comparisons, there is often lots of error-prone boilerplate required to write impls of these traits. For example look at all the Eq impls in
src/libsyntax/ast.rs
.It would good to have some way to auto-generate impls that compare values in the same way that the old polymorphic comparison functions did. This would be similar to the deriving feature of Haskell: http://en.wikibooks.org/wiki/Haskell/Classes_and_types#Deriving.
The syntax might look something like:
The text was updated successfully, but these errors were encountered: