-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
Examples are always a big plus so please add them. :) |
Alright. I'll write them tomorrow. Sleep beckons. |
Tomorrow turned into a week. Whoops. |
src/liballoc/slice.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
src/libcore/slice/mod.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
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`. |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
Once the links added, it's good for me. cc @rust-lang/docs (in case someone would like to double check). |
+1. Can you add the links @GuillaumeGomez requested? |
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.
Links added and rebased against master. |
The job 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 |
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? |
The job 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 |
src/liballoc/slice.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remove this.
There was a problem hiding this comment.
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
src/libcore/slice/mod.rs
Outdated
@@ -1378,6 +1378,7 @@ impl<T> [T] { | |||
/// assert!(v == [5, 4, 3, 2, 1]); | |||
/// ``` | |||
/// | |||
/// [`partial_cmp`]: ../../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp |
There was a problem hiding this comment.
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.
That
|
ping from triage @Havvy: it looks like some changes have been requested to this PR. |
Ping from triage @Havvy: What are your plans for this PR? |
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. |
Ping from triage @GuillaumeGomez: it looks like this PR is ready for another review. |
Ping from triage @GuillaumeGomez / @rust-lang/docs: This PR requires your review. |
Then it's all good as is. Thanks! @bors: r+ |
📌 Commit 99bed21 has been approved by |
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
☀️ Test successful - status-appveyor, status-travis |
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