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

Add another PartialEq example #51760

Merged
merged 1 commit into from Aug 31, 2018

Conversation

GuillaumeGomez
Copy link
Member

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 24, 2018
@@ -95,6 +96,35 @@ use self::Ordering::*;
/// assert!(b1 != b3);
/// ```
///
/// ##How can I implement it to compare with another type?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space between ## and How and it => PartialEq imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not the issue. ;)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[01:16:28]    Doc-tests core
[01:16:41] 
[01:16:41] running 2093 tests
[01:16:55] ....................................................................................................
[01:17:09] ........................................F...........................................................
[01:17:47] .................................i..................................................................
[01:18:00] ....................................................................................................
[01:18:13] ....................................................................................................
[01:18:27] ....................................................................................................

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive
Copy link
Collaborator

Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:00:52] sha256:8c1f0882640438d1d5e0c0acc857fedd1a16de0d9ee943660aa40de5c9b49bad
[00:00:52] Attempting with retry: docker build --rm -t rust-ci -f /home/travis/build/rust-lang/rust/src/ci/docker/x86_64-gnu-llvm-3.9/Dockerfile /home/travis/build/rust-lang/rust/src/ci/docker
[00:00:52] Sending build context to Docker daemon  501.2kB
[00:00:52] Step 1/6 : FROM ubuntu:16.04
[00:00:52] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:00:53] Sending build context to Docker daemon  501.2kB
[00:00:53] Step 1/6 : FROM ubuntu:16.04
[00:00:53] Step 1/6 : FROM ubuntu:16.04
[00:00:53] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:00:55] Sending build context to Docker daemon  501.2kB
[00:00:55] Step 1/6 : FROM ubuntu:16.04
[00:00:55] Step 1/6 : FROM ubuntu:16.04
[00:00:56] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:00:59] Sending build context to Docker daemon  501.2kB
[00:00:59] Step 1/6 : FROM ubuntu:16.04
[00:00:59] Step 1/6 : FROM ubuntu:16.04
[00:00:59] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:01:03] Sending build context to Docker daemon  501.2kB
[00:01:03] Step 1/6 : FROM ubuntu:16.04
[00:01:03] Step 1/6 : FROM ubuntu:16.04
[00:01:03] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:01:03] The command has failed after 5 attempts.

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 1.
travis_time:start:12abd860
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:03b2475d:start=1529879746989628774,finish=1529879746996691113,duration=7062339
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0e6474eb
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers’ for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:2e1bf67f
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@GuillaumeGomez
Copy link
Member Author

ping @steveklabnik

@stokhos
Copy link

stokhos commented Jul 6, 2018

Ping from triage! @steveklabnik @rust-lang/docs , we haven't heard from you for a while, will youh ave time to look into this PR?

@stokhos stokhos added the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Jul 21, 2018
@stokhos
Copy link

stokhos commented Jul 21, 2018

Ping from triage, @rust-lang/docs anyone would want to review this PR?

@stokhos stokhos added I-nominated A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2018
@GuillaumeGomez
Copy link
Member Author

cc @QuietMisdreavus

@@ -95,6 +96,35 @@ use self::Ordering::*;
/// assert!(b1 != b3);
/// ```
///
/// ## How can I implement it to compare with another type?
///
/// This is pretty easy to do. Let's take back our previous code and modify it:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure i agree with using "pretty easy" here. It's a poor phrase to use in documentation. How about something like this:

The type you can compare with is controlled by PartialEq's type parameter. For example, let's tweak our previous code a bit:

Then you can follow up below the example with something like:

By changing impl PartialEq for Book to impl PartialEq<BookFormat> for Book, we've changed what type we can use on the right side of the == operator. This lets us use it in the assert! statements at the bottom.

It would also be cool if you added one more example, combining them to show off that the same type can == to different types. Maybe continue with:

You can even combine these implementations to compare against both Book and BookFormat, like this:

(code sample with both PartialEq impls and both sets of assertions)

@GuillaumeGomez
Copy link
Member Author

Took your sentences and added the new code! (which was a good idea!)

/// we've changed what type we can use on the right side of the `==` operator.
/// This lets us use it in the `assert!` statements at the bottom.
///
/// Of course, you can implement `PartialEq` to have `==` operator on two
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of "of course" either. How about:

You can also combine these implementations to let the == operator work with two different types:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me! 😉

@GuillaumeGomez
Copy link
Member Author

Updated.

Copy link
Member

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing the first ping :(

@@ -95,6 +96,76 @@ use self::Ordering::*;
/// assert!(b1 != b3);
/// ```
///
/// ## How can I implement it to compare with another type?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads as awkward to me; can we get one last tweak?

/// ## How can I compare two different types?

/// For example, let's tweak our previous code a bit:
///
/// ```
/// enum BookFormat { Paperback, Hardback, Ebook }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this how rustfmt formats this code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the code above as is so I don't know?

/// impl PartialEq<BookFormat> for Book {
/// fn eq(&self, other: &BookFormat) -> bool {
/// match (&self.format, other) {
/// (&BookFormat::Paperback, &BookFormat::Paperback) => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this code need the &s? I'd expect them to not these days.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes the code more clear.

/// assert!(b1 != BookFormat::Ebook);
/// ```
///
/// By changing impl `PartialEq` for `Book` to `impl PartialEq<BookFormat> for Book`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the `s should be around the whole "impl PartialEq for book" here

@TimNN TimNN added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Aug 7, 2018
@TimNN
Copy link
Contributor

TimNN commented Aug 7, 2018

Ping from triage @GuillaumeGomez: Some changes have been requested to your PR.

@GuillaumeGomez
Copy link
Member Author

Oh right! I'll update soon.

@GuillaumeGomez
Copy link
Member Author

Updated to @steveklabnik's comments.

@XAMPPRocky XAMPPRocky removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 21, 2018
@XAMPPRocky
Copy link
Member

Triage: @steveklabnik This PR requires your review.

@GuillaumeGomez
Copy link
Member Author

Seems like I failed my rebase. I'll fix the conflicts.

@GuillaumeGomez
Copy link
Member Author

Updated.

@pietroalbini
Copy link
Member

Ping from triage! This PR needs a review, can @steveklabnik or someone else from @rust-lang/docs review this?

@QuietMisdreavus
Copy link
Member

Looks good to me! Let's get this merged.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 27, 2018

📌 Commit 3995bff has been approved by QuietMisdreavus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 27, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Aug 28, 2018
…q-example, r=QuietMisdreavus

Add another PartialEq example

r? @steveklabnik
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Aug 28, 2018
…q-example, r=QuietMisdreavus

Add another PartialEq example

r? @steveklabnik
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Aug 29, 2018
…q-example, r=QuietMisdreavus

Add another PartialEq example

r? @steveklabnik
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Aug 29, 2018
…q-example, r=QuietMisdreavus

Add another PartialEq example

r? @steveklabnik
@RalfJung
Copy link
Member

RalfJung commented Aug 30, 2018

These examples to not follow the rules the documentation states for ==: I can now do b1 == BookFormat::Paperback but not BookFormat::Paperback == b1, breaking symmetry. That does not seem nice.

Cc @gnzlbg

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Aug 30, 2018
…q-example, r=QuietMisdreavus

Add another PartialEq example

r? @steveklabnik
bors added a commit that referenced this pull request Aug 31, 2018
Rollup of 20 pull requests

Successful merges:

 - #51760 (Add another PartialEq example)
 - #53113 (Add example for Cow)
 - #53129 (remove `let x = baz` which was obscuring the real error)
 - #53389 (document effect of join on memory ordering)
 - #53472 (Use FxHash{Map,Set} instead of the default Hash{Map,Set} everywhere in rustc.)
 - #53476 (Add partialeq implementation for TryFromIntError type)
 - #53513 (Force-inline `shallow_resolve` at its hottest call site.)
 - #53655 (set applicability)
 - #53702 (Fix stabilisation version for macro_vis_matcher.)
 - #53727 (Do not suggest dereferencing in macro)
 - #53732 (save-analysis: Differentiate foreign functions and statics.)
 - #53740 (add llvm-readobj to llvm-tools-preview)
 - #53743 (fix a typo: taget_env -> target_env)
 - #53747 (Rustdoc fixes)
 - #53753 (expand keep-stage --help text)
 - #53756 (Fix typo in comment)
 - #53768 (move file-extension based .gitignore down to src/)
 - #53785 (Fix a comment in src/libcore/slice/mod.rs)
 - #53786 (Replace usages of 'bad_style' with 'nonstandard_style'.)
 - #53806 (Fix UI issues on Implementations on Foreign types)

Failed merges:

r? @ghost
@bors bors merged commit 3995bff into rust-lang:master Aug 31, 2018
@GuillaumeGomez GuillaumeGomez deleted the add-another-partialeq-example branch August 31, 2018 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet