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

Doc total order requirement of sort(_unstable)_by #53918

Merged
merged 4 commits into from
Nov 22, 2018

Conversation

Havvy
Copy link
Contributor

@Havvy Havvy commented Sep 3, 2018

I took the definition of what a total order is from the Ord trait
docs. I specifically put "elements of the slice" because if you
have a slice of f64s, but know none are NaN, then sorting by
partial ord is total in this case. I'm not sure if I should give
such an example in the docs or not.

r? @GuillaumeGomez

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 3, 2018
@GuillaumeGomez
Copy link
Member

Examples are always a big plus so please add them. :)

@Havvy
Copy link
Contributor Author

Havvy commented Sep 3, 2018

Alright. I'll write them tomorrow. Sleep beckons.

@Havvy
Copy link
Contributor Author

Havvy commented Sep 10, 2018

Tomorrow turned into a week. Whoops.

@@ -218,6 +218,15 @@ impl<T> [T] {
/// * total and antisymmetric: exactly one of a < b, a == b or a > b is true; and
/// * transitive, a < b and b < c implies a < c. The same must hold for both == and >.
///
/// For example, while `f64` doesn't implement `Ord` because `NaN != NaN`, we can use
Copy link
Member

Choose a reason for hiding this comment

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

Please add urls to types.

@@ -1350,6 +1350,15 @@ impl<T> [T] {
/// * total and antisymmetric: exactly one of a < b, a == b or a > b is true; and
/// * transitive, a < b and b < c implies a < c. The same must hold for both == and >.
///
/// For example, while `f64` doesn't implement `Ord` because `NaN != NaN`, we can use
Copy link
Member

Choose a reason for hiding this comment

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

Same

@Havvy
Copy link
Contributor Author

Havvy commented Sep 25, 2018

ping @GuillaumeGomez

/// * transitive, a < b and b < c implies a < c. The same must hold for both == and >.
///
/// For example, while [`f64`] doesn't implement [`Ord`] because `NaN != NaN`, we can use
/// `partial_cmp` as our sort function when we know the slice doesn't contain a `NaN`.
Copy link
Member

Choose a reason for hiding this comment

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

Can you link to partial_cmp please?

/// * transitive, a < b and b < c implies a < c. The same must hold for both == and >.
///
/// For example, while [`f64`] doesn't implement [`Ord`] because `NaN != NaN`, we can use
/// `partial_cmp` as our sort function when we know the slice doesn't contain a `NaN`.
Copy link
Member

Choose a reason for hiding this comment

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

Same.

@GuillaumeGomez
Copy link
Member

Once the links added, it's good for me.

cc @rust-lang/docs (in case someone would like to double check).

@QuietMisdreavus
Copy link
Member

+1. Can you add the links @GuillaumeGomez requested?

Havvy added 4 commits October 5, 2018 17:41
I took the definition of what a total order is from the Ord trait
docs. I specifically put "elements of the slice" because if you
have a slice of f64s, but know none are NaN, then sorting by
partial ord is total in this case. I'm not sure if I should give
such an example in the docs or not.
@Havvy
Copy link
Contributor Author

Havvy commented Oct 7, 2018

Links added and rebased against master.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 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.
[00:53:06] ................................................................................................i... 2200/4563
[00:53:10] .................................................................................................... 2300/4563
[00:53:14] .................................................................................................... 2400/4563
[00:53:18] .................................................................................................... 2500/4563
[00:53:21] ........iiiiiiiii................................................................................... 2600/4563
[00:53:27] .................................................................................................... 2800/4563
[00:53:31] .................................................................................................... 2900/4563
[00:53:34] ............................i....................................................................... 3000/4563
[00:53:37] ........................................................................................i.i..ii..... 3100/4563
---
[01:31:53] travis_fold:end:stage0-linkchecker

[01:31:53] travis_time:end:stage0-linkchecker:start=1538899941792582952,finish=1538899944042187862,duration=2249604910

[01:33:50] std/vec/struct.Vec.html:1350: broken link - std/std/cmp/trait.PartialOrd.html
[01:33:50] std/vec/struct.Vec.html:1700: broken link - std/std/cmp/trait.PartialOrd.html
[01:34:45] thread 'main' panicked at 'found some broken links', tools/linkchecker/main.rs:49:9
[01:34:45] 
[01:34:45] 
[01:34:45] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/linkchecker" "/checkout/obj/build/x86_64-unknown-linux-gnu/doc"
[01:34:45] expected success, got: exit code: 101
[01:34:45] expected success, got: exit code: 101
[01:34:45] 
[01:34:45] 
[01:34:45] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:34:45] Build completed unsuccessfully in 0:46:26
[01:34:45] Makefile:58: recipe for target 'check' failed
[01:34:45] make: *** [check] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:2bf6801e
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:183b6354:start=1538900124460003233,finish=1538900124591751604,duration=131748371
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0d48c286
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0a02c396
$ 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)

@Havvy
Copy link
Contributor Author

Havvy commented Oct 7, 2018

I'm confused. Those links worked locally. I'll just add the "../" to make linkchecker happy though, and perhaps I misread what happened on my end?

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 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.
[00:47:37] ................................................................................................i... 2200/4563
[00:47:41] .................................................................................................... 2300/4563
[00:47:44] .................................................................................................... 2400/4563
[00:47:48] .................................................................................................... 2500/4563
[00:47:51] ........iiiiiiiii................................................................................... 2600/4563
[00:47:57] .................................................................................................... 2800/4563
[00:48:01] .................................................................................................... 2900/4563
[00:48:03] ............................i....................................................................... 3000/4563
[00:48:06] ........................................................................................i.i..ii..... 3100/4563
---
[01:22:53] travis_fold:end:stage0-linkchecker

[01:22:53] travis_time:end:stage0-linkchecker:start=1538908626887235069,finish=1538908629074560159,duration=2187325090

[01:22:53] std/primitive.slice.html:633: broken link - /checkout/obj/build/x86_64-unknown-linux-gnu/std/cmp/trait.PartialOrd.html
[01:22:53] std/primitive.slice.html:983: broken link - /checkout/obj/build/x86_64-unknown-linux-gnu/std/cmp/trait.PartialOrd.html
[01:26:02] thread 'main' panicked at 'found some broken links', tools/linkchecker/main.rs:49:9
[01:26:02] 
[01:26:02] 
[01:26:02] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/linkchecker" "/checkout/obj/build/x86_64-unknown-linux-gnu/doc"
[01:26:02] expected success, got: exit code: 101
[01:26:02] expected success, got: exit code: 101
[01:26:02] 
[01:26:02] 
[01:26:02] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:26:02] Build completed unsuccessfully in 0:43:05
[01:26:02] make: *** [check] Error 1
[01:26:02] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:03952c38
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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)

@@ -252,6 +252,8 @@ impl<T> [T] {
/// v.sort_by(|a, b| b.cmp(a));
/// assert!(v == [5, 4, 3, 2, 1]);
/// ```
///
/// [`partial_cmp`]: ../../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp
Copy link
Member

Choose a reason for hiding this comment

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

Just remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That causes the rustdoc output to say:

222 |     /// [`partial_cmp`] as our sort function when we know the slice doesn't contain a `NaN`.                                                                                                                   
    |          ^^^^^^^^^^^^^ cannot be resolved, ignoring 

@@ -1378,6 +1378,7 @@ impl<T> [T] {
/// assert!(v == [5, 4, 3, 2, 1]);
/// ```
///
/// [`partial_cmp`]: ../../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp
Copy link
Member

Choose a reason for hiding this comment

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

And remove this one too.

@QuietMisdreavus
Copy link
Member

That partial_ord cannot be linked to, either from directly linking to the file or via intra-doc links.

  • The core issue with linking directly to the file is that these docs appear in two places: directly on slices (std/primitive.slice.html) and on Vec when documented in std (std/vec/struct.Vec.html - they're not in alloc because the slice docs aren't available there). You can't use different amounts of ../ to appease both places.
  • You could try to use intra-doc links like @GuillaumeGomez suggests, but you need to link to the libcore version of PartialOrd, which may cause the eventual docs to link to core instead of std like we prefer. If you want to try it, link to the method via the full declaration of the PartialOrd trait - so core::cmp::PartialOrd::partial_cmp (cmp::PartialOrd::partial_cmp for the location in libcore) - then see whether the docs in std link to core or std. I have a feeling they'll link to core, but i haven't looked closely enough at the relevant code to know for sure.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2018
@TimNN
Copy link
Contributor

TimNN commented Oct 30, 2018

ping from triage @Havvy: it looks like some changes have been requested to this PR.

@TimNN
Copy link
Contributor

TimNN commented Nov 6, 2018

Ping from triage @Havvy: What are your plans for this PR?

@Havvy
Copy link
Contributor Author

Havvy commented Nov 7, 2018

I removed the commits for linkifying partial_cmp since I don't think it's possible given the link has to work in two places and cannot be done with intra-linking.

@TimNN TimNN added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2018
@TimNN
Copy link
Contributor

TimNN commented Nov 13, 2018

Ping from triage @GuillaumeGomez: it looks like this PR is ready for another review.

@TimNN
Copy link
Contributor

TimNN commented Nov 20, 2018

Ping from triage @GuillaumeGomez / @rust-lang/docs: This PR requires your review.

@GuillaumeGomez
Copy link
Member

Then it's all good as is. Thanks!

@bors: r+

@bors
Copy link
Contributor

bors commented Nov 21, 2018

📌 Commit 99bed21 has been approved by GuillaumeGomez

@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 Nov 21, 2018
@bors
Copy link
Contributor

bors commented Nov 22, 2018

⌛ Testing commit 99bed21 with merge f3adec6...

bors added a commit that referenced this pull request Nov 22, 2018
Doc total order requirement of sort(_unstable)_by

I took the definition of what a total order is from the Ord trait
docs. I specifically put "elements of the slice" because if you
have a slice of f64s, but know none are NaN, then sorting by
partial ord is total in this case. I'm not sure if I should give
such an example in the docs or not.

r? @GuillaumeGomez
@bors
Copy link
Contributor

bors commented Nov 22, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: GuillaumeGomez
Pushing f3adec6 to master...

@bors bors merged commit 99bed21 into rust-lang:master Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants