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

rustdoc: Add PartialOrd trait to doc comment explanation #104068

Merged
merged 1 commit into from
Feb 17, 2023

Conversation

yancyribbens
Copy link
Contributor

The doc comments for partial_cmp is the exact same as the doc comment for cmp. This PR adds to the description partial_cmp to disambiguate the description from cmp.

@rustbot
Copy link
Collaborator

rustbot commented Nov 6, 2022

r? @scottmcm

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 6, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 6, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

@rustbot author

/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
/// of another.
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`], which
/// implements the `PartialOrd` trait, with those of another.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I like the idea that improving the comment here, but I think this isn't quite the right phrasing, since it could be interpreted as the iterator implementing the PartialOrd trait, especially with the word "implements".

Maybe something like "compares the PartialOrd elements of this"?

Also, while you're here, it would be great to have some prose about what happens for incomparable items like NANs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@scottmcm, thanks. I agree that adding an explanation about PartialOrd elements is correct. I also added some prose about using partial_cmp with things like NANs.

@rustbot rustbot 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 Nov 25, 2022
@yancyribbens yancyribbens force-pushed the partial-cmp-doc-update branch 2 times, most recently from ca5cdcf to 06077d0 Compare November 27, 2022 17:04
@rust-log-analyzer

This comment has been minimized.

@pitaj
Copy link
Contributor

pitaj commented Jan 28, 2023

If you've made changes to resolve any issues brought up during review, then mark the PR as waiting on review with @rustbot ready

@yancyribbens
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot 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 Jan 31, 2023
/// of another.
/// [Lexicographically](Ord#lexicographical-comparison) compares the [`PartialOrd`] elements of
/// this [`Iterator`] with those of another. A [`Option`] type is returned and will either be
/// [`Some`] if the types have a total order, or else [`None`]. For example, for floating
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I've got more phrasing nitpicks here.

let it1 = std::iter::repeat(1.0);
let it2 = std::iter::repeat(2.0);
dbg!(it1.partial_cmp(it2));

returns Some(Less) here, but that doesn't mean that the types have a total order, just that the values observed were ordered.

Maybe there's a way to phrase it in terms of if PartialOrd::partial_cmp every returns None from any of the comparisons done, then this will also return None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe there's a way to phrase it in terms of if PartialOrd::partial_cmp every returns None from any of the comparisons done, then this will also return None?

Wouldn't it be more descriptive to explain that as soon as an orderings can be determined the evaluation stops (similar to how short-circuit evaluation works)?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that sounds good too!

/// [Lexicographically](Ord#lexicographical-comparison) compares the [`PartialOrd`] elements of
/// this [`Iterator`] with those of another. A [`Option`] type is returned and will either be
/// [`Some`] if the types have a total order, or else [`None`]. For example, for floating
/// point numbers, NaN does not have a total order and will result in the [`None`] variant
Copy link
Member

@scottmcm scottmcm Feb 11, 2023

Choose a reason for hiding this comment

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

If the prose says "for example", then consider putting it down in the # Examples section with a runnable example.

Perhaps take this part

    /// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
    ///
    /// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None);
    /// ```

and put your text in there?

    /// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
    /// ```
    ///
    /// For floating-point numbers, NaN does not have a total order and will result
    /// in `None` when compared:
    ///
    /// ```
    /// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None);
    /// ```

You could also add some more examples about it here, like comparing [1.0, NAN] with [2.0, NAN], where you'll get a result despite the NANs since the prefix is enough to decide the lexicographical order.

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

Apologies for taking a while to get back to this. I had a few more thoughts about it.

@rustbot author

@rustbot rustbot 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 Feb 11, 2023
@yancyribbens
Copy link
Contributor Author

@scottmcm no problem. Thanks for the feedback.

@yancyribbens
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot 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 Feb 16, 2023
Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

Looking good. I'll wait for CI to confirm, though.

@scottmcm
Copy link
Member

@bors r+ rollup=always

@bors
Copy link
Contributor

bors commented Feb 16, 2023

📌 Commit ced9629 has been approved by scottmcm

It is now in the queue for this repository.

@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 Feb 16, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 17, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#104068 (rustdoc: Add PartialOrd trait to doc comment explanation)
 - rust-lang#107489 (Implement partial support for non-lifetime binders)
 - rust-lang#107905 (Pass arguments to `x` subcommands with `--`)
 - rust-lang#108009 (Move some tests)
 - rust-lang#108086 (wasm: Register the `relaxed-simd` target feature)
 - rust-lang#108104 (don't into self)
 - rust-lang#108133 (Small cleanups around `EarlyBinder`)
 - rust-lang#108136 (Do not ICE on unmet trait alias impl bounds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6379c72 into rust-lang:master Feb 17, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 17, 2023
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants