Skip to content
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

There should be some way to generate default implementations of the cmp::Eq and cmp::Ord traits (deriving?). #3434

Closed
Dretch opened this issue Sep 9, 2012 · 9 comments
Labels
E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Milestone

Comments

@Dretch
Copy link
Contributor

Dretch commented Sep 9, 2012

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:

struct Bob deriving Eq, Ord {
    some: Boo,
    struct: Foo,
    fields: Hoo,
}
@pcwalton
Copy link
Contributor

+1. I think the syntax should just be impl Bob : Eq;.

@burg
Copy link

burg commented Sep 10, 2012

+1. This would help a lot for Servo. I hope to avoid writing 100+ Eq implementations, one per CSS property :-)

@graydon
Copy link
Contributor

graydon commented Sep 10, 2012

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 impl Bob : Eq; declaration can simply mean "just use the default methods for this trait". Yes?

@Dretch
Copy link
Contributor Author

Dretch commented Sep 10, 2012

@graydon That sounds neat.

@pcwalton
Copy link
Contributor

@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.

@nikomatsakis
Copy link
Contributor

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 tr interface found in rustc::middle::astencode. That kind of thing is really tedious.

@graydon
Copy link
Contributor

graydon commented Sep 13, 2012

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

@dckc
Copy link
Contributor

dckc commented Oct 27, 2012

I found myself wishing for this last night.

Does github not have a way to star or +1 an issue? odd.

@catamorphism
Copy link
Contributor

Superseded by the syntax-extension-based implementation of deriving, which works now.

RalfJung pushed a commit to RalfJung/rust that referenced this issue Mar 31, 2024
…ency, r=RalfJung

cotrol stacked borrows consistency check with its own feature flag

Fixes rust-lang/miri#3431
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

7 participants