Skip to content

Guide: Derive Eq to avoid compile error. #16003

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

Guide: Derive Eq to avoid compile error. #16003

wants to merge 1 commit into from

Conversation

treeman
Copy link
Contributor

@treeman treeman commented Jul 26, 2014

If we copy in Ordering and use it with the following example we'll get a compile error as == has not been defined.

I chose to introduce deriving(Eq, PartialEq) but refer to the later discussion (which I assume is going to come). I'm not sure about the formulation however.

It could have been fine to use match, but it hasn't been presented yet. In the next example though we are using match in the example code, so we could do it here as well. But I'm more inclined to remove the use of match there as well as it might be a bit confusing?

cc @steveklabnik

@steveklabnik
Copy link
Member

This is not acceptable, as we haven't covered any of this material yet. And you shouldn't be copying in Ordering.

@steveklabnik
Copy link
Member

Sorry, was reading on my phone and didn't notice you added an explanation!

I think the better way to fix this is to just tell people that they don't need to define this, if you feel like this is something people are going to do.

@treeman
Copy link
Contributor Author

treeman commented Jul 26, 2014

Yes we could simply add a comment, and it would be kind of okay.

We should aim to have the code as copyable as possible however. And I do believe some people will type it all in (I usually do) and it's quite scary to encounter errors when doing this. Also some may try variations of the code, "oh we have an enum Ordering, but I want an enum Color" and then get lost when == errors. But maybe that's also fine if you haven't gone through the guide to the end.

My solution might not be good though. Introducing #[deriving(Eq, PartialEq)] might be too messy for a hasty introduction like this.

Could we consider moving the discussion of match before defining Ordering? This defeats some of the flow between the sections though...

Hmm, if you are still unsure we could just leave it with a comment?

@nielsle nielsle mentioned this pull request Jul 26, 2014
@alexcrichton
Copy link
Member

r? @steveklabnik

@steveklabnik
Copy link
Member

I don't like this 'solution' and I'm unsure of how much of a problem it really is, or if the root cause can be handled somehow else.

bors added a commit that referenced this pull request Aug 21, 2014
This way people won't try to copy/paste it in.

This is provided as an alternate solution to #16003. What do you think, @treeman?
@treeman
Copy link
Contributor Author

treeman commented Aug 22, 2014

Fixed with #16635.

@treeman treeman closed this Aug 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants